diff --git a/README.md b/README.md index 0dcd7731..8f5d651b 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,9 @@ 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`. +The placement strategy for the bootstrapped topic configs will default to `cross-rack` +unless a different one is set via the `--placement-strategy` flag. + 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. diff --git a/cmd/topicctl/subcmd/bootstrap.go b/cmd/topicctl/subcmd/bootstrap.go index 8b090bdd..e7d4ed3a 100644 --- a/cmd/topicctl/subcmd/bootstrap.go +++ b/cmd/topicctl/subcmd/bootstrap.go @@ -21,6 +21,7 @@ type bootstrapCmdConfig struct { excludeRegexp string outputDir string overwrite bool + placementStrategy config.PlacementStrategy allowInternalTopics bool @@ -59,7 +60,14 @@ func init() { &bootstrapConfig.allowInternalTopics, "allow-internal-topics", false, - "Include topics that start with __ (typically these are internal topics)") + "Include topics that start with __ (typically these are internal topics)", + ) + bootstrapCmd.Flags().StringVar( + (*string)(&bootstrapConfig.placementStrategy), + "placement-strategy", + "cross-rack", + "Provide a placementStrategy to overwrite the default value of cross-rack", + ) addSharedConfigOnlyFlags(bootstrapCmd, &bootstrapConfig.shared) bootstrapCmd.MarkFlagRequired("cluster-config") @@ -101,5 +109,6 @@ func bootstrapRun(cmd *cobra.Command, args []string) error { bootstrapConfig.outputDir, bootstrapConfig.overwrite, bootstrapConfig.allowInternalTopics, + bootstrapConfig.placementStrategy, ) } diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index a60a1208..2af77d8e 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -210,6 +210,7 @@ func (c *CLIRunner) BootstrapTopics( outputDir string, overwrite bool, allowInternalTopics bool, + placementStrategyOverwrite ...config.PlacementStrategy, ) error { topicInfoObjs, err := c.adminClient.GetTopics(ctx, topics, false) if err != nil { @@ -225,6 +226,11 @@ func (c *CLIRunner) BootstrapTopics( return err } + placementStrategy := config.PlacementStrategyCrossRack + if len(placementStrategyOverwrite) > 0 { + placementStrategy = placementStrategyOverwrite[0] + } + topicConfigs := []config.TopicConfig{} for _, topicInfo := range topicInfoObjs { @@ -240,6 +246,7 @@ func (c *CLIRunner) BootstrapTopics( topicConfig := config.TopicConfigFromTopicInfo( clusterConfig, topicInfo, + placementStrategy, ) topicConfigs = append(topicConfigs, topicConfig) } diff --git a/pkg/config/topic.go b/pkg/config/topic.go index 370b877e..2fdf955d 100644 --- a/pkg/config/topic.go +++ b/pkg/config/topic.go @@ -313,6 +313,7 @@ func (t TopicConfig) ToYAML() (string, error) { func TopicConfigFromTopicInfo( clusterConfig ClusterConfig, topicInfo admin.TopicInfo, + placementStrategy PlacementStrategy, ) TopicConfig { topicConfig := TopicConfig{ Meta: ResourceMeta{ @@ -326,7 +327,7 @@ func TopicConfigFromTopicInfo( Partitions: len(topicInfo.Partitions), ReplicationFactor: len(topicInfo.Partitions[0].Replicas), PlacementConfig: TopicPlacementConfig{ - Strategy: PlacementStrategyAny, + Strategy: placementStrategy, }, }, } diff --git a/pkg/config/topic_test.go b/pkg/config/topic_test.go index 764010d8..f4135ab2 100644 --- a/pkg/config/topic_test.go +++ b/pkg/config/topic_test.go @@ -481,6 +481,7 @@ func TestTopicConfigFromTopicInfo(t *testing.T) { topicConfig := TopicConfigFromTopicInfo( testCase.clusterConfig, testCase.topicInfo, + "any", ) assert.Equal(t, testCase.expTopicConfig, topicConfig) } diff --git a/pkg/version/version.go b/pkg/version/version.go index f2857ccb..8d061ec6 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,4 +1,4 @@ package version // Version is the current topicctl version. -const Version = "1.23.1" +const Version = "2.0.0"