Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion cmd/topicctl/subcmd/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type bootstrapCmdConfig struct {
excludeRegexp string
outputDir string
overwrite bool
placementStrategy config.PlacementStrategy

allowInternalTopics bool

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -101,5 +109,6 @@ func bootstrapRun(cmd *cobra.Command, args []string) error {
bootstrapConfig.outputDir,
bootstrapConfig.overwrite,
bootstrapConfig.allowInternalTopics,
bootstrapConfig.placementStrategy,
)
}
7 changes: 7 additions & 0 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -240,6 +246,7 @@ func (c *CLIRunner) BootstrapTopics(
topicConfig := config.TopicConfigFromTopicInfo(
clusterConfig,
topicInfo,
placementStrategy,
)
topicConfigs = append(topicConfigs, topicConfig)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func (t TopicConfig) ToYAML() (string, error) {
func TopicConfigFromTopicInfo(
clusterConfig ClusterConfig,
topicInfo admin.TopicInfo,
placementStrategy PlacementStrategy,
) TopicConfig {
topicConfig := TopicConfig{
Meta: ResourceMeta{
Expand All @@ -326,7 +327,7 @@ func TopicConfigFromTopicInfo(
Partitions: len(topicInfo.Partitions),
ReplicationFactor: len(topicInfo.Partitions[0].Replicas),
PlacementConfig: TopicPlacementConfig{
Strategy: PlacementStrategyAny,
Strategy: placementStrategy,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/config/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ func TestTopicConfigFromTopicInfo(t *testing.T) {
topicConfig := TopicConfigFromTopicInfo(
testCase.clusterConfig,
testCase.topicInfo,
"any",
)
assert.Equal(t, testCase.expTopicConfig, topicConfig)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package version

// Version is the current topicctl version.
const Version = "1.23.1"
const Version = "2.0.0"