@@ -121,22 +121,15 @@ func (r *UpgradeJobReconciler) Reconcile(ctx context.Context, req ctrl.Request)
121121
122122 now := r .Clock .Now ()
123123
124- window , err := r .matchingUpgradeSuspensionWindow (ctx , uj , now )
125- if err != nil {
126- return ctrl.Result {}, fmt .Errorf ("failed to search for matching upgrade suspension window: %w" , err )
127- }
128- if window != nil {
129- l .Info ("Upgrade job skipped by UpgradeSuspensionWindow" , "window" , window .Name , "reason" , window .Spec .Reason , "start" , window .Spec .Start .Time , "end" , window .Spec .End .Time )
130- r .setStatusCondition (& uj .Status .Conditions , metav1.Condition {
131- Type : managedupgradev1beta1 .UpgradeJobConditionSucceeded ,
132- Status : metav1 .ConditionTrue ,
133- Reason : managedupgradev1beta1 .UpgradeJobReasonSkipped ,
134- Message : fmt .Sprintf ("Upgrade job skipped by UpgradeSuspensionWindow %q, reason: %q" , window .Name , window .Spec .Reason ),
135- })
136- return ctrl.Result {}, r .Status ().Update (ctx , & uj )
137- }
138-
139124 if now .After (uj .Spec .StartBefore .Time ) {
125+ skipped , err := r .checkAndMarkSkipped (ctx , uj , now )
126+ if err != nil {
127+ return ctrl.Result {}, err
128+ }
129+ if skipped {
130+ return ctrl.Result {}, nil
131+ }
132+
140133 r .setStatusCondition (& uj .Status .Conditions , metav1.Condition {
141134 Type : managedupgradev1beta1 .UpgradeJobConditionFailed ,
142135 Status : metav1 .ConditionTrue ,
@@ -148,6 +141,14 @@ func (r *UpgradeJobReconciler) Reconcile(ctx context.Context, req ctrl.Request)
148141 }
149142
150143 if ! now .Before (uj .Spec .StartAfter .Time ) {
144+ skipped , err := r .checkAndMarkSkipped (ctx , uj , now )
145+ if err != nil {
146+ return ctrl.Result {}, err
147+ }
148+ if skipped {
149+ return ctrl.Result {}, nil
150+ }
151+
151152 r .setStatusCondition (& uj .Status .Conditions , metav1.Condition {
152153 Type : managedupgradev1beta1 .UpgradeJobConditionStarted ,
153154 Status : metav1 .ConditionTrue ,
@@ -1010,3 +1011,22 @@ func (r *UpgradeJobReconciler) matchingUpgradeSuspensionWindow(ctx context.Conte
10101011
10111012 return nil , nil
10121013}
1014+
1015+ // checkAndMarkSkipped checks if the upgrade job should be skipped due to an UpgradeSuspensionWindow and marks it as skipped if necessary.
1016+ func (r * UpgradeJobReconciler ) checkAndMarkSkipped (ctx context.Context , uj managedupgradev1beta1.UpgradeJob , now time.Time ) (skipped bool , err error ) {
1017+ window , err := r .matchingUpgradeSuspensionWindow (ctx , uj , now )
1018+ if err != nil {
1019+ return true , fmt .Errorf ("failed to search for matching upgrade suspension window: %w" , err )
1020+ }
1021+ if window != nil {
1022+ log .FromContext (ctx ).Info ("Upgrade job skipped by UpgradeSuspensionWindow" , "window" , window .Name , "reason" , window .Spec .Reason , "start" , window .Spec .Start .Time , "end" , window .Spec .End .Time )
1023+ r .setStatusCondition (& uj .Status .Conditions , metav1.Condition {
1024+ Type : managedupgradev1beta1 .UpgradeJobConditionSucceeded ,
1025+ Status : metav1 .ConditionTrue ,
1026+ Reason : managedupgradev1beta1 .UpgradeJobReasonSkipped ,
1027+ Message : fmt .Sprintf ("Upgrade job skipped by UpgradeSuspensionWindow %q, reason: %q" , window .Name , window .Spec .Reason ),
1028+ })
1029+ return true , r .Status ().Update (ctx , & uj )
1030+ }
1031+ return false , nil
1032+ }
0 commit comments