Skip to content

Commit

Permalink
Add CRDs to functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
afaranha committed Dec 1, 2023
1 parent 88a2fad commit 7ac9165
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 21 deletions.
9 changes: 9 additions & 0 deletions controllers/barbican_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand All @@ -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)
}

Expand All @@ -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,
Expand All @@ -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))
Expand All @@ -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)
Expand Down
70 changes: 62 additions & 8 deletions tests/functional/barbican_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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,
)
}
*/
})
})
})
8 changes: 5 additions & 3 deletions tests/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {
Expand Down Expand Up @@ -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) {
Expand Down
55 changes: 45 additions & 10 deletions tests/functional/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -57,7 +62,7 @@ var (
)

const (
timeout = time.Second * 2
timeout = time.Second * 5

SecretName = "test-osp-secret"

Expand All @@ -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")},
Expand All @@ -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

Expand Down

0 comments on commit 7ac9165

Please sign in to comment.