Skip to content

Commit

Permalink
Merge branch 'master' into luciani/allow-dashes-in-broker-rack
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlaltluc authored Jun 28, 2023
2 parents d44e702 + 83868b8 commit 16b8306
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions controllers/tests/kafkacluster_controller_externalnodeport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/banzaicloud/koperator/api/v1beta1"
)
Expand Down Expand Up @@ -91,6 +92,8 @@ var _ = Describe("KafkaClusterNodeportExternalAccess", func() {
By("deleting Kafka cluster object " + kafkaCluster.Name + " in namespace " + namespace)
err := k8sClient.Delete(ctx, kafkaCluster)
Expect(err).NotTo(HaveOccurred())
// deletes all nodeports in the test namespace, to ensure a clean sheet, as garbage collection does not work in envtest
Expect(deleteNodePorts(ctx, kafkaCluster)).Should(Succeed())
kafkaCluster = nil
})

Expand Down Expand Up @@ -370,3 +373,20 @@ var _ = Describe("KafkaClusterNodeportExternalAccess", func() {
})
})
})

func deleteNodePorts(ctx SpecContext, kafkaCluster *v1beta1.KafkaCluster) error {
var serviceList corev1.ServiceList
err := k8sClient.List(ctx, &serviceList, client.ListOption(client.InNamespace(kafkaCluster.Namespace)))
if err != nil {
return err
}
for _, service := range serviceList.Items {
if service.Spec.Type == corev1.ServiceTypeNodePort {
err = k8sClient.Delete(ctx, &service)
if err != nil {
return err
}
}
}
return nil
}

0 comments on commit 16b8306

Please sign in to comment.