@@ -41,6 +41,7 @@ import (
41
41
"github.com/cortexlabs/cortex/pkg/lib/sets/strset"
42
42
"github.com/cortexlabs/cortex/pkg/lib/slices"
43
43
libstr "github.com/cortexlabs/cortex/pkg/lib/strings"
44
+ s "github.com/cortexlabs/cortex/pkg/lib/strings"
44
45
"github.com/cortexlabs/cortex/pkg/lib/structs"
45
46
"github.com/cortexlabs/yaml"
46
47
)
@@ -165,6 +166,27 @@ type NodeGroup struct {
165
166
SpotConfig * SpotConfig `json:"spot_config" yaml:"spot_config"`
166
167
}
167
168
169
+ // compares the supported updatable fields of a nodegroup
170
+ func (ng * NodeGroup ) HasChanged (old * NodeGroup ) bool {
171
+ return ng .MaxInstances != old .MaxInstances || ng .MinInstances != old .MinInstances || ng .Priority != old .Priority
172
+ }
173
+
174
+ func (ng * NodeGroup ) UpdatePlan (old * NodeGroup ) string {
175
+ var changes []string
176
+
177
+ if old .MinInstances != ng .MinInstances {
178
+ changes = append (changes , fmt .Sprintf ("%s %d->%d" , MinInstancesKey , old .MinInstances , ng .MinInstances ))
179
+ }
180
+ if old .MaxInstances != ng .MaxInstances {
181
+ changes = append (changes , fmt .Sprintf ("%s %d->%d" , MaxInstancesKey , old .MaxInstances , ng .MaxInstances ))
182
+ }
183
+ if old .Priority != ng .Priority {
184
+ changes = append (changes , fmt .Sprintf ("%s %d->%d" , PriorityKey , old .Priority , ng .Priority ))
185
+ }
186
+
187
+ return fmt .Sprintf ("nodegroup %s will be updated with the following changes: %s" , ng .Name , s .StrsAnd (changes ))
188
+ }
189
+
168
190
type SpotConfig struct {
169
191
InstanceDistribution []string `json:"instance_distribution" yaml:"instance_distribution"`
170
192
OnDemandBaseCapacity * int64 `json:"on_demand_base_capacity" yaml:"on_demand_base_capacity"`
@@ -207,13 +229,13 @@ type AccessConfig struct {
207
229
type ConfigureChanges struct {
208
230
NodeGroupsToAdd []string
209
231
NodeGroupsToRemove []string
210
- NodeGroupsToScale []string
232
+ NodeGroupsToUpdate []string
211
233
EKSNodeGroupsToRemove []string // EKS node group names of (NodeGroupsToRemove ∩ Cortex-converted EKS node groups) ∪ (Cortex-converted EKS node groups - the new cluster config's nodegroups)
212
234
FieldsToUpdate []string
213
235
}
214
236
215
237
func (c * ConfigureChanges ) HasChanges () bool {
216
- return len (c .NodeGroupsToAdd )+ len (c .NodeGroupsToRemove )+ len (c .NodeGroupsToScale )+ len (c .EKSNodeGroupsToRemove )+ len (c .FieldsToUpdate ) != 0
238
+ return len (c .NodeGroupsToAdd )+ len (c .NodeGroupsToRemove )+ len (c .NodeGroupsToUpdate )+ len (c .EKSNodeGroupsToRemove )+ len (c .FieldsToUpdate ) != 0
217
239
}
218
240
219
241
// GetGhostEKSNodeGroups returns the set difference between EKSNodeGroupsToRemove and the EKS-converted NodeGroupsToRemove
@@ -1087,8 +1109,10 @@ func (cc *Config) validateSharedNodeGroupsDiff(oldConfig Config) error {
1087
1109
1088
1110
newNgCopy .MinInstances = 0
1089
1111
newNgCopy .MaxInstances = 0
1112
+ newNgCopy .Priority = 0
1090
1113
oldNgCopy .MinInstances = 0
1091
1114
oldNgCopy .MaxInstances = 0
1115
+ oldNgCopy .Priority = 0
1092
1116
1093
1117
newHash , err := newNgCopy .Hash ()
1094
1118
if err != nil {
@@ -1200,17 +1224,17 @@ func (cc *Config) ValidateOnConfigure(awsClient *aws.Client, k8sClient *k8s.Clie
1200
1224
}
1201
1225
1202
1226
sharedNgsFromNewConfig , sharedNgsFromOldConfig := cc .getCommonNodeGroups (oldConfig )
1203
- ngNamesToBeScaled := []* NodeGroup {}
1227
+ ngsToBeUpdated := []* NodeGroup {}
1204
1228
for i := range sharedNgsFromNewConfig {
1205
- if sharedNgsFromNewConfig [i ].MinInstances != sharedNgsFromOldConfig [i ]. MinInstances || sharedNgsFromNewConfig [ i ]. MaxInstances != sharedNgsFromOldConfig [ i ]. MaxInstances {
1206
- ngNamesToBeScaled = append (ngNamesToBeScaled , sharedNgsFromNewConfig [i ])
1229
+ if sharedNgsFromNewConfig [i ].HasChanged ( sharedNgsFromOldConfig [i ]) {
1230
+ ngsToBeUpdated = append (ngsToBeUpdated , sharedNgsFromNewConfig [i ])
1207
1231
}
1208
1232
}
1209
1233
1210
1234
return ConfigureChanges {
1211
1235
NodeGroupsToAdd : GetNodeGroupNames (ngsToBeAdded ),
1212
1236
NodeGroupsToRemove : GetNodeGroupNames (ngsToBeRemoved ),
1213
- NodeGroupsToScale : GetNodeGroupNames (ngNamesToBeScaled ),
1237
+ NodeGroupsToUpdate : GetNodeGroupNames (ngsToBeUpdated ),
1214
1238
EKSNodeGroupsToRemove : getStaleEksNodeGroups (cc .ClusterName , eksNodeGroupStacks , cc .NodeGroups , ngsToBeRemoved ),
1215
1239
FieldsToUpdate : fieldsToUpdate ,
1216
1240
}, nil
0 commit comments