Skip to content

Commit

Permalink
kadm: add NumPartitions,ReplicationFactor,Configs to CreateTopicResponse
Browse files Browse the repository at this point in the history
Closes #351.
  • Loading branch information
twmb committed Feb 25, 2023
1 parent 3322f31 commit f5ddf71
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions pkg/kadm/topics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ func (cl *Client) ListTopicsWithInternal(

// CreateTopicResponse contains the response for an individual created topic.
type CreateTopicResponse struct {
Topic string // Topic is the topic that was created.
ID TopicID // ID is the topic ID for this topic, if talking to Kafka v2.8+.
Err error // Err is any error preventing this topic from being created.
Topic string // Topic is the topic that was created.
ID TopicID // ID is the topic ID for this topic, if talking to Kafka v2.8+.
Err error // Err is any error preventing this topic from being created.
NumPartitions int32 // NumPartitions is the number of partitions in the response, if talking to Kafka v2.4+.
ReplicationFactor int16 // ReplicationFactor is how many replicas every partition has for this topic, if talking to Kafka 2.4+.
Configs map[string]Config // Configs contains the topic configuration (minus config synonyms), if talking to Kafka 2.4+.
}

// CreateTopicRepsonses contains per-topic responses for created topics.
Expand Down Expand Up @@ -205,11 +208,23 @@ func (cl *Client) createTopics(ctx context.Context, dry bool, p int32, rf int16,

rs := make(CreateTopicResponses)
for _, t := range resp.Topics {
rs[t.Topic] = CreateTopicResponse{
Topic: t.Topic,
ID: t.TopicID,
Err: kerr.ErrorForCode(t.ErrorCode),
rt := CreateTopicResponse{
Topic: t.Topic,
ID: t.TopicID,
Err: kerr.ErrorForCode(t.ErrorCode),
NumPartitions: t.NumPartitions,
ReplicationFactor: t.ReplicationFactor,
Configs: make(map[string]Config),
}
for _, c := range t.Configs {
rt.Configs[c.Name] = Config{
Key: c.Name,
Value: c.Value,
Source: kmsg.ConfigSource(c.Source),
Sensitive: c.IsSensitive,
}
}
rs[t.Topic] = rt
}
return rs, nil
}
Expand Down

0 comments on commit f5ddf71

Please sign in to comment.