Skip to content

Commit

Permalink
Delete additional cell delete job
Browse files Browse the repository at this point in the history
We need to delete only nova finalizer
  • Loading branch information
mrkisaolamb committed Sep 27, 2024
1 parent c68748a commit f188883
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 1,032 deletions.
49 changes: 0 additions & 49 deletions .zuul.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,54 +72,6 @@
ip: 172.18.0.5
tenant:
ip: 172.19.0.5
- job:
name: nova-operator-kuttl-cell-delete
parent: nova-operator-base
dependencies: ["openstack-meta-content-provider"]
roles:
- zuul: github.com/openstack-k8s-operators/ci-framework
description: |
This job deploy a basic "Compute Starter Kit" topology
https://www.openstack.org/software/sample-configs#compute-starter-kit
that is the minium set of openstack services required to boot a vm.
pre-run:
- ci/nova-operator-kuttl-cell-delete/playbooks/deploy-deps.yaml
run:
- ci/nova-operator-kuttl-cell-delete/playbooks/run-kuttl.yaml
nodeset: centos-9-medium-crc-extracted-2-39-0-3xl
vars:
collection_namespace_override: "nova-kuttl-cell-delete-tests"
zuul_log_collection: true
extra-vars:
crc_ci_bootstrap_networking:
networks:
default:
range: 192.168.122.0/24
mtu: 1500
internal-api:
vlan: 20
range: 172.17.0.0/24
storage:
vlan: 21
range: 172.18.0.0/24
tenant:
vlan: 22
range: 172.19.0.0/24
instances:
controller:
networks:
default:
ip: 192.168.122.11
crc:
networks:
default:
ip: 192.168.122.10
internal-api:
ip: 172.17.0.5
storage:
ip: 172.18.0.5
tenant:
ip: 172.19.0.5
- job:
name: nova-operator-tempest-multinode
parent: podified-multinode-edpm-deployment-crc-3comp
Expand Down Expand Up @@ -259,7 +211,6 @@
- nova-operator-kuttl
- nova-operator-tempest-multinode
- nova-operator-tempest-multinode-ceph
- nova-operator-kuttl-cell-delete

- pragma:
implied-branch-matchers: True
Expand Down
2 changes: 0 additions & 2 deletions ci/nova-operator-kuttl-cell-delete/ansible.cfg

This file was deleted.

9 changes: 0 additions & 9 deletions ci/nova-operator-kuttl-cell-delete/inventory.ini

This file was deleted.

18 changes: 0 additions & 18 deletions ci/nova-operator-kuttl-cell-delete/playbooks/deploy-deps.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions ci/nova-operator-kuttl-cell-delete/playbooks/run-kuttl.yaml

This file was deleted.

98 changes: 85 additions & 13 deletions controllers/nova_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,6 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
}

for _, cr := range novaCellList.Items {
cellDbs := [][]string{}
_, ok := instance.Spec.CellTemplates[cr.Spec.CellName]
if !ok {
err := r.ensureCellDeleted(ctx, h, instance,
Expand All @@ -610,26 +609,93 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
if err != nil {
return ctrl.Result{}, err
}
cellDbs = append(cellDbs, []string{novaapi.ServiceName + "-" + cr.Spec.CellName, instance.Spec.CellTemplates[cr.Spec.CellName].CellDatabaseAccount})
Log.Info("Cell deleted", "cell", cr.Spec.CellName)
delete(instance.Status.RegisteredCells, cr.Name)
}
// iterate over novaDbs and remove finalizers
for _, novaDb := range cellDbs {
dbName, accountName := novaDb[0], novaDb[1]
db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, h, dbName, accountName, instance.ObjectMeta.Namespace)

}

Log.Info("Successfully reconciled")
return ctrl.Result{}, nil
}

// GetDatabase returns an existing MariaDBDatabase object from the cluster
func GetDatabase(ctx context.Context,
h *helper.Helper,
name string, namespace string,
) (*mariadbv1.MariaDBDatabase, error) {
mariaDBDatabase := &mariadbv1.MariaDBDatabase{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}
objectKey := client.ObjectKeyFromObject(mariaDBDatabase)

err := h.GetClient().Get(ctx, objectKey, mariaDBDatabase)
if err != nil {
return nil, err
}
return mariaDBDatabase, err
}

