Skip to content

Commit 66e0162

Browse files
dateutliDavid Teutli
andauthored
feat: add option to override placementStrategy for bootstrap command (#249)
* feat: add option to override placementStrategy for bootstrap command * chore: update README and bump version * chore: change placement-straegy-overwrite flag to placement-stragy --------- Co-authored-by: David Teutli <dapalacio@segment.com>
1 parent e814444 commit 66e0162

6 files changed

Lines changed: 24 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ 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+
The placement strategy for the bootstrapped topic configs will default to `cross-rack`
149+
unless a different one is set via the `--placement-strategy` flag.
150+
148151
By default, this does not include internal topics such as `__consumer_offsets`.
149152
If you would like to have these topics included,
150153
pass the `--allow-internal-topics` flag.

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+
placementStrategy 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.placementStrategy),
67+
"placement-strategy",
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.placementStrategy,
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 = "2.0.0"

0 commit comments

Comments
 (0)