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

[v22.1.x] rpk: improve wording in topic create: replication factor must be odd #5621

Closed
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
13 changes: 11 additions & 2 deletions src/go/rpk/pkg/cli/cmd/topic/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -91,15 +93,22 @@ 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)
}
},
}
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
Expand Down