@@ -70,6 +70,16 @@ func (c *Config) validate(key string, value interface{}) error {
70
70
return nil
71
71
}
72
72
73
+ func (c * Config ) revalidateSettingsValue (key string ) error {
74
+ if err := c .validate (key , c .Get (key )); err != nil {
75
+ if _ , err := c .Unset (key ); err != nil {
76
+ return err
77
+ }
78
+ }
79
+
80
+ return nil
81
+ }
82
+
73
83
// Set sets the value for a given config key
74
84
func (c * Config ) Set (key string , value interface {}) (string , error ) {
75
85
setting , ok := c .settingsByName [key ]
@@ -102,21 +112,15 @@ func (c *Config) Set(key string, value interface{}) (string, error) {
102
112
return "" , fmt .Errorf (invalidType , value , key )
103
113
}
104
114
105
- // Preset is mapped with `memory`, `cpus` and `bundle` and
106
- // we want to make sure if cpu or memory is less for a preset
107
- // then default is set automatic .
115
+ // The `memory` and `cpus` values are preset-dependent.
116
+ // When they are lower than the preset requirements, this code
117
+ // automatically resets them to their default value .
108
118
if setting .Name == Preset {
109
- mem := c .Get (Memory )
110
- if err := c .validate (Memory , mem ); err != nil {
111
- if _ , err := c .Unset (Memory ); err != nil {
112
- return "" , err
113
- }
119
+ if err := c .revalidateSettingsValue (Memory ); err != nil {
120
+ return "" , err
114
121
}
115
- cpu := c .Get (CPUs )
116
- if err := c .validate (CPUs , cpu ); err != nil {
117
- if _ , err := c .Unset (CPUs ); err != nil {
118
- return "" , err
119
- }
122
+ if err := c .revalidateSettingsValue (CPUs ); err != nil {
123
+ return "" , err
120
124
}
121
125
}
122
126
0 commit comments