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

add ability to include internal topics in bootstrap #192

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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,
)
}
12 changes: 2 additions & 10 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,7 @@ func (c *CLIRunner) DeleteACL(

// BootstrapTopics creates configs for one or more topics based on their current state in the
// cluster.
func (c *CLIRunner) BootstrapTopics(
ctx context.Context,
topics []string,
clusterConfig config.ClusterConfig,
matchRegexpStr string,
excludeRegexpStr string,
outputDir string,
overwrite bool,
) error {
func (c *CLIRunner) BootstrapTopics(ctx context.Context, topics []string, clusterConfig config.ClusterConfig, matchRegexpStr string, excludeRegexpStr string, outputDir string, overwrite bool, allowUnderscoreTopics bool) error {
dtjm marked this conversation as resolved.
Show resolved Hide resolved
topicInfoObjs, err := c.adminClient.GetTopics(ctx, topics, false)
if err != nil {
return err
Expand All @@ -226,7 +218,7 @@ func (c *CLIRunner) BootstrapTopics(
topicConfigs := []config.TopicConfig{}

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