Skip to content

Commit

Permalink
feat: add option to orphan resources
Browse files Browse the repository at this point in the history
Signed-off-by: atarax <[email protected]>
  • Loading branch information
kaessert authored and Serpentiel committed Oct 17, 2023
1 parent aaea43b commit ab81e14
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion controllers/basic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit ab81e14

Please sign in to comment.