Skip to content

Commit 73a4b92

Browse files
committed
Config: Make preset config aware of cpu/memory
Preset property is bound with cpu/memory/bundle and have default values for it but our `set` function doesn't have map around those settings and a user can do following without any error message. ``` $ crc config set preset microshift $ crc config set cpus 2 $ crc config set preset openshift ``` and when user try to perform `crc start` then error message shown. With this PR we are making the set function bit self aware of the preset and it's bound properties (cpu/memory) and make sure if those property doesn't validated for the preset then unset those so default values going to take over. with this PR following now works as expected. ``` $ curl -X POST -d '{"properties":{"preset": "microshift"}}' --unix-socket ~/.crc/crc-http.sock http:/c/api/config {"Properties":["preset"]} $ curl -X POST -d '{"properties":{"cpus": "3"}}' --unix-socket ~/.crc/crc-http.sock http:/c/api/config {"Properties":["cpus"]} $ curl -X POST -d '{"properties":{"preset": "openshift"}}' --unix-socket ~/.crc/crc-http.sock http:/c/api/config {"Properties":["preset"]} $ curl -X GET --unix-socket ~/.crc/crc-http.sock http:/c/api/config | jq . % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 894 100 894 0 0 56924 0 --:--:-- --:--:-- --:--:-- 59600 { "Configs": { "bundle": "/Users/prkumar/.crc/cache/crc_vfkit_4.12.13_arm64.crcbundle", "consent-telemetry": "no", "cpus": 4, "disable-update-check": true, "disk-size": 31, "enable-cluster-monitoring": false, "enable-experimental-features": false, "enable-shared-dirs": true, "host-network-access": false, "http-proxy": "", "https-proxy": "", "ingress-http-port": 80, "ingress-https-port": 443, "kubeadmin-password": "", "memory": 9216, [...] ```
1 parent f9a0a4a commit 73a4b92

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pkg/crc/config/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"reflect"
66

77
"github.com/crc-org/crc/pkg/crc/preset"
8+
"github.com/crc-org/crc/pkg/crc/validation"
89
"github.com/spf13/cast"
910
)
1011

@@ -95,6 +96,25 @@ func (c *Config) Set(key string, value interface{}) (string, error) {
9596
return "", fmt.Errorf(invalidType, value, key)
9697
}
9798

99+
// Preset is mapped with `memory`, `cpus` and `bundle` and
100+
// we want to make sure if cpu or memory is less for a preset
101+
// then default is set automatic.
102+
if setting.Name == Preset {
103+
preset := preset.ParsePreset(value.(string))
104+
mem := c.Get(Memory)
105+
if err := validation.ValidateMemory(mem.AsInt(), preset); err != nil {
106+
if _, err := c.Unset(Memory); err != nil {
107+
return "", err
108+
}
109+
}
110+
cpu := c.Get(CPUs)
111+
if err := validation.ValidateCPUs(cpu.AsInt(), preset); err != nil {
112+
if _, err := c.Unset(CPUs); err != nil {
113+
return "", err
114+
}
115+
}
116+
}
117+
98118
// Make sure if user try to set same value which
99119
// is default then just unset the value which
100120
// anyway make it default and don't update it

0 commit comments

Comments
 (0)