diff --git a/cmd/topicctl/subcmd/rebalance.go b/cmd/topicctl/subcmd/rebalance.go index c704d57..296c03a 100644 --- a/cmd/topicctl/subcmd/rebalance.go +++ b/cmd/topicctl/subcmd/rebalance.go @@ -158,16 +158,13 @@ func rebalanceRun(cmd *cobra.Command, args []string) error { return err } - existingConfigFiles := make(map[string]struct{}) + bootstrappedFiles := make(map[string]struct{}) if rebalanceConfig.bootstrapMissingConfigs { - // make set of existing files - err := processTopicFiles(topicFiles, func(topicConfig config.TopicConfig, topicFile string) error { + // make set of existing files before bootstrapping + existingConfigFiles := make(map[string]struct{}) + for _, topicFile := range topicFiles { _, topicFilename := filepath.Split(topicFile) existingConfigFiles[topicFilename] = struct{}{} - return nil - }) - if err != nil { - return err } // bootstrap missing config files @@ -188,6 +185,14 @@ func rebalanceRun(cmd *cobra.Command, args []string) error { if err != nil { return err } + + // make list of bootstrappedFiles + for _, topicFile := range topicFiles { + _, topicFilename := filepath.Split(topicFile) + if _, found := existingConfigFiles[topicFilename]; !found { + bootstrappedFiles[topicFile] = struct{}{} + } + } } // iterate through each topic config and initiate rebalance @@ -264,16 +269,10 @@ func rebalanceRun(cmd *cobra.Command, args []string) error { } // clean up any bootstrapped topic configs - if rebalanceConfig.bootstrapMissingConfigs { - for _, topicFile := range topicFiles { - _, topicFilename := filepath.Split(topicFile) - if _, found := existingConfigFiles[topicFilename]; found { - continue - } - err := os.Remove(topicFile) - if err != nil { - log.Errorf("error deleting temporary file %s: %v", topicFile, err) - } + for topicFile := range bootstrappedFiles { + err := os.Remove(topicFile) + if err != nil { + log.Errorf("error deleting temporary file %s: %v", topicFile, err) } } diff --git a/pkg/version/version.go b/pkg/version/version.go index 1cc493c..69eb7fd 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 = "2.0.1" +const Version = "2.0.2"