Skip to content

Commit

Permalink
Added suite cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed Jul 24, 2024
1 parent c026a90 commit db485ae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/v1beta1/aerospikebackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type AerospikeBackupStatus struct {
// This config is used to trigger backups. It includes: aerospike-cluster, backup-routines.
Config runtime.RawExtension `json:"config"`

// OnDemand is the configuration on demand backups.
// OnDemand is the configuration for demand backups.
OnDemand []OnDemandSpec `json:"onDemand,omitempty"`
// TODO: finalize the status and phase
}
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/asdb.aerospike.com_aerospikebackups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
onDemand:
description: OnDemand is the configuration on demand backups.
description: OnDemand is the configuration for demand backups.
items:
properties:
delay:
Expand Down
34 changes: 21 additions & 13 deletions controllers/backup/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ func (r *SingleBackupReconciler) reconcileConfigMap() error {
}

r.Log.Info("Updating existing ConfigMap for Backup",
"name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
"name", r.aeroBackup.Spec.BackupService.Name,
"namespace", r.aeroBackup.Spec.BackupService.Namespace,
)

backupDataMap := make(map[string]interface{})
cmDataMap := make(map[string]interface{})
Expand Down Expand Up @@ -193,7 +195,9 @@ func (r *SingleBackupReconciler) reconcileConfigMap() error {
}

r.Log.Info("Updated Backup Service ConfigMap for Backup",
"name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
"name", r.aeroBackup.Spec.BackupService.Name,
"namespace", r.aeroBackup.Spec.BackupService.Namespace,
)

return nil
}
Expand All @@ -215,7 +219,9 @@ func (r *SingleBackupReconciler) removeBackupInfoFromConfigMap() error {
}

r.Log.Info("Removing Backup info from existing ConfigMap",
"name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
"name", r.aeroBackup.Spec.BackupService.Name,
"namespace", r.aeroBackup.Spec.BackupService.Namespace,
)

backupDataMap := make(map[string]interface{})
cmDataMap := make(map[string]interface{})
Expand Down Expand Up @@ -269,7 +275,9 @@ func (r *SingleBackupReconciler) removeBackupInfoFromConfigMap() error {
}

r.Log.Info("Removed Backup info from existing ConfigMap",
"name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
"name", r.aeroBackup.Spec.BackupService.Name,
"namespace", r.aeroBackup.Spec.BackupService.Namespace,
)

return nil
}
Expand All @@ -278,12 +286,13 @@ func (r *SingleBackupReconciler) scheduleOnDemandBackup() error {
// There can be only one on-demand backup allowed right now.
if len(r.aeroBackup.Status.OnDemand) > 0 &&
r.aeroBackup.Spec.OnDemand[0].ID == r.aeroBackup.Status.OnDemand[0].ID {
r.Log.Info("On-demand backup already scheduled",
"name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
r.Log.Info("On-demand backup already scheduled for the same ID",
"ID", r.aeroBackup.Status.OnDemand[0].ID)
return nil
}

r.Log.Info("Schedule on-demand backup", "name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
r.Log.Info("Schedule on-demand backup",
"ID", r.aeroBackup.Spec.OnDemand[0].ID, "routine", r.aeroBackup.Spec.OnDemand[0].RoutineName)

backupServiceClient, err := backup_service.GetBackupServiceClient(r.Client, &r.aeroBackup.Spec.BackupService)
if err != nil {
Expand All @@ -296,8 +305,8 @@ func (r *SingleBackupReconciler) scheduleOnDemandBackup() error {
return err
}

r.Log.Info("Scheduled on-demand backup", "routine-name",
r.aeroBackup.Spec.OnDemand[0].RoutineName)
r.Log.Info("Scheduled on-demand backup", "ID", r.aeroBackup.Spec.OnDemand[0].ID,
"routine", r.aeroBackup.Spec.OnDemand[0].RoutineName)

return nil
}
Expand All @@ -322,12 +331,11 @@ func (r *SingleBackupReconciler) reconcileScheduledBackup() error {
}

if specHash == statusHash {
r.Log.Info("Backup config not changed",
"name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
r.Log.Info("Backup config not changed")
return nil
}

r.Log.Info("Registering backup", "name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
r.Log.Info("Registering backup")

serviceClient, err := backup_service.GetBackupServiceClient(r.Client, &r.aeroBackup.Spec.BackupService)
if err != nil {
Expand Down Expand Up @@ -400,7 +408,7 @@ func (r *SingleBackupReconciler) reconcileScheduledBackup() error {
return err
}

r.Log.Info("Registered backup", "name", r.aeroBackup.Name, "namespace", r.aeroBackup.Namespace)
r.Log.Info("Registered backup")

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ spec:
type: object
x-kubernetes-preserve-unknown-fields: true
onDemand:
description: OnDemand is the configuration on demand backups.
description: OnDemand is the configuration for demand backups.
items:
properties:
delay:
Expand Down
12 changes: 12 additions & 0 deletions test/cleanup-test-namespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ for namespace in $namespaces; do
echo "Removing Aerospike clusters from namespace: $namespace"
kubectl -n "$namespace" delete aerospikecluster --all

echo "Removing Aerospike restore from namespace: $namespace"
kubectl -n "$namespace" delete aerospikerestore --all

echo "Removing Aerospike backup from namespace: $namespace"
kubectl -n "$namespace" delete aerospikebackup --all

echo "Removing Aerospike backup service from namespace: $namespace"
kubectl -n "$namespace" delete aerospikebackupservice --all

# Force delete pods
kubectl -n "$namespace" delete pod --selector 'app=aerospike-cluster' --grace-period=0 --force --ignore-not-found

Expand Down Expand Up @@ -43,6 +52,9 @@ kubectl delete clusterserviceversion -n $OPERATOR_NS $(kubectl get clusterservic
kubectl delete job $(kubectl get job -o=jsonpath='{.items[?(@.status.succeeded==1)].metadata.name}' -n $OPERATOR_NS) -n $OPERATOR_NS --ignore-not-found
kubectl delete CatalogSource $(kubectl get CatalogSource -n $OPERATOR_NS | grep aerospike-kubernetes-operator | cut -f 1 -d ' ') --ignore-not-found
kubectl delete crd aerospikeclusters.asdb.aerospike.com --ignore-not-found
kubectl delete crd aerospikerestores.asdb.aerospike.com --ignore-not-found
kubectl delete crd aerospikebackups.asdb.aerospike.com --ignore-not-found
kubectl delete crd aerospikebackupservices.asdb.aerospike.com --ignore-not-found

# Delete webhook configurations. Web hooks from older versions linger around and intercept requests.
kubectl delete mutatingwebhookconfigurations.admissionregistration.k8s.io $(kubectl get mutatingwebhookconfigurations.admissionregistration.k8s.io | grep aerospike | cut -f 1 -d " ")
Expand Down

0 comments on commit db485ae

Please sign in to comment.