From 7ac91657dc95ac200afad332bbfd306fbfd47b7f Mon Sep 17 00:00:00 2001 From: Andre Date: Fri, 1 Dec 2023 14:42:09 +0000 Subject: [PATCH] Add CRDs to functional tests --- controllers/barbican_controller.go | 9 +++ tests/functional/barbican_controller_test.go | 70 +++++++++++++++++--- tests/functional/base_test.go | 8 ++- tests/functional/suite_test.go | 55 ++++++++++++--- 4 files changed, 121 insertions(+), 21 deletions(-) diff --git a/controllers/barbican_controller.go b/controllers/barbican_controller.go index 7a7da67..1591777 100644 --- a/controllers/barbican_controller.go +++ b/controllers/barbican_controller.go @@ -172,10 +172,12 @@ func (r *BarbicanReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r ) instance.Status.Conditions.Init(&cl) + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: STATUS CONDITIONS WAS NIL")) // Register overall status immediately to have an early feedback e.g. in the cli return ctrl.Result{}, nil } + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: STATUS CONDITIONS WAS _NOT_ NIL")) if instance.Status.Hash == nil { instance.Status.Hash = map[string]string{} } @@ -186,6 +188,7 @@ func (r *BarbicanReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r } // Handle non-deleted clusters + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: RECONCILE NORMAL")) return r.reconcileNormal(ctx, instance, helper) } @@ -204,7 +207,10 @@ func (r *BarbicanReconciler) reconcileNormal(ctx context.Context, instance *barb // create RabbitMQ transportURL CR and get the actual URL from the associated secret that is created // transportURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels) + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: TRANSPORT URL")) + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: TRANSPORT URL STATUS: %s", transportURL.Status)) if err != nil { + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: TRANSPORT URL WITH ERROR")) instance.Status.Conditions.Set(condition.FalseCondition( barbicanv1beta1.BarbicanRabbitMQTransportURLReadyCondition, condition.ErrorReason, @@ -213,12 +219,14 @@ func (r *BarbicanReconciler) reconcileNormal(ctx context.Context, instance *barb err.Error())) return ctrl.Result{}, err } + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: TRANSPORT URL WORKING")) if op != controllerutil.OperationResultNone { Log.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) } instance.Status.TransportURLSecret = transportURL.Status.SecretName + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: TRANSPORT URL SECRET: %s", instance.Status.TransportURLSecret)) if instance.Status.TransportURLSecret == "" { Log.Info(fmt.Sprintf("Waiting for TransportURL %s secret to be created", transportURL.Name)) @@ -229,6 +237,7 @@ func (r *BarbicanReconciler) reconcileNormal(ctx context.Context, instance *barb barbicanv1beta1.BarbicanRabbitMQTransportURLReadyRunningMessage)) return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG: TRANSPORT URL WAS CREATED")) Log.Info(fmt.Sprintf("TransportURL secret name %s", transportURL.Status.SecretName)) instance.Status.Conditions.MarkTrue(barbicanv1beta1.BarbicanRabbitMQTransportURLReadyCondition, barbicanv1beta1.BarbicanRabbitMQTransportURLReadyMessage) diff --git a/tests/functional/barbican_controller_test.go b/tests/functional/barbican_controller_test.go index f79987e..ec57a07 100644 --- a/tests/functional/barbican_controller_test.go +++ b/tests/functional/barbican_controller_test.go @@ -6,11 +6,11 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - //. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers" - //corev1 "k8s.io/api/core/v1" + . "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" //"k8s.io/utils/ptr" - //condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" + condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" ) var _ = Describe("Barbican controller", func() { @@ -50,11 +50,65 @@ var _ = Describe("Barbican controller", func() { DeferCleanup(th.DeleteInstance, CreateBarbican(barbicanName, GetDefaultBarbicanSpec())) }) - It("should have the Spec fields defaulted", func() { - Barbican := GetBarbican(barbicanName) - Expect(Barbican.Spec.ServiceUser).Should(Equal("barbican")) - Expect(Barbican.Spec.DatabaseInstance).Should(Equal("openstack")) - Expect(Barbican.Spec.DatabaseUser).Should(Equal("barbican")) + /* + It("should have the Spec fields defaulted", func() { + Barbican := GetBarbican(barbicanName) + Expect(Barbican.Spec.ServiceUser).Should(Equal("barbican")) + Expect(Barbican.Spec.DatabaseInstance).Should(Equal("openstack")) + Expect(Barbican.Spec.DatabaseUser).Should(Equal("barbican")) + }) + + It("should have the Status fields initialized", func() { + Barbican := GetBarbican(barbicanName) + Expect(Barbican.Status.Hash).To(BeEmpty()) + Expect(Barbican.Status.BarbicanAPIReadyCount).To(Equal(int32(0))) + Expect(Barbican.Status.BarbicanWorkerReadyCount).To(Equal(int32(0))) + Expect(Barbican.Status.BarbicanKeystoneListenerReadyCount).To(Equal(int32(0))) + Expect(Barbican.Status.TransportURLSecret).To(Equal("")) + Expect(Barbican.Status.DatabaseHostname).To(Equal("")) + }) + */ + + It("should have input not ready and unknown Conditions initialized", func() { + /* + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + condition.ReadyCondition, + corev1.ConditionFalse, + ) + */ + + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + condition.InputReadyCondition, + corev1.ConditionFalse, + ) + /* + + for _, cond := range []condition.Type{ + condition.ServiceConfigReadyCondition, + condition.DBReadyCondition, + condition.DBSyncReadyCondition, + //condition.BarbicanAPIReadyCondition, + //condition.BarbicanWorkerReadyCondition, + //condition.BarbicanKeystoneListenerReadyCondition, + //condition., + //condition.ExposeServiceReadyCondition, + //condition.BootstrapReadyCondition, + //condition.DeploymentReadyCondition, + condition.NetworkAttachmentsReadyCondition, + //condition.CronJobReadyCondition, + } { + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + cond, + corev1.ConditionUnknown, + ) + } + */ }) }) }) diff --git a/tests/functional/base_test.go b/tests/functional/base_test.go index 36ebc9b..d89c39b 100644 --- a/tests/functional/base_test.go +++ b/tests/functional/base_test.go @@ -25,7 +25,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" barbicanv1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1" - //condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" + condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" ) func GetDefaultBarbicanSpec() map[string]interface{} { @@ -68,12 +68,14 @@ func CreateKeystoneAPISecret(namespace string, name string) *corev1.Secret { }, ) } +*/ -func KeystoneConditionGetter(name types.NamespacedName) condition.Conditions { - instance := GetKeystoneAPI(name) +func BarbicanConditionGetter(name types.NamespacedName) condition.Conditions { + instance := GetBarbican(name) return instance.Status.Conditions } +/* func GetCronJob(name types.NamespacedName) *batchv1.CronJob { instance := &batchv1.CronJob{} Eventually(func(g Gomega) { diff --git a/tests/functional/suite_test.go b/tests/functional/suite_test.go index fb28600..bb74303 100644 --- a/tests/functional/suite_test.go +++ b/tests/functional/suite_test.go @@ -24,11 +24,16 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/log/zap" - //memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1" + memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1" //keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1" + networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1" barbicanv1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1" + rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1" + keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1" test "github.com/openstack-k8s-operators/lib-common/modules/test" mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1" + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" infra_test "github.com/openstack-k8s-operators/infra-operator/apis/test/helpers" //keystone_test "github.com/openstack-k8s-operators/keystone-operator/api/test/helpers" @@ -57,7 +62,7 @@ var ( ) const ( - timeout = time.Second * 2 + timeout = time.Second * 5 SecretName = "test-osp-secret" @@ -78,20 +83,42 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) + keystoneCRDs, err := test.GetCRDDirFromModule( + "github.com/openstack-k8s-operators/keystone-operator/api", "../../go.mod", "bases") + Expect(err).ShouldNot(HaveOccurred()) + networkv1CRD, err := test.GetCRDDirFromModule( + "github.com/k8snetworkplumbingwg/network-attachment-definition-client", "../../go.mod", "artifacts/networks-crd.yaml") + Expect(err).ShouldNot(HaveOccurred()) + + //rabbitmqv2CRDs, err := test.GetCRDDirFromModule( + // "github.com/rabbitmq/cluster-operator/v2", "../../go.mod", "config/crd/bases") + //Expect(err).ShouldNot(HaveOccurred()) + rabbitmqCRDs, err := test.GetCRDDirFromModule( + "github.com/openstack-k8s-operators/infra-operator/apis", "../../go.mod", "bases") + Expect(err).ShouldNot(HaveOccurred()) + mariaDBCRDs, err := test.GetCRDDirFromModule( "github.com/openstack-k8s-operators/mariadb-operator/api", "../../go.mod", "bases") Expect(err).ShouldNot(HaveOccurred()) - //memcachedCRDs, err := test.GetCRDDirFromModule( - // "github.com/openstack-k8s-operators/infra-operator/apis", "../../go.mod", "bases") - //Expect(err).ShouldNot(HaveOccurred()) + memcachedCRDs, err := test.GetCRDDirFromModule( + "github.com/openstack-k8s-operators/infra-operator/apis", "../../go.mod", "bases") + Expect(err).ShouldNot(HaveOccurred()) By("bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{ filepath.Join("..", "..", "config", "crd", "bases"), + keystoneCRDs, + rabbitmqCRDs, mariaDBCRDs, - //memcachedCRDs, + memcachedCRDs, + }, + CRDInstallOptions: envtest.CRDInstallOptions{ + Paths: []string{ + networkv1CRD, + }, }, + ErrorIfCRDPathMissing: true, WebhookInstallOptions: envtest.WebhookInstallOptions{ Paths: []string{filepath.Join("..", "..", "config", "webhook")}, @@ -107,14 +134,22 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) Expect(cfg).NotTo(BeNil()) - //err = keystonev1.AddToScheme(scheme.Scheme) - //Expect(err).NotTo(HaveOccurred()) err = barbicanv1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) + err = keystonev1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) err = mariadbv1.AddToScheme(scheme.Scheme) Expect(err).NotTo(HaveOccurred()) - //err = memcachedv1.AddToScheme(scheme.Scheme) - //Expect(err).NotTo(HaveOccurred()) + err = memcachedv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + err = rabbitmqv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + err = networkv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + err = corev1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + err = appsv1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) //+kubebuilder:scaffold:scheme