Skip to content

Commit

Permalink
update finalzier to CRD doc
Browse files Browse the repository at this point in the history
Depends-on: openstack-k8s-operators/lib-common#519
Signed-off-by: Martin Schuppert <[email protected]>
  • Loading branch information
stuggi authored and gibizer committed Nov 21, 2024
1 parent 876cba9 commit 13193ee
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/go-logr/logr v1.4.2
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240603143707-f5c5fe030fdd
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240618142732-ec81334ac10d
k8s.io/api v0.28.11
k8s.io/apimachinery v0.28.11
k8s.io/client-go v0.28.11
Expand Down
4 changes: 2 additions & 2 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/openshift/api v3.9.0+incompatible h1:fJ/KsefYuZAjmrr3+5U9yZIZbTOpVkDDLDLFresAeYs=
github.com/openshift/api v3.9.0+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240603143707-f5c5fe030fdd h1:8s6RMighpgvpYF3WEdEKoLjfrqQ8QJpF4FaP7tOvXSI=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240603143707-f5c5fe030fdd/go.mod h1:4Fe07vWr4OYg2qoFwoOM8rHEukdD3/r3FBqkYKE5//E=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240618142732-ec81334ac10d h1:t1Lvt1WGp/WbkdU5R7nsc0NtMAvfd0K1nlNYLprHhbQ=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240618142732-ec81334ac10d/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
22 changes: 11 additions & 11 deletions api/test/helpers/harnesses.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
Eventually(func() []string {
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: mariadbAccount.Spec.Secret, Namespace: mariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).Should(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).Should(ContainElement(harness.finalizerName))

// mariaDBDatabaseName is set
Expect(mariadbAccount.Labels["mariaDBDatabaseName"]).Should(Equal(harness.databaseName))
Expand Down Expand Up @@ -174,7 +174,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
Eventually(func() []string {
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: mariadbAccount.Spec.Secret, Namespace: mariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).Should(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).Should(ContainElement(harness.finalizerName))

// mariaDBDatabaseName is set
Expect(mariadbAccount.Labels["mariaDBDatabaseName"]).Should(Equal(harness.databaseName))
Expand Down Expand Up @@ -215,7 +215,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
oldMariadbAccount := mariaDBHelper.GetMariaDBAccount(oldAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: oldMariadbAccount.Spec.Secret, Namespace: oldMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).Should(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).Should(ContainElement(harness.finalizerName))

})
It("should ensure a new MariaDBAccount exists when accountname is changed", func() {
Expand Down Expand Up @@ -256,7 +256,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
newMariadbAccount := mariaDBHelper.GetMariaDBAccount(newAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: newMariadbAccount.Spec.Secret, Namespace: newMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).Should(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).Should(ContainElement(harness.finalizerName))

// old account retains the finalizer because we did not yet
// complete the new MariaDBAccount
Expand All @@ -270,7 +270,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
oldMariadbAccount := mariaDBHelper.GetMariaDBAccount(oldAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: oldMariadbAccount.Spec.Secret, Namespace: oldMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).Should(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).Should(ContainElement(harness.finalizerName))

})

Expand Down Expand Up @@ -309,7 +309,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
newMariadbAccount := mariaDBHelper.GetMariaDBAccount(newAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: newMariadbAccount.Spec.Secret, Namespace: newMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).Should(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).Should(ContainElement(harness.finalizerName))

