Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make dbaaspolicy object optional #348

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions api/v1beta1/dbaasprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const (

// DBaaS condition reasons:
Ready string = "Ready"
DBaaSPolicyNotFound string = "DBaaSPolicyNotFound"
DBaaSPolicyNotReady string = "DBaaSPolicyNotReady"
DBaaSProviderNotFound string = "DBaaSProviderNotFound"
DBaaSInventoryNotFound string = "DBaaSInventoryNotFound"
Expand All @@ -54,7 +53,6 @@ const (
MsgProviderCRReconcileInProgress string = "DBaaS Provider Custom Resource reconciliation in progress"
MsgInventoryNotReady string = "Inventory discovery not done"
MsgInventoryNotProvisionable string = "Inventory provisioning not allowed"
MsgPolicyNotFound string = "Failed to find an active Policy"
MsgPolicyReady string = "Policy is active"
MsgInvalidNamespace string = "Invalid connection namespace for the referenced inventory"
MsgPolicyNotReady string = "Another active Policy already exists"
Expand Down
20 changes: 0 additions & 20 deletions controllers/dbaas_controllers_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,6 @@ func assertInventoryStatus(inv *v1beta1.DBaaSInventory, condType string, dbaasSt
}
}

func assertInventoryStatusV1alpha1(inv *v1alpha1.DBaaSInventory, condType string, dbaasStatus metav1.ConditionStatus, providerResourceStatus interface{}) func() {
return func() {
status := inv.Status.DeepCopy()
dbaasConds, providerConds := splitStatusConditions(status.Conditions, condType)
Expect(len(dbaasConds)).Should(Equal(1))
Expect(dbaasConds[0].Type).Should(Equal(condType))
Expect(dbaasConds[0].Status).Should(Equal(dbaasStatus))
status.Conditions = providerConds
Expect(status).Should(Equal(providerResourceStatus))
}
}
func assertConnectionStatus(conn *v1beta1.DBaaSConnection, condType string, providerResourceStatus interface{}) func() {
return func() {
assertConnectionDBaaSStatus(conn.Name, conn.Namespace, metav1.ConditionTrue)()
Expand Down Expand Up @@ -526,15 +515,6 @@ func assertInstanceStatus(conn *v1beta1.DBaaSInstance, condType string, provider
}
}

func assertInstanceStatusV1alpha1(conn *v1alpha1.DBaaSInstance, condType string, providerResourceStatus interface{}) func() {
return func() {
assertInstanceDBaaSStatus(conn.Name, conn.Namespace, metav1.ConditionTrue)()
status := conn.Status.DeepCopy()
_, providerConds := splitStatusConditions(status.Conditions, condType)
status.Conditions = providerConds
Expect(status).Should(Equal(providerResourceStatus))
}
}
func assertProviderResourceSpecUpdated(object client.Object, groupVersion schema.GroupVersion, providerResourceKind string, DBaaSResourceSpec interface{}) func() {
return func() {
By("updating the DBaaS resource spec")
Expand Down
10 changes: 4 additions & 6 deletions controllers/dbaas_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,15 @@ func (r *DBaaSReconciler) isValidConnectionNS(ctx context.Context, namespace str

// check if provisioning is allowed against an inventory. inventory takes precedence over dbaaspolicy.
func canProvision(inventory *v1beta1.DBaaSInventory, activePolicy *v1beta1.DBaaSPolicy) bool {
if activePolicy == nil {
// not an active namespace
return false
}
if inventory.Spec.Policy != nil {
if inventory.Spec.Policy.DisableProvisions != nil {
return !*inventory.Spec.Policy.DisableProvisions
}
} else {
if activePolicy.Spec.DisableProvisions != nil {
return !*activePolicy.Spec.DisableProvisions
if activePolicy != nil {
if activePolicy.Spec.DisableProvisions != nil {
return !*activePolicy.Spec.DisableProvisions
}
}
}
return true
Expand Down
5 changes: 2 additions & 3 deletions controllers/dbaas_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,13 @@ var _ = Describe("list policies by inventory namespace", func() {
Expect(canProvision(inventory, activePolicy)).Should(BeTrue())
activePolicy.Spec.DisableProvisions = &isTrue
Expect(canProvision(inventory, activePolicy)).Should(BeFalse())
// check nil policy
Expect(canProvision(inventory, nil)).Should(BeTrue())

// override policy setting
isFalse := false
inventory.Spec.Policy = &v1beta1.DBaaSInventoryPolicy{DisableProvisions: &isFalse}
Expect(canProvision(inventory, activePolicy)).Should(BeTrue())

// check nil policy
Expect(canProvision(inventory, nil)).Should(BeFalse())
})

It("should, upon deletion, make another policy active", func() {
Expand Down
28 changes: 0 additions & 28 deletions controllers/dbaasinventory_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,6 @@ func (r *DBaaSInventoryReconciler) Reconcile(ctx context.Context, req ctrl.Reque
event = metrics.LabelEventValueCreate
}

policyList, err := r.policyListByNS(ctx, req.Namespace)
if err != nil {
logger.Error(err, "unable to list policies")
metricLabelErrCdValue = metrics.LabelErrorCdValueUnableToListPolicies
return ctrl.Result{}, err
}
activePolicy := getActivePolicy(policyList)
if activePolicy == nil {
logger.Info("No DBaaSPolicy found for the target namespace", "Namespace", req.Namespace)
cond := metav1.Condition{
Type: v1beta1.DBaaSInventoryReadyType,
Status: metav1.ConditionFalse,
Reason: v1beta1.DBaaSPolicyNotFound,
Message: v1beta1.MsgPolicyNotFound,
}
apimeta.SetStatusCondition(&inventory.Status.Conditions, cond)
if err := r.Client.Status().Update(ctx, &inventory); err != nil {
if errors.IsConflict(err) {
logger.V(1).Info("DBaaS Inventory resource modified, retry syncing status", "DBaaS Inventory", inventory)
return ctrl.Result{Requeue: true}, nil
}
logger.Error(err, "Error updating the DBaaS Inventory resource status", "DBaaS Inventory", inventory)
metricLabelErrCdValue = metrics.LabelErrorCdValueErrorUpdatingInventoryStatus
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}

if err := r.checkCredsRefLabel(ctx, inventory); err != nil {
if errors.IsConflict(err) {
return ctrl.Result{Requeue: true}, nil
Expand Down
26 changes: 0 additions & 26 deletions controllers/dbaasinventory_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,6 @@ var _ = Describe("DBaaSInventory controller with errors", func() {
ns := "testns-no-policy"
nsSpec := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ns}}
BeforeEach(assertResourceCreationIfNotExists(nsSpec))
Context("after creating DBaaSInventory without policy in the target namespace", func() {
inventoryName := "test-inventory-no-policy"
testSecret2 := testSecret.DeepCopy()
testSecret2.Namespace = ns
DBaaSInventorySpec := &v1beta1.DBaaSInventorySpec{
CredentialsRef: &v1beta1.LocalObjectReference{
Name: testSecret2.Name,
},
}
testCreatedDBaaSInventory := &v1beta1.DBaaSInventory{
ObjectMeta: metav1.ObjectMeta{
Name: inventoryName,
Namespace: ns,
},
Spec: v1beta1.DBaaSOperatorInventorySpec{
ProviderRef: v1beta1.NamespacedName{
Name: testProviderName,
},
DBaaSInventorySpec: *DBaaSInventorySpec,
},
}
BeforeEach(assertResourceCreationIfNotExists(testSecret2))
BeforeEach(assertResourceCreationIfNotExists(testCreatedDBaaSInventory))
It("reconcile with error", assertDBaaSResourceStatusUpdated(testCreatedDBaaSInventory, metav1.ConditionFalse, v1beta1.DBaaSPolicyNotFound))
})

Context("after creating DBaaSInventory without valid provider", func() {
inventoryName := "test-inventory-no-provider"
providerName := "provider-no-exist"
Expand Down
10 changes: 2 additions & 8 deletions controllers/dbaasplatform_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ var _ = Describe("DBaaSPlatform controller", func() {
},
}
err := dRec.Get(ctx, client.ObjectKeyFromObject(secret), secret)
if err != nil {
return false
}
return true
return err == nil
}, timeout).Should(BeTrue())

Eventually(func() bool {
Expand All @@ -73,10 +70,7 @@ var _ = Describe("DBaaSPlatform controller", func() {
},
}
err := dRec.Get(ctx, client.ObjectKeyFromObject(cm), cm)
if err != nil {
return false
}
return true
return err == nil
}, timeout).Should(BeTrue())
})
})
Expand Down