Skip to content

Commit

Permalink
OCM-9340 | fix: Re-add max-surge/max-unavailable code
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterkepley committed Jul 9, 2024
1 parent 09b0674 commit 983b5fb
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion pkg/machinepool/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,12 @@ func editNodePool(cmd *cobra.Command, nodePoolID string,
isTuningsConfigSet := cmd.Flags().Changed("tuning-configs")
isKubeletConfigSet := cmd.Flags().Changed("kubelet-configs")
isNodeDrainGracePeriodSet := cmd.Flags().Changed("node-drain-grace-period")
isUpgradeMaxSurgeSet := cmd.Flags().Changed("max-surge")
isUpgradeMaxUnavailableSet := cmd.Flags().Changed("max-unavailable")

// isAnyAdditionalParameterSet is true if at least one parameter not related to replicas and autoscaling is set
isAnyAdditionalParameterSet := isLabelsSet || isTaintsSet || isAutorepairSet || isTuningsConfigSet ||
isKubeletConfigSet
isKubeletConfigSet || isUpgradeMaxSurgeSet || isUpgradeMaxUnavailableSet
isAnyParameterSet := isMinReplicasSet || isMaxReplicasSet || isReplicasSet ||
isAutoscalingSet || isAnyAdditionalParameterSet

Expand Down Expand Up @@ -777,6 +779,58 @@ func editNodePool(cmd *cobra.Command, nodePoolID string,
}
}

if isUpgradeMaxSurgeSet && isUpgradeMaxUnavailableSet {
maxSurge := cmd.Flags().Lookup("max-surge").Value.String()
if maxSurge == "" && nodePool.ManagementUpgrade().MaxSurge() != "" {
maxSurge = nodePool.ManagementUpgrade().MaxSurge()
}

maxUnavailable := cmd.Flags().Lookup("max-unavailable").Value.String()
if maxUnavailable == "" && nodePool.ManagementUpgrade().MaxUnavailable() != "" {
maxUnavailable = nodePool.ManagementUpgrade().MaxUnavailable()
}
if interactive.Enabled() {
maxSurge, err = interactive.GetString(interactive.Input{
Question: "Max surge",
Help: cmd.Flags().Lookup("max-surge").Usage,
Default: maxSurge,
Required: false,
Validators: []interactive.Validator{
mpHelpers.ValidateUpgradeMaxSurgeUnavailable,
},
})
if err != nil {
r.Reporter.Errorf("Expected a valid value for max surge: %s", err)
os.Exit(1)
}

maxUnavailable, err = interactive.GetString(interactive.Input{
Question: "Max unavailable",
Help: cmd.Flags().Lookup("max-unavailable").Usage,
Default: maxUnavailable,
Required: false,
Validators: []interactive.Validator{
mpHelpers.ValidateUpgradeMaxSurgeUnavailable,
},
})
if err != nil {
r.Reporter.Errorf("Expected a valid value for max unavailable: %s", err)
os.Exit(1)
}
}

if maxSurge != "" || maxUnavailable != "" {
mgmtUpgradeBuilder := cmv1.NewNodePoolManagementUpgrade()
if maxSurge != "" {
mgmtUpgradeBuilder.MaxSurge(maxSurge)
}
if maxUnavailable != "" {
mgmtUpgradeBuilder.MaxUnavailable(maxUnavailable)
}
npBuilder.ManagementUpgrade(mgmtUpgradeBuilder)
}
}

update, err := npBuilder.Build()
if err != nil {
return fmt.Errorf("Failed to create machine pool for hosted cluster '%s': %v", clusterKey, err)
Expand Down

0 comments on commit 983b5fb

Please sign in to comment.