Skip to content

Commit

Permalink
add ability to include internal topics in bootstrap (#192)
Browse files Browse the repository at this point in the history
* add ability to include double-underscore topics in `bootstrap`

* update flag name and readme

* fix formatting
  • Loading branch information
dtjm committed May 10, 2024
1 parent 20f0774 commit 12e49ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ The `bootstrap` subcommand creates apply topic configs from the existing topics
cluster. This can be used to "import" topics not created or previously managed by topicctl.
The output can be sent to either a directory (if the `--output` flag is set) or `stdout`.

By default, this does not include internal topics such as `__consumer_offsets`.
If you would like to have these topics included,
pass the `--allow-internal-topics` flag.

#### check

```
Expand Down
8 changes: 8 additions & 0 deletions cmd/topicctl/subcmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type bootstrapCmdConfig struct {
outputDir string
overwrite bool

allowInternalTopics bool

shared sharedOptions
}

Expand Down Expand Up @@ -52,6 +54,11 @@ func init() {
false,
"Overwrite existing configs in output directory",
)
bootstrapCmd.Flags().BoolVar(
&bootstrapConfig.allowInternalTopics,
"allow-internal-topics",
false,
"Include topics that start with __ (typically these are internal topics)")

addSharedConfigOnlyFlags(bootstrapCmd, &bootstrapConfig.shared)
bootstrapCmd.MarkFlagRequired("cluster-config")
Expand Down Expand Up @@ -92,5 +99,6 @@ func bootstrapRun(cmd *cobra.Command, args []string) error {
bootstrapConfig.excludeRegexp,
bootstrapConfig.outputDir,
bootstrapConfig.overwrite,
bootstrapConfig.allowInternalTopics,
)
}
3 changes: 2 additions & 1 deletion pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func (c *CLIRunner) BootstrapTopics(
excludeRegexpStr string,
outputDir string,
overwrite bool,
allowInternalTopics bool,
) error {
topicInfoObjs, err := c.adminClient.GetTopics(ctx, topics, false)
if err != nil {
Expand All @@ -226,7 +227,7 @@ func (c *CLIRunner) BootstrapTopics(
topicConfigs := []config.TopicConfig{}

for _, topicInfo := range topicInfoObjs {
if strings.HasPrefix(topicInfo.Name, "__") {
if !allowInternalTopics && strings.HasPrefix(topicInfo.Name, "__") {
// Never include underscore topics
continue
} else if !matchRegexp.MatchString(topicInfo.Name) {
Expand Down

0 comments on commit 12e49ad

Please sign in to comment.