Skip to content

Commit

Permalink
topic: fix set-config
Browse files Browse the repository at this point in the history
  • Loading branch information
birdayz committed Jul 18, 2022
1 parent 556273f commit 5d19a7a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/kaf/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var topicsCmd = &cobra.Command{

var topicSetConfig = &cobra.Command{
Use: "set-config",
Short: "set topic config",
Short: "set topic config. requires Kafka >=2.3.0 on broker side and kaf cluster config.",
Example: "kaf topic set-config topic.name \"cleanup.policy=delete\"",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -64,7 +64,7 @@ var topicSetConfig = &cobra.Command{
topic := args[0]

splt := strings.Split(args[1], ",")
configs := make(map[string]*string)
configs := make(map[string]sarama.IncrementalAlterConfigsEntry)

for _, kv := range splt {
s := strings.Split(kv, "=")
Expand All @@ -75,14 +75,17 @@ var topicSetConfig = &cobra.Command{

key := s[0]
value := s[1]
configs[key] = &value
configs[key] = sarama.IncrementalAlterConfigsEntry{
Operation: sarama.IncrementalAlterConfigsOperationSet,
Value: &value,
}
}

if len(configs) < 1 {
errorExit("No valid configs found")
}

err := admin.AlterConfig(sarama.TopicResource, topic, configs, false)
err := admin.IncrementalAlterConfig(sarama.TopicResource, topic, configs, false)
if err != nil {
errorExit("Unable to alter topic config: %v\n", err)
}
Expand Down

0 comments on commit 5d19a7a

Please sign in to comment.