Giter Site home page Giter Site logo

Comments (2)

redradrat avatar redradrat commented on June 11, 2024

@shivpathak I'm not sure what we can do about that on operator side? Of course we cannot delete a Policy before a PolicyAttachment. But the user has to be aware of that order. Right now the operator should give an error, if you try to delete in the wrong order. Is this not the case?

I think the operator should throw an error if you're trying to delete in the wrong order, and once you delete the right object, it should finish deletion.

Here we check for existing Attachments:

// Returns a function, that does everything necessary before we can delete our actual Policy (cleanup)
func policyCleanup(r *PolicyReconciler, ctx context.Context, policy *iamv1beta1.Policy) func() error {
return func() error {
attachments := iamv1beta1.PolicyAttachmentList{}
if err := r.List(ctx, &attachments); err != nil {
return err
}
for _, att := range attachments.Items {
if att.Spec.PolicyReference.Name == policy.Name && att.Spec.PolicyReference.Namespace == policy.Namespace {
err := fmt.Errorf(fmt.Sprintf("cannot delete policy due to existing PolicyAttachment '%s/%s'", att.Name, att.Namespace))
return err
}
}
return nil
}
}

Here we fail if there was a "cleanup" error:

cleanupFunc := policyCleanup(r, ctx, &policy)
// Check Deletion and finalizer
if policy.ObjectMeta.DeletionTimestamp.IsZero() {
// The object is not being deleted, so if it does not have our finalizer,
// then lets add the finalizer and update the object. This is equivalent
// registering our finalizer.
if !containsString(policy.ObjectMeta.Finalizers, policiesFinalizer) {
policy.ObjectMeta.Finalizers = append(policy.ObjectMeta.Finalizers, policiesFinalizer)
if err := r.Update(context.Background(), &policy); err != nil {
log.Error(err, "unable to register finalizer for Policy")
return ctrl.Result{}, errWithStatus(&policy, err, r.Status(), ctx)
}
}
} else {
if containsString(policy.ObjectMeta.Finalizers, policiesFinalizer) {
// our finalizer is present, so lets handle any external dependency
// delete the actual AWS Object and pass the cleanup function
statusWriter, err := DeleteAWSObject(iamsvc, ins, cleanupFunc)
statusWriter(ins, &policy, ctx, r.Status(), log)
if err != nil {
// we had an error during AWS Object deletion... so we return here to retry
log.Error(err, "unable to delete Policy")
return ctrl.Result{}, err
}

So as soon as the PolicyAttachment is gone, the deletion should cascade.

from aws-iam-operator.

redradrat avatar redradrat commented on June 11, 2024

Oh I see the issue,

the reconcile filter filters out the actual re-reuns after failing, due to the generation already being increased. Will move the generation increase to after the reconcile went OK.

from aws-iam-operator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.