Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCM-7268 | feat: Update create machinepool command to support kubeletconfigs #2045

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/create/machinepool/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var args struct {
version string
autorepair bool
tuningConfigs string
kubeletConfigs string
rootDiskSize string
securityGroupIds []string
nodeDrainGracePeriod string
Expand Down Expand Up @@ -207,6 +208,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.rootDiskSize,
"disk-size",
"",
Expand Down
38 changes: 38 additions & 0 deletions cmd/create/machinepool/nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,44 @@ func addNodePool(cmd *cobra.Command, clusterKey string, cluster *cmv1.Cluster, r
npBuilder.TuningConfigs(inputTuningConfig...)
}

var inputKubeletConfigs []string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an active task on-going to refactor the create machinepool command to align with the runner model. I'm following the existing implementation at the minute to avoid do a large refactor in this PR.

kubeletConfigs := args.kubeletConfigs
// Get the list of available kubelet configs
availableKubeletConfigs, err := r.OCMClient.ListKubeletConfigNames(cluster.ID())
if err != nil {
r.Reporter.Errorf("%s", err)
os.Exit(1)
}
if kubeletConfigs != "" {
if len(availableKubeletConfigs) > 0 {
inputKubeletConfigs = 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() {
// Skip if no kubelet configs are available
if len(availableKubeletConfigs) > 0 {
inputKubeletConfigs, err = interactive.GetMultipleOptions(interactive.Input{
Question: "Kubelet configs",
Help: cmd.Flags().Lookup("kubelet-configs").Usage,
Options: availableKubeletConfigs,
Default: inputKubeletConfigs,
Required: false,
})
if err != nil {
r.Reporter.Errorf("Expected a valid value for kubelet configs: %s", err)
os.Exit(1)
}
}
}

if len(inputKubeletConfigs) != 0 {
npBuilder.KubeletConfigs(inputKubeletConfigs...)
}

npBuilder.AWSNodePool(createAwsNodePoolBuilder(instanceType, securityGroupIds, awsTags))

nodeDrainGracePeriod := args.nodeDrainGracePeriod
Expand Down
16 changes: 16 additions & 0 deletions pkg/ocm/kubeletconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ func toOCMKubeletConfig(args KubeletConfigArgs) (*cmv1.KubeletConfig, error) {
return kubeletConfig, nil
}

func (c *Client) ListKubeletConfigNames(clusterId string) ([]string, error) {
configs, err := c.ListKubeletConfigs(context.Background(), clusterId)
if err != nil {
return make([]string, 0), err
}

var names []string

if len(configs) > 0 {
for _, c := range configs {
names = append(names, c.Name())
}
}
return names, nil
}

func (c *Client) CreateKubeletConfig(clusterID string, args KubeletConfigArgs) (*cmv1.KubeletConfig, error) {

kubeletConfig, err := toOCMKubeletConfig(args)
Expand Down
35 changes: 35 additions & 0 deletions pkg/ocm/kubeletconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
"time"

"slices"

. "github.com/onsi/ginkgo/v2/dsl/core"
. "github.com/onsi/ginkgo/v2/dsl/decorators"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -314,6 +316,39 @@ var _ = Describe("KubeletConfig", Ordered, func() {
Expect(kubeletConfig.PodPidsLimit()).To(Equal(10000))
})
})

Context("Get KubeletConfig names", func() {
It("Gets the name of available KubeletConfigs", func() {
apiServer.AppendHandlers(
RespondWithJSON(
http.StatusOK, createKubeletConfigList(false)))

names, err := ocmClient.ListKubeletConfigNames(clusterId)
Expect(err).NotTo(HaveOccurred())
Expect(slices.Contains(names, kubeletName)).To(BeTrue())
})

It("Returns an empty list if no kubeletconfigs available", func() {
apiServer.AppendHandlers(
RespondWithJSON(
http.StatusOK, createKubeletConfigList(true)))

names, err := ocmClient.ListKubeletConfigNames(clusterId)
Expect(err).NotTo(HaveOccurred())
Expect(names).To(BeEmpty())
})

It("Returns an error if failing to list KubeletConfig names", func() {
apiServer.AppendHandlers(
RespondWithJSON(
http.StatusInternalServerError, createKubeletConfigList(false)))

names, err := ocmClient.ListKubeletConfigNames(clusterId)
Expect(err).To(HaveOccurred())
Expect(names).To(BeEmpty())
})

})
})

func createKubeletConfig() (string, error) {
Expand Down