Skip to content

Commit 9c1f75c

Browse files
dateutliDavid Teutli
andauthored
fix: take into account all existing files in given path when bootstraping (#256)
* fix: take into account all existing files in the given path * fix: reverse logic of existingConfigFiles to bootstrappedFiles * fix: store full file path * fix: bump version for release --------- Co-authored-by: David Teutli <dapalacio@segment.com>
1 parent 19b38ca commit 9c1f75c

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

cmd/topicctl/subcmd/rebalance.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,13 @@ func rebalanceRun(cmd *cobra.Command, args []string) error {
158158
return err
159159
}
160160

161-
existingConfigFiles := make(map[string]struct{})
161+
bootstrappedFiles := make(map[string]struct{})
162162
if rebalanceConfig.bootstrapMissingConfigs {
163-
// make set of existing files
164-
err := processTopicFiles(topicFiles, func(topicConfig config.TopicConfig, topicFile string) error {
163+
// make set of existing files before bootstrapping
164+
existingConfigFiles := make(map[string]struct{})
165+
for _, topicFile := range topicFiles {
165166
_, topicFilename := filepath.Split(topicFile)
166167
existingConfigFiles[topicFilename] = struct{}{}
167-
return nil
168-
})
169-
if err != nil {
170-
return err
171168
}
172169

173170
// bootstrap missing config files
@@ -188,6 +185,14 @@ func rebalanceRun(cmd *cobra.Command, args []string) error {
188185
if err != nil {
189186
return err
190187
}
188+
189+
// make list of bootstrappedFiles
190+
for _, topicFile := range topicFiles {
191+
_, topicFilename := filepath.Split(topicFile)
192+
if _, found := existingConfigFiles[topicFilename]; !found {
193+
bootstrappedFiles[topicFile] = struct{}{}
194+
}
195+
}
191196
}
192197

193198
// iterate through each topic config and initiate rebalance
@@ -264,16 +269,10 @@ func rebalanceRun(cmd *cobra.Command, args []string) error {
264269
}
265270

266271
// clean up any bootstrapped topic configs
267-
if rebalanceConfig.bootstrapMissingConfigs {
268-
for _, topicFile := range topicFiles {
269-
_, topicFilename := filepath.Split(topicFile)
270-
if _, found := existingConfigFiles[topicFilename]; found {
271-
continue
272-
}
273-
err := os.Remove(topicFile)
274-
if err != nil {
275-
log.Errorf("error deleting temporary file %s: %v", topicFile, err)
276-
}
272+
for topicFile := range bootstrappedFiles {
273+
err := os.Remove(topicFile)
274+
if err != nil {
275+
log.Errorf("error deleting temporary file %s: %v", topicFile, err)
277276
}
278277
}
279278

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 = "2.0.1"
4+
const Version = "2.0.2"

0 commit comments

Comments
 (0)