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

LP-3339: Fix --cku description for kafka cluster update #2379

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 12 additions & 9 deletions internal/kafka/command_cluster_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *clusterCommand) newUpdateCommand() *cobra.Command {
}

cmd.Flags().String("name", "", "Name of the Kafka cluster.")
cmd.Flags().Uint32("cku", 0, `Number of Confluent Kafka Units. For Kafka clusters of type "dedicated" only. When shrinking a cluster, you must reduce capacity one CKU at a time.`)
cmd.Flags().Uint32("cku", 0, `Number of Confluent Kafka Units. For Kafka clusters of type "dedicated" only.`)
pcmd.AddContextFlag(cmd, c.CLICommand)
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
pcmd.AddOutputFlag(cmd)
Expand Down Expand Up @@ -97,24 +97,26 @@ func (c *clusterCommand) update(cmd *cobra.Command, args []string) error {
}

func (c *clusterCommand) validateResize(cku int32, currentCluster *cmkv2.CmkV2Cluster) (int32, error) {
// Ensure the cluster is a Dedicated Cluster
if currentCluster.GetSpec().Config.CmkV2Dedicated == nil {
if currentCluster.Spec.Config.CmkV2Dedicated == nil {
return 0, fmt.Errorf("failed to update Kafka cluster: cluster resize is only supported on dedicated clusters")
}
// Durability Checks

if currentCluster.Spec.GetAvailability() == highAvailability && cku <= 1 {
return 0, fmt.Errorf("`--cku` value must be greater than 1 for high durability")
}

if cku == 0 {
return 0, fmt.Errorf(errors.CkuMoreThanZeroErrorMsg)
}

// Cluster can't be resized while it's provisioning or being expanded already.
// Name _can_ be changed during these times, though.
if err := isClusterResizeInProgress(currentCluster); err != nil {
return 0, err
}

// If shrink
if cku < currentCluster.GetSpec().Config.CmkV2Dedicated.Cku {
if cku < currentCluster.Spec.Config.CmkV2Dedicated.GetCku() {
promptMessage := ""
// metrics api auth via jwt
if err := c.validateKafkaClusterMetrics(currentCluster, true); err != nil {
Expand All @@ -138,20 +140,21 @@ func (c *clusterCommand) validateKafkaClusterMetrics(currentCluster *cmkv2.CmkV2
window = "15 min"
}

if err := c.validateClusterLoad(*currentCluster.Id, isLatestMetric); err != nil {
if err := c.validateClusterLoad(currentCluster.GetId(), isLatestMetric); err != nil {
return fmt.Errorf("Looking at metrics in the last %s window:\n%v", window, err)
}

return nil
}

func confirmShrink(promptMessage string) (bool, error) {
f := form.New(form.Field{ID: "proceed", Prompt: fmt.Sprintf("Validated cluster metrics and found that: %s\nDo you want to proceed with shrinking your kafka cluster?", promptMessage), IsYesOrNo: true})
prompt := fmt.Sprintf("Validated cluster metrics and found that: %s\nDo you want to proceed with shrinking your Kafka cluster?", promptMessage)
f := form.New(form.Field{ID: "proceed", Prompt: prompt, IsYesOrNo: true})
if err := f.Prompt(form.NewPrompt()); err != nil {
return false, fmt.Errorf("cluster resize error: failed to read your confirmation")
return false, fmt.Errorf("cluster resize error: failed to read confirmation: %w", err)
}
if !f.Responses["proceed"].(bool) {
output.Println(false, "Not proceeding with kafka cluster shrink")
output.Println(false, "Not proceeding with Kafka cluster shrink")
return false, nil
}
return true, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Update the name and CKU count of a Kafka cluster:

Flags:
--name string Name of the Kafka cluster.
--cku uint32 Number of Confluent Kafka Units. For Kafka clusters of type "dedicated" only. When shrinking a cluster, you must reduce capacity one CKU at a time.
--cku uint32 Number of Confluent Kafka Units. For Kafka clusters of type "dedicated" only.
--context string CLI context name.
--environment string Environment ID.
-o, --output string Specify the output format as "human", "json", or "yaml". (default "human")
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/output/kafka/cluster/update-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Update the name and CKU count of a Kafka cluster:

Flags:
--name string Name of the Kafka cluster.
--cku uint32 Number of Confluent Kafka Units. For Kafka clusters of type "dedicated" only. When shrinking a cluster, you must reduce capacity one CKU at a time.
--cku uint32 Number of Confluent Kafka Units. For Kafka clusters of type "dedicated" only.
--context string CLI context name.
--environment string Environment ID.
-o, --output string Specify the output format as "human", "json", or "yaml". (default "human")
Expand Down