Skip to content

Commit fc08788

Browse files
authored
Update priority on a running cluster (#2369)
1 parent 8aaf5fd commit fc08788

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

cli/cmd/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ var _clusterConfigureCmd = &cobra.Command{
390390
confirmConfigureClusterConfig(configureChanges, oldClusterConfig, *newClusterConfig, _flagClusterDisallowPrompt)
391391

392392
out, exitCode, err := runManagerWithClusterConfig("/root/install.sh --configure", newClusterConfig, awsClient, nil, nil, []string{
393-
"CORTEX_NODEGROUP_NAMES_TO_SCALE=" + strings.Join(configureChanges.NodeGroupsToScale, " "), // NodeGroupsToScale contain the cluster config node-group names
393+
"CORTEX_NODEGROUP_NAMES_TO_UPDATE=" + strings.Join(configureChanges.NodeGroupsToUpdate, " "), // NodeGroupsToUpdate contain the cluster config node-group names
394394
"CORTEX_NODEGROUP_NAMES_TO_ADD=" + strings.Join(configureChanges.NodeGroupsToAdd, " "), // NodeGroupsToAdd contain the cluster config node-group names
395395
"CORTEX_EKS_NODEGROUP_NAMES_TO_REMOVE=" + strings.Join(configureChanges.EKSNodeGroupsToRemove, " "), // EKSNodeGroupsToRemove contain the EKS node-group names
396396
})

cli/cmd/lib_cluster_config.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,10 @@ func confirmConfigureClusterConfig(configureChanges clusterconfig.ConfigureChang
290290
fmt.Printf("○ %s will be updated\n", fieldToUpdate)
291291
}
292292

293-
for _, ngName := range configureChanges.NodeGroupsToScale {
293+
for _, ngName := range configureChanges.NodeGroupsToUpdate {
294294
ngOld := oldCc.GetNodeGroupByName(ngName)
295-
ngScaled := newCc.GetNodeGroupByName(ngName)
296-
if ngOld.MinInstances != ngScaled.MinInstances && ngOld.MaxInstances != ngScaled.MaxInstances {
297-
fmt.Printf("○ nodegroup %s will update %s from %d to %d and %s from %d to %d\n", ngName, clusterconfig.MinInstancesKey, ngOld.MinInstances, ngScaled.MinInstances, clusterconfig.MaxInstancesKey, ngOld.MaxInstances, ngScaled.MaxInstances)
298-
} else if ngOld.MinInstances == ngScaled.MinInstances && ngOld.MaxInstances != ngScaled.MaxInstances {
299-
fmt.Printf("○ nodegroup %s will update %s from %d to %d\n", ngName, clusterconfig.MaxInstancesKey, ngOld.MaxInstances, ngScaled.MaxInstances)
300-
} else if ngOld.MinInstances != ngScaled.MinInstances && ngOld.MaxInstances == ngScaled.MaxInstances {
301-
fmt.Printf("○ nodegroup %s will update %s from %d to %d\n", ngName, clusterconfig.MinInstancesKey, ngOld.MinInstances, ngScaled.MinInstances)
302-
}
295+
ngNew := newCc.GetNodeGroupByName(ngName)
296+
fmt.Printf("○ %s\n", ngNew.UpdatePlan(ngOld))
303297
}
304298

305299
for _, ngName := range configureChanges.NodeGroupsToAdd {

manager/install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,15 @@ function restart_controller_manager() {
287287
}
288288

289289
function resize_nodegroups() {
290-
if [ -z "$CORTEX_NODEGROUP_NAMES_TO_SCALE" ]; then
290+
if [ -z "$CORTEX_NODEGROUP_NAMES_TO_UPDATE" ]; then
291291
return
292292
fi
293293

294294
eksctl get nodegroup --cluster=$CORTEX_CLUSTER_NAME --region=$CORTEX_REGION --verbose=0 -o json > nodegroups.json
295295
eks_ng_len=$(cat nodegroups.json | jq -r length)
296296
cfg_ng_len=$(cat $CORTEX_CLUSTER_CONFIG_FILE | yq -r .node_groups | yq -r length)
297297

298-
for cfg_ng_name in $CORTEX_NODEGROUP_NAMES_TO_SCALE; do
298+
for cfg_ng_name in $CORTEX_NODEGROUP_NAMES_TO_UPDATE; do
299299
has_ng="false"
300300
for eks_idx in $(seq 0 $(($eks_ng_len-1))); do
301301
stack_ng=$(cat nodegroups.json | jq -r .[$eks_idx].Name)

pkg/types/clusterconfig/cluster_config.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
168190
type 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 {
207229
type 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

215237
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
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

pkg/types/clusterconfig/config_key.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const (
2929
AcceleratorsPerInstanceKey = "accelerators_per_instance"
3030
MinInstancesKey = "min_instances"
3131
MaxInstancesKey = "max_instances"
32+
PriorityKey = "priority"
3233
SpotKey = "spot"
3334
SpotConfigKey = "spot_config"
3435
InstanceDistributionKey = "instance_distribution"

0 commit comments

Comments
 (0)