redpanda-data / redpanda

Redpanda is a streaming data platform for developers. Kafka API compatible. 10x faster. No ZooKeeper. No JVM!
https://redpanda.com
9.44k stars 579 forks source link

Dry run for create topic doesn’t fail on pre-existing topic #10132

Open vovtz opened 1 year ago

vovtz commented 1 year ago

Version & Environment

Redpanda version: (use rpk version): 22.2.6 OS: the one used in container image docker.io/vectorized/redpanda K8s: 1.19.2 Client libraries: N/A

What went wrong?

I want to perform a ‘pre-flight’ step in a shell script (actually within the post-install job of the Helm chart), to make sure creating a topic will work. I would expect rpk topic create <topic-name> --dry … to fail if a topic is pre-exisiting, but it doesn’t.

What should have happened instead?

It should have failed the dry run, reflected in both the exit code and the textual response.

How to reproduce the issue?

  1. Start with a fresh Redpanda copy (e.g. container image in docker-compose or K8s)
  2. Run the below from the CLI (adjust the flags and their values to your environment):
    
    rpk topic create example-topic --dry --brokers redpanda-0.redpanda.greenpanda:9093 --tls-enabled --tls-truststore /etc/tls/certs/default/ca.crt --tls-key /etc/tls/certs/default/tls.key --tls-cert /etc/tls/certs/default/tls.crt

rpk topic create example-topic --replicas 1 --partitions 1 --brokers redpanda-0.redpanda.greenpanda:9093 --tls-enabled --tls-truststore /etc/tls/certs/default/ca.crt --tls-key /etc/tls/certs/default/tls.key --tls-cert /etc/tls/certs/default/tls.crt

rpk topic create example-topic --dry --brokers redpanda-0.redpanda.greenpanda:9093 --tls-enabled --tls-truststore /etc/tls/certs/default/ca.crt --tls-key /etc/tls/certs/default/tls.key --tls-cert /etc/tls/certs/default/tls.crt


### Additional information

Please attach any relevant logs, backtraces, or metric charts.

Output for all three `rpk` commands above is (exit code is 0 for all as well):

```log
TOPIC          STATUS
example-topic  OK

A more comprehensive explanation of my situation:

From a Bash script (in the post-install job of the Helm chart), I create some topics. Most of the time that just works (the job might need several attempts and have to spin up multiple pods, though, because often the server is not ready to receive requests yet), but sometimes a race condition appears: an earlier pod created by the job succeeded to create a topic, but not the next (why is a topic by itself), so the next pod fails to create the topic that already exists.

I hoped to do a ‘pre-flight’ for topic creation via the --dry flag, but now I find out that the result of running that is equal for a non-existing versus an existing topic. In all respects, both its textual response and its exit code. Is that by design? If so, do you have another recommendation to do a pre-flight?

JIRA Link: CORE-1274

r-vasquez commented 1 year ago

Related to: https://github.com/redpanda-data/redpanda/issues/7946, once that's fixed rpk will return the correct message.

CC. @graphcareful since you are assigned to #7946

emaxerrno commented 1 year ago

cc: @vshtokman

github-actions[bot] commented 1 month ago

This issue hasn't seen activity in 3 months. If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in two weeks.