diff --git a/controllers/ovndbcluster_controller.go b/controllers/ovndbcluster_controller.go index 2a226728..331538ff 100644 --- a/controllers/ovndbcluster_controller.go +++ b/controllers/ovndbcluster_controller.go @@ -25,6 +25,7 @@ import ( "github.com/go-logr/logr" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -589,12 +590,25 @@ func (r *OVNDBClusterReconciler) reconcileServices( if err != nil { return ctrl.Result{}, err } + // Delete DNS thingy + dnsRecord := &infranetworkv1.DNSData{} + dnsName := "dns-" + serviceName + fmt.Sprintf("-%d", i) + dnsNamespace := helper.GetBeforeObject().GetNamespace() + Log.Info(fmt.Sprintf("Name: %v, Namespace: %v", dnsName, dnsNamespace)) + test_err := helper.GetClient().Get(ctx, types.NamespacedName{Name: dnsName, Namespace: dnsNamespace}, dnsRecord) + if test_err != nil { + Log.Info(fmt.Sprintf("Error: %v", test_err)) + } + err := helper.GetClient().Delete(ctx, dnsRecord) + if err != nil { + Log.Info(fmt.Sprintf("Error: %v", err)) + } + } } Log.Info("DNS Starts here") - Log.Info(fmt.Sprintf("AAA - Using instance: %v", instance)) - Log.Info(fmt.Sprintf("AAA - Using instance.spec: %v", instance.Spec)) + serviceName = ovndbcluster.ServiceNameSB if instance.Spec.DBType == v1beta1.NBDBType { serviceName = ovndbcluster.ServiceNameNB @@ -606,7 +620,14 @@ func (r *OVNDBClusterReconciler) reconcileServices( if err != nil { return ctrl.Result{}, err } - for _, ovnPod := range podList.Items { + if len(podList.Items) > int(*(instance.Spec.Replicas)) { + + } + for i, ovnPod := range podList.Items { + if i >= int(*(instance.Spec.Replicas)) { + Log.Info(fmt.Sprintf("In iteration %v is OOO, exit", i)) + break + } Log.Info(fmt.Sprintf("Using Pod: %v", ovnPod.Name)) var dnsName string var dnsIP string @@ -619,6 +640,9 @@ func (r *OVNDBClusterReconciler) reconcileServices( ovnPod.Name, ovnPod.Namespace, ) + if err != nil { + return ctrl.Result{}, err + } hostname := svc.ObjectMeta.Annotations[infranetworkv1.AnnotationHostnameKey] hostnames = append(hostnames, hostname) diff --git a/tests/functional/base_test.go b/tests/functional/base_test.go index 7b7b52c2..3a28763e 100644 --- a/tests/functional/base_test.go +++ b/tests/functional/base_test.go @@ -22,6 +22,7 @@ import ( "time" "github.com/google/uuid" + "github.com/onsi/gomega" . "github.com/onsi/gomega" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -29,6 +30,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" + infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" @@ -258,3 +260,13 @@ func SimulateDaemonsetNumberReadyWithPods(name types.NamespacedName, networkIPs logger.Info("Simulated daemonset success", "on", name) } + +// DNSData +func GetDNSData(name types.NamespacedName) *infranetworkv1.DNSData { + dns := &infranetworkv1.DNSData{} + gomega.Eventually(func(g gomega.Gomega) { + g.Expect(k8sClient.Get(ctx, name, dns)).Should(gomega.Succeed()) + }).Should(gomega.Succeed()) + + return dns +} diff --git a/tests/functional/ovncontroller_controller_test.go b/tests/functional/ovncontroller_controller_test.go index 4b73a7d4..02046805 100644 --- a/tests/functional/ovncontroller_controller_test.go +++ b/tests/functional/ovncontroller_controller_test.go @@ -369,6 +369,7 @@ var _ = Describe("OVNController controller", func() { daemonSetName, map[string][]string{namespace + "/internalapi": {"10.0.0.1"}}, ) + ExpectedExternalSBEndpoint := "tcp:ovsdbserver-sb." + namespace + ".svc:6642" externalSBEndpoint := "10.0.0.254" SetExternalEndpoint(dbs[1], externalSBEndpoint) @@ -377,7 +378,7 @@ var _ = Describe("OVNController controller", func() { }, timeout, interval).ShouldNot(BeNil()) Expect(th.GetConfigMap(externalCM).Data["ovsdb-config"]).Should( - ContainSubstring("ovn-remote: %s", externalSBEndpoint)) + ContainSubstring("ovn-remote: %s", ExpectedExternalSBEndpoint)) Expect(th.GetConfigMap(externalCM).Data["ovsdb-config"]).Should( ContainSubstring("ovn-encap-type: %s", "geneve")) }) @@ -460,6 +461,7 @@ var _ = Describe("OVNController controller", func() { map[string][]string{namespace + "/internalapi": {"10.0.0.1"}}, ) externalSBEndpoint := "10.0.0.254" + ExpectedExternalSBEndpoint := "tcp:ovsdbserver-sb." + namespace + ".svc:6642" SetExternalEndpoint(dbs[1], externalSBEndpoint) Eventually(func() corev1.ConfigMap { @@ -467,14 +469,14 @@ var _ = Describe("OVNController controller", func() { }, timeout, interval).ShouldNot(BeNil()) Expect(th.GetConfigMap(externalCM).Data["ovsdb-config"]).Should( - ContainSubstring("ovn-remote: %s", externalSBEndpoint)) + ContainSubstring("ovn-remote: %s", ExpectedExternalSBEndpoint)) newExternalSBEndpoint := "10.0.0.250" SetExternalEndpoint(dbs[1], newExternalSBEndpoint) Eventually(func(g Gomega) { g.Expect(th.GetConfigMap(externalCM).Data["ovsdb-config"]).Should( - ContainSubstring("ovn-remote: %s", newExternalSBEndpoint)) + ContainSubstring("ovn-remote: %s", ExpectedExternalSBEndpoint)) }, timeout, interval).Should(Succeed()) }) }) diff --git a/tests/functional/ovndbcluster_controller_test.go b/tests/functional/ovndbcluster_controller_test.go index d7e3c538..6634427b 100644 --- a/tests/functional/ovndbcluster_controller_test.go +++ b/tests/functional/ovndbcluster_controller_test.go @@ -24,6 +24,7 @@ import ( networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" . "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers" "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" @@ -73,6 +74,19 @@ var _ = Describe("OVNDBCluster controller", func() { Entry("config-data CM", "config-data"), Entry("scripts CM", "scripts"), ) + DescribeTable("should not create the dnsdata CR", + func(DnsName string) { + Eventually(func() *infranetworkv1.DNSData { + dnsm := types.NamespacedName{ + Namespace: OVNDBClusterName.Namespace, + Name: fmt.Sprintf("dns-%s", OVNDBClusterName.Name), + } + return GetDNSData(dnsm) + }, timeout, interval).Should(BeNil()) + }, + Entry("config-data CM", "config-data"), + Entry("scripts CM", "scripts"), + ) DescribeTable("should eventually create the config maps", func(cmName string) { Eventually(func() corev1.ConfigMap {