Skip to content

Commit 12e49ad

Browse files
authored
add ability to include internal topics in bootstrap (#192)
* add ability to include double-underscore topics in `bootstrap` * update flag name and readme * fix formatting
1 parent 20f0774 commit 12e49ad

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ The `bootstrap` subcommand creates apply topic configs from the existing topics
145145
cluster. This can be used to "import" topics not created or previously managed by topicctl.
146146
The output can be sent to either a directory (if the `--output` flag is set) or `stdout`.
147147

148+
By default, this does not include internal topics such as `__consumer_offsets`.
149+
If you would like to have these topics included,
150+
pass the `--allow-internal-topics` flag.
151+
148152
#### check
149153

150154
```

cmd/topicctl/subcmd/bootstrap.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type bootstrapCmdConfig struct {
2121
outputDir string
2222
overwrite bool
2323

24+
allowInternalTopics bool
25+
2426
shared sharedOptions
2527
}
2628

@@ -52,6 +54,11 @@ func init() {
5254
false,
5355
"Overwrite existing configs in output directory",
5456
)
57+
bootstrapCmd.Flags().BoolVar(
58+
&bootstrapConfig.allowInternalTopics,
59+
"allow-internal-topics",
60+
false,
61+
"Include topics that start with __ (typically these are internal topics)")
5562

5663
addSharedConfigOnlyFlags(bootstrapCmd, &bootstrapConfig.shared)
5764
bootstrapCmd.MarkFlagRequired("cluster-config")
@@ -92,5 +99,6 @@ func bootstrapRun(cmd *cobra.Command, args []string) error {
9299
bootstrapConfig.excludeRegexp,
93100
bootstrapConfig.outputDir,
94101
bootstrapConfig.overwrite,
102+
bootstrapConfig.allowInternalTopics,
95103
)
96104
}

pkg/cli/cli.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func (c *CLIRunner) BootstrapTopics(
208208
excludeRegexpStr string,
209209
outputDir string,
210210
overwrite bool,
211+
allowInternalTopics bool,
211212
) error {
212213
topicInfoObjs, err := c.adminClient.GetTopics(ctx, topics, false)
213214
if err != nil {
@@ -226,7 +227,7 @@ func (c *CLIRunner) BootstrapTopics(
226227
topicConfigs := []config.TopicConfig{}
227228

228229
for _, topicInfo := range topicInfoObjs {
229-
if strings.HasPrefix(topicInfo.Name, "__") {
230+
if !allowInternalTopics && strings.HasPrefix(topicInfo.Name, "__") {
230231
// Never include underscore topics
231232
continue
232233
} else if !matchRegexp.MatchString(topicInfo.Name) {

0 commit comments

Comments
 (0)