Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit d3bb667

Browse files
committed
Fix error handling in topicmanager to avoid panic
1 parent c0d5507 commit d3bb667

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pkg/resources/cruisecontrol/topicManager.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"crypto/x509"
2121
"fmt"
2222

23+
"emperror.dev/errors"
2324
banzaicloudv1alpha1 "github.com/banzaicloud/kafka-operator/pkg/apis/banzaicloud/v1alpha1"
2425
"github.com/banzaicloud/kafka-operator/pkg/resources/kafka"
2526
"github.com/go-logr/logr"
@@ -73,7 +74,9 @@ func generateCCTopic(cluster *banzaicloudv1alpha1.KafkaCluster, client client.Cl
7374
ReplicationFactor: 3,
7475
}, false)
7576

76-
if err != nil && err.(*sarama.TopicError).Err != sarama.ErrTopicAlreadyExists {
77+
var tError *sarama.TopicError
78+
79+
if err != nil && !(errors.As(err, &tError) && tError.Err == sarama.ErrTopicAlreadyExists) {
7780
return emperror.Wrap(err, "Error while creating CC topic")
7881
}
7982

0 commit comments

Comments
 (0)