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

retrigger awsacfg update immediately after pod restart #55

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Changes from all 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
11 changes: 8 additions & 3 deletions controllers/awsadapterconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ const (
// AWSAdapterConfigReconciler reconciles a AWSAdapterConfig object
type AWSAdapterConfigReconciler struct {
client.Client
Scheme *runtime.Scheme
RequeueInterval time.Duration
Scheme *runtime.Scheme
RequeueInterval time.Duration
updatedStatusOnceAfterStart bool
}

//+kubebuilder:rbac:groups=security.nirmata.io,resources=awsadapterconfigs,verbs=get;list;watch;create;update;patch;delete
Expand All @@ -79,7 +80,7 @@ func (r *AWSAdapterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Req
}

if !isStatusVacuous(&objOld.Status) {
if metav1.Now().Time.Before(objOld.Status.LastPollInfo.Timestamp.Add(r.RequeueInterval)) {
if r.updatedStatusOnceAfterStart && metav1.Now().Time.Before(objOld.Status.LastPollInfo.Timestamp.Add(r.RequeueInterval)) {
return ctrl.Result{}, nil
}
}
Expand Down Expand Up @@ -411,6 +412,8 @@ func (r *AWSAdapterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Req
objNew.Status.LastUpdatedTimestamp = &metav1.Time{Time: currentPollTimestamp}
if err := r.Status().Update(ctx, objNew); err != nil {
l.Error(err, "error updating status")
} else {
r.updatedStatusOnceAfterStart = true
}
}

Expand All @@ -434,6 +437,8 @@ func (r *AWSAdapterConfigReconciler) updateLastPollStatusFailure(ctx context.Con

if err := r.Status().Update(ctx, objOld); err != nil {
l.Error(err, "error updating last poll's status failure")
} else {
r.updatedStatusOnceAfterStart = true
}

return ctrl.Result{RequeueAfter: r.RequeueInterval}, nil
Expand Down