Skip to content

Commit 87bd0e5

Browse files
sgagniereBrian Strauch
andauthored
[CLI-1830] Show better error when shrinking Kafka cluster by more than 1 cku (#1364)
* Modified one of the error handling statements in command_cluster_update.go to not wrap a suggestion as an error * un-capitalize first word in error message Co-authored-by: Brian Strauch <bstrauch@confluent.io> * Added new integration test for shrinking dedicated cluster by more than 1 cku * Switched if statements to a switch as suggested * Updated new error messsage * Forgot to run go fmt Co-authored-by: Brian Strauch <bstrauch@confluent.io>
1 parent 6847394 commit 87bd0e5

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

internal/cmd/kafka/command_cluster_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (c *clusterCommand) update(cmd *cobra.Command, args []string, prompt form.P
8989

9090
updatedCluster, httpResp, err := c.V2Client.UpdateKafkaCluster(clusterID, update)
9191
if err != nil {
92-
return errors.Wrap(errors.CatchV2ErrorDetailWithResponse(err, httpResp), errors.KafkaClusterUpdateFailedSuggestions)
92+
return errors.NewWrapErrorWithSuggestions(errors.CatchV2ErrorDetailWithResponse(err, httpResp), "failed to update Kafka cluster", errors.KafkaClusterUpdateFailedSuggestions)
9393
}
9494

9595
return c.outputKafkaClusterDescription(cmd, &updatedCluster)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Error: failed to update Kafka cluster: Bad Request: 400 Bad Request
2+
3+
Suggestions:
4+
A cluster can't be updated while still provisioning. If you just created this cluster, retry in a few minutes.

test/kafka_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func (s *CLITestSuite) TestKafka() {
4747
{args: "kafka cluster update lkc-update --cku 2", fixture: "kafka/kafka-cluster-resize-error.golden", wantErrCode: 1},
4848
{args: "kafka cluster update lkc-update-dedicated-shrink --name lkc-update-dedicated-name --cku 1", fixture: "kafka/44.golden"},
4949
{args: "kafka cluster update lkc-update-dedicated-shrink --cku 1", fixture: "kafka/45.golden"},
50+
{args: "kafka cluster update lkc-update-dedicated-shrink-multi --cku 1", fixture: "kafka/kafka-cluster-dedicated-shrink-error.golden", wantErrCode: 1},
5051
{args: "kafka cluster update lkc-update --cku 1", fixture: "kafka/kafka-cluster-resize-error.golden", wantErrCode: 1},
5152

5253
{args: "kafka cluster delete", fixture: "kafka/3.golden", wantErrCode: 1},

test/test-server/cmk_handlers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func handleCmkCluster(t *testing.T) http.HandlerFunc {
145145
handleCmkKafkaDedicatedClusterExpansion(t)(w, r)
146146
case "lkc-update-dedicated-shrink":
147147
handleCmkKafkaDedicatedClusterShrink(t)(w, r)
148+
case "lkc-update-dedicated-shrink-multi":
149+
handleCmkKafkaDedicatedClusterShrinkMulti(t)(w, r)
148150
case "lkc-unknown":
149151
err := writeResourceNotFoundError(w)
150152
require.NoError(t, err)
@@ -301,3 +303,21 @@ func handleCmkKafkaDedicatedClusterShrink(t *testing.T) http.HandlerFunc {
301303
}
302304
}
303305
}
306+
307+
// Handler for GET/PATCH "/cmk/v2/clusters/lkc-update-dedicated-shrink-multi"
308+
func handleCmkKafkaDedicatedClusterShrinkMulti(t *testing.T) http.HandlerFunc {
309+
return func(w http.ResponseWriter, r *http.Request) {
310+
w.Header().Set("Content-Type", "application/json")
311+
switch r.Method {
312+
case http.MethodGet:
313+
id := r.URL.Query().Get("id")
314+
cluster := getCmkDedicatedDescribeCluster(id, "lkc-update-dedicated-shrink-multi", 3)
315+
err := json.NewEncoder(w).Encode(cluster)
316+
require.NoError(t, err)
317+
case http.MethodPatch:
318+
w.WriteHeader(http.StatusBadRequest)
319+
_, err := io.WriteString(w, badRequestErrMsg)
320+
require.NoError(t, err)
321+
}
322+
}
323+
}

test/test-server/utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var (
2020
serviceAccountInvalidErrMsg = `{"errors":[{"status":"403","detail":"service account is not valid"}]}`
2121
resourceNotFoundErrMsg = `{"errors":[{"status":"403","detail":"resource not found"}]}`
2222
v1ResourceNotFoundErrMsg = `{"error":{"code":403,"message":"resource not found","nested_errors":{},"details":[],"stack":null},"cluster":null}`
23+
badRequestErrMsg = `{"errors":[{"status":"400","detail":"Bad Request"}]}`
2324
)
2425

2526
type ApiKeyList []*schedv1.ApiKey

0 commit comments

Comments
 (0)