From 9f8dc75f3527dc2996ca8e73886143dff3acf81b Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 8 Feb 2024 22:17:24 +0000 Subject: [PATCH 1/2] tests: confirm that ovn ready status is removed on ovn disabled This is to confirm that we can deploy CP without ovn enabled and get it to Ready. --- tests/functional/base_test.go | 5 +++ .../openstackoperator_controller_test.go | 31 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/tests/functional/base_test.go b/tests/functional/base_test.go index e41cec9c7..e1f3ae09d 100644 --- a/tests/functional/base_test.go +++ b/tests/functional/base_test.go @@ -269,3 +269,8 @@ func GetOpenStackControlPlane(name types.NamespacedName) *corev1.OpenStackContro }, timeout, interval).Should(Succeed()) return instance } + +func OpenStackControlPlaneConditionGetter(name types.NamespacedName) condition.Conditions { + instance := GetOpenStackControlPlane(name) + return instance.Status.Conditions +} diff --git a/tests/functional/openstackoperator_controller_test.go b/tests/functional/openstackoperator_controller_test.go index 437eff249..bf4000d24 100644 --- a/tests/functional/openstackoperator_controller_test.go +++ b/tests/functional/openstackoperator_controller_test.go @@ -22,7 +22,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" + k8s_corev1 "k8s.io/api/core/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/types" @@ -33,6 +33,7 @@ import ( . "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers" "github.com/openstack-k8s-operators/lib-common/modules/common/tls" clientv1 "github.com/openstack-k8s-operators/openstack-operator/apis/client/v1beta1" + corev1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1" ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1" ) @@ -162,10 +163,10 @@ var _ = Describe("OpenStackOperator controller", func() { names.OpenStackClientName, ConditionGetterFunc(OpenStackClientConditionGetter), clientv1.OpenStackClientReadyCondition, - corev1.ConditionTrue, + k8s_corev1.ConditionTrue, ) - pod := &corev1.Pod{} + pod := &k8s_corev1.Pod{} err := th.K8sClient.Get(ctx, names.OpenStackClientName, pod) g.Expect(pod).Should(Not(BeNil())) g.Expect(err).ToNot(HaveOccurred()) @@ -201,6 +202,8 @@ var _ = Describe("OpenStackOperator controller", func() { }, }, } + // TODO: had to disable tls to allow control plane status to update + spec["tls"] = map[string]interface{}{} DeferCleanup( th.DeleteInstance, CreateOpenStackControlPlane(names.OpenStackControlplaneName, spec), @@ -231,6 +234,22 @@ var _ = Describe("OpenStackOperator controller", func() { ovnDbServerSB := ovn.GetOVNDBCluster(names.OVNDbServerSBName) g.Expect(ovnDbServerSB).Should(Not(BeNil())) }, timeout, interval).Should(Succeed()) + + // set ready states for each ovn component + ovn.SimulateOVNNorthdReady(names.OVNNorthdName) + ovn.SimulateOVNDBClusterReady(names.OVNDbServerNBName) + ovn.SimulateOVNDBClusterReady(names.OVNDbServerSBName) + ovn.SimulateOVNControllerReady(names.OVNControllerName) + + // expect the ready status to propagate to control plane object + Eventually(func(g Gomega) { + th.ExpectCondition( + names.OpenStackControlplaneName, + ConditionGetterFunc(OpenStackControlPlaneConditionGetter), + corev1.OpenStackControlPlaneOVNReadyCondition, + k8s_corev1.ConditionTrue, + ) + }, timeout, interval).Should(Succeed()) }) It("should remove OVN resources on disable", func() { @@ -265,6 +284,12 @@ var _ = Describe("OpenStackOperator controller", func() { instance := &ovnv1.OVNController{} g.Expect(th.K8sClient.Get(th.Ctx, names.OVNControllerName, instance)).Should(Not(Succeed())) }, timeout, interval).Should(Succeed()) + + // expect the ovn ready condition removed to not affect deployment success + Eventually(func(g Gomega) { + conditions := OpenStackControlPlaneConditionGetter(names.OpenStackControlplaneName) + g.Expect(conditions.Has(corev1.OpenStackControlPlaneOVNReadyCondition)).To(BeFalse()) + }, timeout, interval).Should(Succeed()) }) }) }) From c13dcf8535fb947f0409b2c46d999520e3d5107f Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Thu, 8 Feb 2024 22:19:23 +0000 Subject: [PATCH 2/2] ovn: remove redundant removes for ready status when disabled It is removed in the main reconcile entrypoint, so there is no need to remove it inside per-CRD reconcile functions. --- pkg/openstack/ovn.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkg/openstack/ovn.go b/pkg/openstack/ovn.go index 5d060fe12..ac07abb19 100644 --- a/pkg/openstack/ovn.go +++ b/pkg/openstack/ovn.go @@ -73,7 +73,6 @@ func ReconcileOVNDbClusters(ctx context.Context, instance *corev1beta1.OpenStack if _, err := EnsureDeleted(ctx, helper, OVNDBCluster); err != nil { return false, err } - instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneOVNReadyCondition) continue } @@ -121,7 +120,6 @@ func ReconcileOVNNorthd(ctx context.Context, instance *corev1beta1.OpenStackCont if _, err := EnsureDeleted(ctx, helper, OVNNorthd); err != nil { return false, err } - instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneOVNReadyCondition) return false, nil } @@ -170,7 +168,6 @@ func ReconcileOVNController(ctx context.Context, instance *corev1beta1.OpenStack if _, err := EnsureDeleted(ctx, helper, OVNController); err != nil { return false, err } - instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneOVNReadyCondition) return false, nil }