@@ -74,17 +74,16 @@ func (r *RecommendationReconciler) Reconcile(ctx context.Context, req ctrl.Reque
7474 _ = log .FromContext (ctx )
7575
7676 key := req .NamespacedName
77- klog .Info ("got event for Recommendation: " , key .String ())
7877
7978 obj := & api.Recommendation {}
8079 if err := r .Client .Get (ctx , key , obj ); err != nil {
81- klog .Infof ("Recommendation %q doesn't exist anymore" , key .String ())
8280 return ctrl.Result {}, client .IgnoreNotFound (err )
8381 }
8482 obj = obj .DeepCopy ()
8583
8684 // Skipped outdated Recommendation
8785 if obj .Status .Outdated {
86+ klog .Infof ("skipped outdated recommendation: %s" , obj .Name )
8887 _ , err := kmc .PatchStatus (ctx , r .Client , obj , func (obj client.Object ) client.Object {
8988 in := obj .(* api.Recommendation )
9089 in .Status .ObservedGeneration = in .Generation
@@ -107,6 +106,7 @@ func (r *RecommendationReconciler) Reconcile(ctx context.Context, req ctrl.Reque
107106 }
108107
109108 if obj .Status .FailedAttempt > pointer .Int32 (obj .Spec .BackoffLimit ) {
109+ klog .Infof ("backoff limit exceeded for recommendation: %s" , key .String ())
110110 _ , err := kmc .PatchStatus (ctx , r .Client , obj , func (obj client.Object ) client.Object {
111111 in := obj .(* api.Recommendation )
112112 in .Status .ObservedGeneration = in .Generation
@@ -129,6 +129,23 @@ func (r *RecommendationReconciler) Reconcile(ctx context.Context, req ctrl.Reque
129129 }
130130 }
131131
132+ if obj .Status .Phase == api .Pending && obj .Status .ApprovalStatus == api .ApprovalPending {
133+ if obj .Spec .Deadline != nil && obj .Spec .Deadline .UTC ().Before (r .Clock .Now ()) {
134+ _ , err := kmc .PatchStatus (ctx , r .Client , obj , func (obj client.Object ) client.Object {
135+ in := obj .(* api.Recommendation )
136+ in .Status .ApprovalStatus = api .ApprovalApproved
137+ in .Status .ApprovedWindow = & api.ApprovedWindow {
138+ Window : api .Immediate ,
139+ }
140+ return in
141+ })
142+ if err != nil {
143+ return ctrl.Result {}, err
144+ }
145+ return ctrl.Result {RequeueAfter : r .RequeueAfterDuration }, nil
146+ }
147+ }
148+
132149 if obj .Status .ApprovalStatus == api .ApprovalApproved {
133150 if obj .Status .Phase == api .InProgress && obj .Status .CreatedOperationRef != nil {
134151 return r .checkOpsRequestStatus (ctx , obj )
@@ -157,8 +174,14 @@ func (r *RecommendationReconciler) Reconcile(ctx context.Context, req ctrl.Reque
157174 // If WaitingForMaintenanceWindow, but certificate deadline is reached,
158175 // trigger maintenanceWork anyway, requeue otherwise
159176 if obj .Status .Phase == api .Waiting && obj .Status .Reason == api .WaitingForMaintenanceWindow {
160- if obj .Spec .Deadline != nil && obj .Spec .Deadline .UTC ().After (r .Clock .Now ()) {
161- return ctrl.Result {RequeueAfter : r .RequeueAfterDuration }, nil
177+ if obj .Spec .Deadline != nil {
178+ if obj .Spec .Deadline .UTC ().After (r .Clock .Now ()) && ! isMaintenanceTime {
179+ return ctrl.Result {RequeueAfter : r .RequeueAfterDuration }, nil
180+ }
181+ } else {
182+ if ! isMaintenanceTime {
183+ return ctrl.Result {RequeueAfter : r .RequeueAfterDuration }, nil
184+ }
162185 }
163186 }
164187
@@ -220,10 +243,12 @@ func (r *RecommendationReconciler) checkOpsRequestStatus(ctx context.Context, rc
220243 }
221244
222245 if success == nil {
246+ klog .Infof ("not successful operation retry again %q" , key .String ())
223247 return ctrl.Result {RequeueAfter : r .RequeueAfterDuration }, nil
224248 }
225249
226250 if pointer .Bool (success ) {
251+ klog .Infof ("successful operation %q" , key .String ())
227252 _ , err = kmc .PatchStatus (ctx , r .Client , rcmd , func (obj client.Object ) client.Object {
228253 in := obj .(* api.Recommendation )
229254 in .Status .Phase = api .Succeeded
@@ -240,6 +265,7 @@ func (r *RecommendationReconciler) checkOpsRequestStatus(ctx context.Context, rc
240265 })
241266 return ctrl.Result {}, err
242267 } else {
268+ klog .Infof ("record failed operation %q" , key .String ())
243269 return r .recordFailedAttempt (ctx , rcmd , errors .New ("operation has been failed" ))
244270 }
245271}
@@ -256,7 +282,6 @@ func (r *RecommendationReconciler) runMaintenanceWork(ctx context.Context, rcmd
256282
257283 deadlineMgr := deadline_manager .NewManager (rcmd , r .Clock )
258284 deadlineKnocking := deadlineMgr .IsDeadlineLessThan (r .BeforeDeadlineDuration )
259-
260285 if ! (maintainParallelism || deadlineKnocking ) {
261286 _ , err = kmc .PatchStatus (ctx , r .Client , rcmd , func (obj client.Object ) client.Object {
262287 in := obj .(* api.Recommendation )
@@ -272,21 +297,24 @@ func (r *RecommendationReconciler) runMaintenanceWork(ctx context.Context, rcmd
272297
273298 unObj , err := shared .GetUnstructuredObj (rcmd .Spec .Operation )
274299 if err != nil {
300+ klog .Infof ("error getting unstructured object: %v" , err )
275301 return r .handleErr (ctx , rcmd , err , api .Failed )
276302 }
277303
278304 opsReqName , err := generateOpsRequestName (unObj )
279305 if err != nil {
306+ klog .Errorf ("error generating ops request name: %v" , err )
280307 return ctrl.Result {}, err
281308 }
282309 unObj .SetName (opsReqName )
283-
284310 err = r .Client .Create (ctx , unObj )
285311 if err != nil {
312+ klog .Infof ("error creating unstructured object: %v" , err )
286313 return r .handleErr (ctx , rcmd , err , api .Failed )
287314 }
288315
289316 _ , err = kmc .PatchStatus (ctx , r .Client , rcmd , func (obj client.Object ) client.Object {
317+ klog .Info ("Created Opsrequest name is" , opsReqName )
290318 in := obj .(* api.Recommendation )
291319 in .Status .Phase = api .InProgress
292320 in .Status .Reason = api .StartedExecutingOperation
0 commit comments