Skip to content

Commit

Permalink
retrigger awsacfg update immediately after pod restart (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
pns-nirmata authored Jan 12, 2023
1 parent e1c95ec commit e209814
Showing 1 changed file with 8 additions and 3 deletions.
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

0 comments on commit e209814

Please sign in to comment.