Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
brianstrauch committed Nov 30, 2023
1 parent bc08075 commit 8a7811e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/kafka/command_cluster_update.go
Original file line number Diff line number Diff line change
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

0 comments on commit 8a7811e

Please sign in to comment.