From 576a833d5656c34d29479d2cc61b978472a123f9 Mon Sep 17 00:00:00 2001 From: Rogger Vasquez Date: Tue, 17 May 2022 17:21:56 -0500 Subject: [PATCH] rpk: improve wording in topic create: replication factor must be odd (cherry picked from commit 2eeed7658e493ebc08d19941bea17983b36080c4) --- src/go/rpk/pkg/cli/cmd/topic/create.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/go/rpk/pkg/cli/cmd/topic/create.go b/src/go/rpk/pkg/cli/cmd/topic/create.go index 67e1890cd2f4..b88022a83185 100644 --- a/src/go/rpk/pkg/cli/cmd/topic/create.go +++ b/src/go/rpk/pkg/cli/cmd/topic/create.go @@ -11,6 +11,8 @@ package topic import ( "context" + "errors" + "fmt" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/kafka" @@ -91,7 +93,14 @@ the cleanup.policy=compact config option set. for _, topic := range resp.Topics { msg := "OK" if err := kerr.ErrorForCode(topic.ErrorCode); err != nil { - msg = err.Error() + if errors.Is(err, kerr.InvalidPartitions) && partitions > 0 { + msg = fmt.Sprintf("INVALID_PARTITIONS: unable to create topic with %d partitions due to hardware constraints", partitions) + } else if errors.Is(err, kerr.InvalidReplicationFactor) && replicas%2 == 0 { + msg = "INVALID_REPLICATION_FACTOR: replication factor must be odd" + } else { + msg = err.Error() + } + exit1 = true } tw.Print(topic.Topic, msg) } @@ -99,7 +108,7 @@ the cleanup.policy=compact config option set. } cmd.Flags().StringArrayVarP(&configKVs, "topic-config", "c", nil, "key=value; Config parameters (repeatable; e.g. -c cleanup.policy=compact)") cmd.Flags().Int32VarP(&partitions, "partitions", "p", 1, "Number of partitions to create per topic") - cmd.Flags().Int16VarP(&replicas, "replicas", "r", -1, "Replication factor; if -1, this will be the broker's default.replication.factor") + cmd.Flags().Int16VarP(&replicas, "replicas", "r", -1, "Replication factor (must be odd); if -1, this will be the broker's default.replication.factor") cmd.Flags().BoolVarP(&dry, "dry", "d", false, "dry run: validate the topic creation request; do not create topics") // Sept 2021