@@ -41,6 +41,7 @@ import (
4141 "github.com/cortexlabs/cortex/pkg/lib/sets/strset"
4242 "github.com/cortexlabs/cortex/pkg/lib/slices"
4343 libstr "github.com/cortexlabs/cortex/pkg/lib/strings"
44+ s "github.com/cortexlabs/cortex/pkg/lib/strings"
4445 "github.com/cortexlabs/cortex/pkg/lib/structs"
4546 "github.com/cortexlabs/yaml"
4647)
@@ -165,6 +166,27 @@ type NodeGroup struct {
165166 SpotConfig * SpotConfig `json:"spot_config" yaml:"spot_config"`
166167}
167168
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+
168190type SpotConfig struct {
169191 InstanceDistribution []string `json:"instance_distribution" yaml:"instance_distribution"`
170192 OnDemandBaseCapacity * int64 `json:"on_demand_base_capacity" yaml:"on_demand_base_capacity"`
@@ -207,13 +229,13 @@ type AccessConfig struct {
207229type ConfigureChanges struct {
208230 NodeGroupsToAdd []string
209231 NodeGroupsToRemove []string
210- NodeGroupsToScale []string
232+ NodeGroupsToUpdate []string
211233 EKSNodeGroupsToRemove []string // EKS node group names of (NodeGroupsToRemove ∩ Cortex-converted EKS node groups) ∪ (Cortex-converted EKS node groups - the new cluster config's nodegroups)
212234 FieldsToUpdate []string
213235}
214236
215237func (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
217239}
218240
219241// GetGhostEKSNodeGroups returns the set difference between EKSNodeGroupsToRemove and the EKS-converted NodeGroupsToRemove
@@ -1087,8 +1109,10 @@ func (cc *Config) validateSharedNodeGroupsDiff(oldConfig Config) error {
10871109
10881110 newNgCopy .MinInstances = 0
10891111 newNgCopy .MaxInstances = 0
1112+ newNgCopy .Priority = 0
10901113 oldNgCopy .MinInstances = 0
10911114 oldNgCopy .MaxInstances = 0
1115+ oldNgCopy .Priority = 0
10921116
10931117 newHash , err := newNgCopy .Hash ()
10941118 if err != nil {
@@ -1200,17 +1224,17 @@ func (cc *Config) ValidateOnConfigure(awsClient *aws.Client, k8sClient *k8s.Clie
12001224 }
12011225
12021226 sharedNgsFromNewConfig , sharedNgsFromOldConfig := cc .getCommonNodeGroups (oldConfig )
1203- ngNamesToBeScaled := []* NodeGroup {}
1227+ ngsToBeUpdated := []* NodeGroup {}
12041228 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 ])
12071231 }
12081232 }
12091233
12101234 return ConfigureChanges {
12111235 NodeGroupsToAdd : GetNodeGroupNames (ngsToBeAdded ),
12121236 NodeGroupsToRemove : GetNodeGroupNames (ngsToBeRemoved ),
1213- NodeGroupsToScale : GetNodeGroupNames (ngNamesToBeScaled ),
1237+ NodeGroupsToUpdate : GetNodeGroupNames (ngsToBeUpdated ),
12141238 EKSNodeGroupsToRemove : getStaleEksNodeGroups (cc .ClusterName , eksNodeGroupStacks , cc .NodeGroups , ngsToBeRemoved ),
12151239 FieldsToUpdate : fieldsToUpdate ,
12161240 }, nil
0 commit comments