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 creation of multiple KafkaTopics #750

Merged
merged 5 commits into from
Jan 25, 2022
Merged
Changes from 4 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
21 changes: 8 additions & 13 deletions pkg/webhook/topic_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
admissionv1beta1 "k8s.io/api/admission/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -154,16 +153,9 @@ func (s *webhookServer) checkExistingKafkaTopicCRs(ctx context.Context,
clusterNamespace string, topic *banzaicloudv1alpha1.KafkaTopic) *admissionv1beta1.AdmissionResponse {
// check KafkaTopic in the referred KafkaCluster's namespace
kafkaTopicList := banzaicloudv1alpha1.KafkaTopicList{}
err := s.client.List(ctx, &kafkaTopicList,
client.MatchingFieldsSelector{
Selector: fields.OneTermEqualSelector("spec.name", topic.Spec.Name),
},
client.MatchingFieldsSelector{
Selector: fields.OneTermEqualSelector("spec.clusterRef.name", topic.Spec.ClusterRef.Name),
},
)
err := s.client.List(ctx, &kafkaTopicList, client.MatchingFields{"spec.name": topic.Spec.Name})
bartam1 marked this conversation as resolved.
Show resolved Hide resolved
stoader marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Info("failed to list KafkaTopics")
log.Error(err, "couldn't list KafkaTopic custom resources")
return notAllowed("API failure while retrieving KafkaTopic list, please try again", metav1.StatusReasonServiceUnavailable)
}

Expand All @@ -175,9 +167,12 @@ func (s *webhookServer) checkExistingKafkaTopicCRs(ctx context.Context,
}

referredNamespace := kafkaTopic.Spec.ClusterRef.Namespace
if (kafkaTopic.GetNamespace() == clusterNamespace && referredNamespace == "") || referredNamespace == clusterNamespace {
foundKafkaTopic = &kafkaTopicList.Items[i]
break
referredName := kafkaTopic.Spec.ClusterRef.Name
if referredName == topic.Spec.ClusterRef.Name {
stoader marked this conversation as resolved.
Show resolved Hide resolved
stoader marked this conversation as resolved.
Show resolved Hide resolved
if (kafkaTopic.GetNamespace() == clusterNamespace && referredNamespace == "") || referredNamespace == clusterNamespace {
foundKafkaTopic = &kafkaTopicList.Items[i]
break
}
}
}
if foundKafkaTopic != nil {
Expand Down