// finalizer removed from old account
Eventually(func() []string {
Expand All @@ -322,7 +322,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
oldMariadbAccount := mariaDBHelper.GetMariaDBAccount(oldAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: oldMariadbAccount.Spec.Secret, Namespace: oldMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).ShouldNot(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).ShouldNot(ContainElement(harness.finalizerName))

// CreateOrPatchDBByName will add a label referring to the database
Eventually(func() string {
Expand Down Expand Up @@ -371,7 +371,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
newMariadbAccount := mariaDBHelper.GetMariaDBAccount(newAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: newMariadbAccount.Spec.Secret, Namespace: newMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).Should(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).Should(ContainElement(harness.finalizerName))

Eventually(func() []string {
oldMariadbAccount := mariaDBHelper.GetMariaDBAccount(oldAccountName)
Expand All @@ -383,7 +383,7 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
oldMariadbAccount := mariaDBHelper.GetMariaDBAccount(oldAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: oldMariadbAccount.Spec.Secret, Namespace: oldMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).Should(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).Should(ContainElement(harness.finalizerName))

// now delete the CR
harness.DeleteCR()
Expand All @@ -405,13 +405,13 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
oldMariadbAccount := mariaDBHelper.GetMariaDBAccount(oldAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: oldMariadbAccount.Spec.Secret, Namespace: oldMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).ShouldNot(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).ShouldNot(ContainElement(harness.finalizerName))

Eventually(func() []string {
newMariadbAccount := mariaDBHelper.GetMariaDBAccount(newAccountName)
dbSecret := harness.mariaDBHelper.GetSecret(types.NamespacedName{Name: newMariadbAccount.Spec.Secret, Namespace: newMariadbAccount.Namespace})
return dbSecret.Finalizers
}, timeout, interval).ShouldNot(ContainElement(fmt.Sprintf("mariadb.openstack.org/%s", harness.finalizerName)))
}, timeout, interval).ShouldNot(ContainElement(harness.finalizerName))

})

Expand Down
10 changes: 4 additions & 6 deletions api/v1beta1/mariadbdatabase_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,12 @@ func (d *Database) DeleteFinalizer(
h *helper.Helper,
) error {

secretFinalizer := fmt.Sprintf("mariadb.openstack.org/%s", h.GetFinalizer())
if d.secretObj != nil && controllerutil.RemoveFinalizer(d.secretObj, secretFinalizer) {
if d.secretObj != nil && controllerutil.RemoveFinalizer(d.secretObj, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, d.secretObj)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
}
util.LogForObject(h, fmt.Sprintf("Removed finalizer %s from Secret %s", secretFinalizer, d.secretObj.Name), d.secretObj)
util.LogForObject(h, fmt.Sprintf("Removed finalizer %s from Secret %s", h.GetFinalizer(), d.secretObj.Name), d.secretObj)
}

if d.account != nil && controllerutil.RemoveFinalizer(d.account, h.GetFinalizer()) {
Expand Down Expand Up @@ -566,8 +565,7 @@ func DeleteUnusedMariaDBAccountFinalizers(
return err
}

secretFinalizer := fmt.Sprintf("mariadb.openstack.org/%s", h.GetFinalizer())
if dbSecret != nil && controllerutil.RemoveFinalizer(dbSecret, secretFinalizer) {
if dbSecret != nil && controllerutil.RemoveFinalizer(dbSecret, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, dbSecret)
if err != nil && !k8s_errors.IsNotFound(err) {
h.GetLogger().Error(
Expand Down Expand Up @@ -651,7 +649,7 @@ func createOrPatchAccountAndSecret(
// GetDatabaseByNameAndAccount to locate the Database which is how
// they remove finalizers. this will return not found if secret
// is not present, so finalizer will keep it around
controllerutil.AddFinalizer(accountSecret, fmt.Sprintf("mariadb.openstack.org/%s", h.GetFinalizer()))
controllerutil.AddFinalizer(accountSecret, h.GetFinalizer())

return nil
})
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/go-logr/logr v1.4.2
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240603143707-f5c5fe030fdd
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.0
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240618142732-ec81334ac10d
github.com/openstack-k8s-operators/mariadb-operator/api v0.0.0-00010101000000-000000000000
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
k8s.io/api v0.28.11
k8s.io/apimachinery v0.28.11
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240603143707-f5c5fe030fdd h1:8s6RMighpgvpYF3WEdEKoLjfrqQ8QJpF4FaP7tOvXSI=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240603143707-f5c5fe030fdd/go.mod h1:4Fe07vWr4OYg2qoFwoOM8rHEukdD3/r3FBqkYKE5//E=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240618142732-ec81334ac10d h1:t1Lvt1WGp/WbkdU5R7nsc0NtMAvfd0K1nlNYLprHhbQ=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240618142732-ec81334ac10d/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down

0 comments on commit 13193ee

Please sign in to comment.