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

Fix rpk topic add-partition panic #5369

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/go/rpk/pkg/cli/cmd/topic/add_partitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewAddPartitionsCommand(fs afero.Fs) *cobra.Command {
if errors.Is(e, kerr.InvalidPartitions) && num > 0 {
msg = fmt.Sprintf("INVALID_PARTITIONS: unable to add %d partitions due to hardware constraints", num)
} else {
msg = err.Error()
msg = e.Error()
}
exit1 = true
}
Expand Down
4 changes: 4 additions & 0 deletions tests/rptest/clients/rpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def create_topic(self, topic, partitions=1, replicas=None, config=None):
self._check_stdout_success(output)
return output

def add_partitions(self, topic, partitions):
cmd = ["add-partitions", topic, "-n", str(partitions)]
return self._run_topic(cmd)

def _check_stdout_success(self, output):
"""
Helper for topic operations where rpk does not surface errors
Expand Down
7 changes: 7 additions & 0 deletions tests/rptest/tests/rpk_topic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def test_create_topic_with_invalid_config(self, config_type):
lambda e: "INVALID_CONFIG" in str(e)):
out = self._rpk.create_topic("topic", config={config_type: "foo"})

@cluster(num_nodes=1)
def test_add_unfeasible_number_of_partitions(self):
with expect_exception(RpkException,
lambda e: "INVALID_REQUEST" in str(e)):
self._rpk.create_topic("topic")
out = self._rpk.add_partitions("topic", 2000000000000)

@cluster(num_nodes=4)
def test_produce(self):
topic = 'topic'
Expand Down