Skip to content

Commit

Permalink
OCM-8112 | fix: Force users into interactive mode if omitting a name …
Browse files Browse the repository at this point in the history
…when creating a KubeletConfig for HCP clusters
  • Loading branch information
robpblake committed May 17, 2024
1 parent 193245a commit db1bba7
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 30 deletions.
2 changes: 1 addition & 1 deletion cmd/create/kubeletconfig/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func CreateKubeletConfigRunner(options *KubeletConfigOptions) rosa.CommandRunner
"You should edit it via 'rosa edit kubeletconfig'", clusterKey)
}
} else {
options.Name, err = PromptForName(options.Name)
options.Name, err = PromptForName(options.Name, true)
if err != nil {
return err
}
Expand Down
24 changes: 0 additions & 24 deletions cmd/create/kubeletconfig/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,6 @@ var _ = Describe("create kubeletconfig", func() {
ContainSubstring("Failed getting KubeletConfig for cluster 'cluster'"))
})

It("Returns an error if no name specified for HCP KubeletConfig", func() {
cluster := MockCluster(func(c *cmv1.ClusterBuilder) {
c.State(cmv1.ClusterStateReady)
b := cmv1.HypershiftBuilder{}
b.Enabled(true)
c.Hypershift(&b)

})

t.ApiServer.AppendHandlers(
testing.RespondWithJSON(
http.StatusOK, FormatClusterList([]*cmv1.Cluster{cluster})))
t.SetCluster("cluster", cluster)

options := NewKubeletConfigOptions()
options.PodPidsLimit = 10000

runner := CreateKubeletConfigRunner(options)

err := runner(context.Background(), t.RosaRuntime, nil, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("The --name flag is required for Hosted Control Plane clusters."))
})

It("Creates the KubeletConfig for HCP clusters", func() {
cluster := MockCluster(func(c *cmv1.ClusterBuilder) {
c.State(cmv1.ClusterStateReady)
Expand Down
2 changes: 1 addition & 1 deletion cmd/describe/kubeletconfig/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func DescribeKubeletConfigRunner(options *KubeletConfigOptions) rosa.CommandRunn
var exists bool

if cluster.Hypershift().Enabled() {
options.Name, err = PromptForName(options.Name)
options.Name, err = PromptForName(options.Name, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dlt/kubeletconfig/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func DeleteKubeletConfigRunner(options *KubeletConfigOptions) rosa.CommandRunner
}

if cluster.Hypershift().Enabled() {
options.Name, err = PromptForName(options.Name)
options.Name, err = PromptForName(options.Name, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/edit/kubeletconfig/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func EditKubeletConfigRunner(options *KubeletConfigOptions) rosa.CommandRunner {
var exists bool

if cluster.Hypershift().Enabled() {
options.Name, err = PromptForName(options.Name)
options.Name, err = PromptForName(options.Name, false)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/kubeletconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func GetInteractiveInput(maxPidsLimit int, kubeletConfig *v1.KubeletConfig) inte
}
}

func PromptForName(requestedName string) (string, error) {
func PromptForName(requestedName string, forceInteractive bool) (string, error) {

if requestedName == "" && interactive.Enabled() {
if requestedName == "" && forceInteractive {
interactive.Enable()
return interactive.GetString(interactive.Input{
Question: InteractiveNameHelpPrompt,
Help: InteractiveNameHelp,
Expand Down

0 comments on commit db1bba7

Please sign in to comment.