Skip to content

Commit

Permalink
OCM-8020 | feat: Update rosa edit machinepool command for kubeletconf…
Browse files Browse the repository at this point in the history
…ig support
  • Loading branch information
robpblake committed May 14, 2024
1 parent 127cc35 commit 72e98c3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cmd/edit/machinepool/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var args struct {
version string
autorepair bool
tuningConfigs string
kubeletConfigs string
nodeDrainGracePeriod string
}

Expand Down Expand Up @@ -135,6 +136,15 @@ func init() {
"This list will overwrite any modifications made to node tuning configs on an ongoing basis.",
)

flags.StringVar(
&args.kubeletConfigs,
"kubelet-configs",
"",
"Name of the kubelet configs to be applied to the machine pool. Format should be a comma-separated list. "+
"Kubelet config must already exist. "+
"This list will overwrite any modifications made to node kubelet configs on an ongoing basis.",
)

flags.StringVar(&args.nodeDrainGracePeriod,
"node-drain-grace-period",
"",
Expand Down
46 changes: 45 additions & 1 deletion cmd/edit/machinepool/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func editNodePool(cmd *cobra.Command, nodePoolID string,
isVersionSet := cmd.Flags().Changed("version")
isAutorepairSet := cmd.Flags().Changed("autorepair")
isTuningsConfigSet := cmd.Flags().Changed("tuning-configs")
isKubeletConfigSet := cmd.Flags().Changed("kubelet-configs")
isNodeDrainGracePeriodSet := cmd.Flags().Changed("node-drain-grace-period")

// we don't support anymore the version parameter
Expand All @@ -35,7 +36,8 @@ func editNodePool(cmd *cobra.Command, nodePoolID string,
}

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

Expand Down Expand Up @@ -152,6 +154,48 @@ func editNodePool(cmd *cobra.Command, nodePoolID string,
npBuilder.TuningConfigs(inputTuningConfig...)
}

if isKubeletConfigSet || interactive.Enabled() {
var inputKubeletConfig []string
kubeletConfigs := args.kubeletConfigs
// Get the list of available tuning configs
availableKubeletConfigs, err := r.OCMClient.ListKubeletConfigNames(cluster.ID())
if err != nil {
return fmt.Errorf("%s", err)
}
if kubeletConfigs != "" {
if len(availableKubeletConfigs) > 0 {
inputKubeletConfig = strings.Split(kubeletConfigs, ",")
} else {
// Parameter will be ignored
r.Reporter.Warnf("No kubelet config available for cluster '%s'. "+
"Any kubelet config in input will be ignored", cluster.ID())
}
}

if interactive.Enabled() {
if !isKubeletConfigSet {
// Interactive mode without explicit input parameter. Take the existing value
inputKubeletConfig = nodePool.KubeletConfigs()
}

// Skip if no tuning configs are available
if len(availableKubeletConfigs) > 0 {
inputKubeletConfig, err = interactive.GetMultipleOptions(interactive.Input{
Question: "Kubelet configs",
Help: cmd.Flags().Lookup("kubelet-configs").Usage,
Options: availableKubeletConfigs,
Default: inputKubeletConfig,
Required: false,
})
if err != nil {
return fmt.Errorf("Expected a valid value for kubelet configs: %s", err)
}
}
}

npBuilder.KubeletConfigs(inputKubeletConfig...)
}

if isNodeDrainGracePeriodSet || interactive.Enabled() {
nodeDrainGracePeriod := args.nodeDrainGracePeriod
if nodeDrainGracePeriod == "" && nodePool.NodeDrainGracePeriod() != nil &&
Expand Down

0 comments on commit 72e98c3

Please sign in to comment.