Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle graceful deletion of awsadapterconfig #44

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/samples/security_v1alpha1_awsadapterconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
app.kubernetes.io/part-of: kyverno-aws-adapter
app.kubernetes.io/created-by: kyverno-aws-adapter
name: test-config
namespace: abcd
namespace: default
spec:
name: test
region: us-west-1
10 changes: 7 additions & 3 deletions controllers/awsadapterconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/google/go-cmp/cmp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -58,9 +57,13 @@ func (r *AWSAdapterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Req
l := log.FromContext(ctx)

objOld := &securityv1alpha1.AWSAdapterConfig{}
err := r.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, objOld)
err := r.Get(ctx, req.NamespacedName, objOld)
Copy link
Contributor

@pns-nirmata pns-nirmata Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple warning with pointers to creation of the CR might be helpful here, along with the return. Also, this means there could be multiple CRs trying to get from AWS. Not a problem as such, but not needed too.

if err != nil {
l.Error(err, "error occurred while retrieving awsadapterconfig")
return ctrl.Result{}, client.IgnoreNotFound(err)
}

if !objOld.DeletionTimestamp.IsZero() {
l.Info("Deleting AWSAdapterConfig")
pns-nirmata marked this conversation as resolved.
Show resolved Hide resolved
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -291,6 +294,7 @@ func (r *AWSAdapterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Req
Timestamp: &metav1.Time{Time: currentPollTimestamp},
Status: PollSuccess,
}

if !cmp.Equal(objNew.Status.EKSCluster, objOld.Status.EKSCluster) {
objNew.Status.LastUpdatedTimestamp = &metav1.Time{Time: currentPollTimestamp}
if err := r.Status().Update(ctx, objNew); err != nil {
Expand Down