diff --git a/controllers/basic_controller.go b/controllers/basic_controller.go index 75ef35a3..4aac1b0f 100644 --- a/controllers/basic_controller.go +++ b/controllers/basic_controller.go @@ -317,7 +317,23 @@ func (i instanceReconcilerHelper) getObjectRefs(ctx context.Context, o client.Ob func (i instanceReconcilerHelper) finalize(ctx context.Context, o client.Object) (ctrl.Result, error) { i.rec.Event(o, corev1.EventTypeNormal, eventTryingToDeleteAtAiven, "trying to delete instance at aiven") - finalised, err := i.h.delete(ctx, i.avn, o) + var err error + finalised := true + deletionPolicy := deletionPolicyDelete + + // Parse the annotations for the deletion policy. For simplicity, we only allow 'Orphan'. + // If set will skip the deletion of the remote object. Disable by removing the annoation. + if p, ok := o.GetAnnotations()[deletionPolicyAnnotation]; ok { + deletionPolicy = deletionPolicyOrphan + if p != deletionPolicyOrphan { + i.log.Info(fmt.Sprintf("Invalid deletion policy! Only '%s' is allowed.", deletionPolicyOrphan)) + finalised = false + } + } + + if deletionPolicy == deletionPolicyDelete { + finalised, err = i.h.delete(ctx, i.avn, o) + } // There are dependencies on Aiven side, resets error, so it goes for requeue // Handlers does not have logger, it goes here diff --git a/controllers/common.go b/controllers/common.go index 0e255d33..9cdeb90b 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -28,6 +28,10 @@ const ( processedGenerationAnnotation = "controllers.aiven.io/generation-was-processed" instanceIsRunningAnnotation = "controllers.aiven.io/instance-is-running" + + deletionPolicyAnnotation = "controllers.aiven.io/deletion-policy" + deletionPolicyOrphan = "Orphan" + deletionPolicyDelete = "Delete" ) var (