Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add retries to alter user scram creds #2632

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ func (ca *clusterAdmin) refreshController() (*Broker, error) {
return ca.client.RefreshController()
}

// isErrNoController returns `true` if the given error type unwraps to an
// isErrNotController returns `true` if the given error type unwraps to an
// `ErrNotController` response from Kafka
func isErrNoController(err error) bool {
func isErrNotController(err error) bool {
return errors.Is(err, ErrNotController)
}

Expand Down Expand Up @@ -249,7 +249,7 @@ func (ca *clusterAdmin) CreateTopic(topic string, detail *TopicDetail, validateO
request.Version = 1
}

return ca.retryOnError(isErrNoController, func() error {
return ca.retryOnError(isErrNotController, func() error {
b, err := ca.Controller()
if err != nil {
return err
Expand Down Expand Up @@ -278,14 +278,14 @@ func (ca *clusterAdmin) CreateTopic(topic string, detail *TopicDetail, validateO

func (ca *clusterAdmin) DescribeTopics(topics []string) (metadata []*TopicMetadata, err error) {
var response *MetadataResponse
err = ca.retryOnError(isErrNoController, func() error {
err = ca.retryOnError(isErrNotController, func() error {
controller, err := ca.Controller()
if err != nil {
return err
}
request := NewMetadataRequest(ca.conf.Version, topics)
response, err = controller.GetMetadata(request)
if isErrNoController(err) {
if isErrNotController(err) {
_, _ = ca.refreshController()
}
return err
Expand All @@ -298,15 +298,15 @@ func (ca *clusterAdmin) DescribeTopics(topics []string) (metadata []*TopicMetada

func (ca *clusterAdmin) DescribeCluster() (brokers []*Broker, controllerID int32, err error) {
var response *MetadataResponse
err = ca.retryOnError(isErrNoController, func() error {
err = ca.retryOnError(isErrNotController, func() error {
controller, err := ca.Controller()
if err != nil {
return err
}

request := NewMetadataRequest(ca.conf.Version, nil)
response, err = controller.GetMetadata(request)
if isErrNoController(err) {
if isErrNotController(err) {
_, _ = ca.refreshController()
}
return err
Expand Down Expand Up @@ -438,7 +438,7 @@ func (ca *clusterAdmin) DeleteTopic(topic string) error {
request.Version = 1
}

return ca.retryOnError(isErrNoController, func() error {
return ca.retryOnError(isErrNotController, func() error {
b, err := ca.Controller()
if err != nil {
return err
Expand Down Expand Up @@ -482,7 +482,7 @@ func (ca *clusterAdmin) CreatePartitions(topic string, count int32, assignment [
request.Version = 1
}

return ca.retryOnError(isErrNoController, func() error {
return ca.retryOnError(isErrNotController, func() error {
b, err := ca.Controller()
if err != nil {
return err
Expand Down Expand Up @@ -523,7 +523,7 @@ func (ca *clusterAdmin) AlterPartitionReassignments(topic string, assignment [][
request.AddBlock(topic, int32(i), assignment[i])
}

return ca.retryOnError(isErrNoController, func() error {
return ca.retryOnError(isErrNotController, func() error {
b, err := ca.Controller()
if err != nil {
return err
Expand Down Expand Up @@ -570,15 +570,15 @@ func (ca *clusterAdmin) ListPartitionReassignments(topic string, partitions []in
request.AddBlock(topic, partitions)

var rsp *ListPartitionReassignmentsResponse
err = ca.retryOnError(isErrNoController, func() error {
err = ca.retryOnError(isErrNotController, func() error {
b, err := ca.Controller()
if err != nil {
return err
}
_ = b.Open(ca.client.Config())

rsp, err = b.ListPartitionReassignments(request)
if isErrNoController(err) {
if isErrNotController(err) {
_, _ = ca.refreshController()
}
return err
Expand Down Expand Up @@ -1203,12 +1203,16 @@ func (ca *clusterAdmin) AlterUserScramCredentials(u []AlterUserScramCredentialsU
Upsertions: u,
}

b, err := ca.Controller()
if err != nil {
return nil, err
}
var rsp *AlterUserScramCredentialsResponse
err := ca.retryOnError(isErrNotController, func() error {
b, err := ca.Controller()
if err != nil {
return err
}

rsp, err := b.AlterUserScramCredentials(req)
rsp, err = b.AlterUserScramCredentials(req)
return err
})
if err != nil {
return nil, err
}
Expand Down
Loading