diff --git a/internal/kafka/command_cluster_update.go b/internal/kafka/command_cluster_update.go index 41dd33ab64..b72b7893e2 100644 --- a/internal/kafka/command_cluster_update.go +++ b/internal/kafka/command_cluster_update.go @@ -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) @@ -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 { @@ -138,7 +140,7 @@ 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) } @@ -146,12 +148,13 @@ func (c *clusterCommand) validateKafkaClusterMetrics(currentCluster *cmkv2.CmkV2 } 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 diff --git a/test/fixtures/output/kafka/cluster/create-flag-error.golden b/test/fixtures/output/kafka/cluster/create-flag-error.golden index a507e142a0..9e8e87b1a2 100644 --- a/test/fixtures/output/kafka/cluster/create-flag-error.golden +++ b/test/fixtures/output/kafka/cluster/create-flag-error.golden @@ -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") diff --git a/test/fixtures/output/kafka/cluster/update-help.golden b/test/fixtures/output/kafka/cluster/update-help.golden index 1b05c247ce..fd580d903e 100644 --- a/test/fixtures/output/kafka/cluster/update-help.golden +++ b/test/fixtures/output/kafka/cluster/update-help.golden @@ -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")