Skip to content

Commit 69daa2d

Browse files
author
David Teutli
committed
feat: add option to override placementStrategy for bootstrap command
1 parent e814444 commit 69daa2d

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

cmd/topicctl/subcmd/bootstrap.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type bootstrapCmdConfig struct {
2121
excludeRegexp string
2222
outputDir string
2323
overwrite bool
24+
placementStrategyOverwrite config.PlacementStrategy
2425

2526
allowInternalTopics bool
2627

@@ -59,7 +60,14 @@ func init() {
5960
&bootstrapConfig.allowInternalTopics,
6061
"allow-internal-topics",
6162
false,
62-
"Include topics that start with __ (typically these are internal topics)")
63+
"Include topics that start with __ (typically these are internal topics)",
64+
)
65+
bootstrapCmd.Flags().StringVar(
66+
(*string)(&bootstrapConfig.placementStrategyOverwrite),
67+
"placement-strategy-overwrite",
68+
"cross-rack",
69+
"Provide a placementStrategy to overwrite the default value of cross-rack",
70+
)
6371

6472
addSharedConfigOnlyFlags(bootstrapCmd, &bootstrapConfig.shared)
6573
bootstrapCmd.MarkFlagRequired("cluster-config")
@@ -101,5 +109,6 @@ func bootstrapRun(cmd *cobra.Command, args []string) error {
101109
bootstrapConfig.outputDir,
102110
bootstrapConfig.overwrite,
103111
bootstrapConfig.allowInternalTopics,
112+
bootstrapConfig.placementStrategyOverwrite,
104113
)
105114
}

pkg/cli/cli.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ func (c *CLIRunner) BootstrapTopics(
210210
outputDir string,
211211
overwrite bool,
212212
allowInternalTopics bool,
213+
placementStrategyOverwrite ...config.PlacementStrategy,
213214
) error {
214215
topicInfoObjs, err := c.adminClient.GetTopics(ctx, topics, false)
215216
if err != nil {
@@ -225,6 +226,11 @@ func (c *CLIRunner) BootstrapTopics(
225226
return err
226227
}
227228

229+
placementStrategy := config.PlacementStrategyCrossRack
230+
if len(placementStrategyOverwrite) > 0 {
231+
placementStrategy = placementStrategyOverwrite[0]
232+
}
233+
228234
topicConfigs := []config.TopicConfig{}
229235

230236
for _, topicInfo := range topicInfoObjs {
@@ -240,6 +246,7 @@ func (c *CLIRunner) BootstrapTopics(
240246
topicConfig := config.TopicConfigFromTopicInfo(
241247
clusterConfig,
242248
topicInfo,
249+
placementStrategy,
243250
)
244251
topicConfigs = append(topicConfigs, topicConfig)
245252
}

pkg/config/topic.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ func (t TopicConfig) ToYAML() (string, error) {
313313
func TopicConfigFromTopicInfo(
314314
clusterConfig ClusterConfig,
315315
topicInfo admin.TopicInfo,
316+
placementStrategy PlacementStrategy,
316317
) TopicConfig {
317318
topicConfig := TopicConfig{
318319
Meta: ResourceMeta{
@@ -326,7 +327,7 @@ func TopicConfigFromTopicInfo(
326327
Partitions: len(topicInfo.Partitions),
327328
ReplicationFactor: len(topicInfo.Partitions[0].Replicas),
328329
PlacementConfig: TopicPlacementConfig{
329-
Strategy: PlacementStrategyAny,
330+
Strategy: placementStrategy,
330331
},
331332
},
332333
}

pkg/config/topic_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ func TestTopicConfigFromTopicInfo(t *testing.T) {
481481
topicConfig := TopicConfigFromTopicInfo(
482482
testCase.clusterConfig,
483483
testCase.topicInfo,
484+
"any",
484485
)
485486
assert.Equal(t, testCase.expTopicConfig, topicConfig)
486487
}

pkg/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package version
22

33
// Version is the current topicctl version.
4-
const Version = "1.23.1"
4+
const Version = "1.24.0"

0 commit comments

Comments
 (0)