func DeleteDatabaseAndAccountFinalizers(
ctx context.Context,
h *helper.Helper,
name string,
accountName string,
namespace string,
) error {

databaseAccount, err := mariadbv1.GetAccount(ctx, h, accountName, namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
} else if err == nil {
if databaseAccount.Spec.Secret != "" {
dbSecret, _, err := secret.GetSecret(ctx, h, databaseAccount.Spec.Secret, namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
return err
}
if !k8s_errors.IsNotFound(err) {
if err := db.DeleteFinalizer(ctx, h); err != nil {
return ctrl.Result{}, err

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

if controllerutil.RemoveFinalizer(databaseAccount, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, databaseAccount)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
}
util.LogForObject(h, fmt.Sprintf("Removed finalizer %s from MariaDBAccount %s", h.GetFinalizer(), databaseAccount.Name), databaseAccount)
}
}

Log.Info("Successfully reconciled")
return ctrl.Result{}, nil
// also do a delete for "unused" MariaDBAccounts, associated with
// this MariaDBDatabase.
err = mariadbv1.DeleteUnusedMariaDBAccountFinalizers(
ctx, h, name, accountName, namespace,
)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
}

mariaDBDatabase, err := GetDatabase(ctx, h, name, namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
} else if err == nil && controllerutil.RemoveFinalizer(mariaDBDatabase, h.GetFinalizer()) {
err := h.GetClient().Update(ctx, mariaDBDatabase)
if err != nil && !k8s_errors.IsNotFound(err) {
return err
}
util.LogForObject(h, fmt.Sprintf("Removed finalizer %s from MariaDBDatabase %s", h.GetFinalizer(), mariaDBDatabase.Spec.Name), mariaDBDatabase)
}

return nil
}

func (r *NovaReconciler) ensureCellDeleted(
Expand Down Expand Up @@ -665,11 +731,14 @@ func (r *NovaReconciler) ensureCellDeleted(
"cell", cell)
return nil
}

err = r.Client.Delete(ctx, cell)
if err != nil && k8s_errors.IsNotFound(err) {
return err
}

dbName, accountName := novaapi.ServiceName+"-"+cell.Spec.CellName, cell.Spec.CellDatabaseAccount

configHash, scriptName, configName, err := r.ensureNovaManageJobSecret(ctx, h, instance,
cell0, topLevelSecret, APIDatabaseHostname, apiTransportURL, apiDB)
if err != nil {
Expand All @@ -687,7 +756,7 @@ func (r *NovaReconciler) ensureCellDeleted(
job := job.NewJob(
jobDef, cell.Name+"-cell-delete",
instance.Spec.PreserveJobs, r.RequeueTimeout,
instance.Status.RegisteredCells[cell.Name])
inputHash)

_, err = job.DoJob(ctx, h)
if err != nil {
Expand All @@ -714,6 +783,9 @@ func (r *NovaReconciler) ensureCellDeleted(
},
}
err = r.Client.Delete(ctx, transportURL)

err = DeleteDatabaseAndAccountFinalizers(ctx, h, dbName, accountName, instance.ObjectMeta.Namespace)

if err != nil {
return err
}
Expand Down
8 changes: 0 additions & 8 deletions test/functional/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@ func NovaConductorConditionGetter(name types.NamespacedName) condition.Condition
return instance.Status.Conditions
}

func AssertConductorDoesNotExist(name types.NamespacedName) {
instance := &novav1.NovaConductor{}
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, name, instance)
g.Expect(k8s_errors.IsNotFound(err)).To(BeTrue())
}, timeout, interval).Should(Succeed())
}

func CreateNovaMessageBusSecret(cell CellNames) *corev1.Secret {
s := th.CreateSecret(
types.NamespacedName{Namespace: cell.CellCRName.Namespace, Name: fmt.Sprintf("%s-secret", cell.TransportURLName.Name)},
Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions test/kuttl/test-suites/cell-delete-tests/config.yaml

This file was deleted.

This file was deleted.

32 changes: 0 additions & 32 deletions test/kuttl/test-suites/cell-delete-tests/deps/infra.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions test/kuttl/test-suites/cell-delete-tests/deps/keystone.yaml

This file was deleted.

Loading

0 comments on commit f188883

Please sign in to comment.