@@ -46,7 +46,6 @@ import (
46
46
47
47
const (
48
48
DelayAnnotationName = "approval.nephio.org/delay"
49
- DelayConditionType = "approval.nephio.org.DelayExpired"
50
49
PolicyAnnotationName = "approval.nephio.org/policy"
51
50
InitialPolicyAnnotationValue = "initial"
52
51
)
@@ -104,44 +103,16 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
104
103
return ctrl.Result {}, nil
105
104
}
106
105
107
- // If it is published, ignore it
108
- if porchv1alpha1 .LifecycleIsPublished (pr .Spec .Lifecycle ) {
109
- return ctrl.Result {}, nil
110
- }
111
-
112
- // Delay if needed
113
- // This is a workaround for some "settling" that seems to be needed
114
- // in Porch and/or PackageVariant. We should be able to remove it if
115
- // we can fix that.
116
- requeue , err := r .manageDelay (ctx , pr )
117
- if err != nil {
118
- r .recorder .Eventf (pr , corev1 .EventTypeWarning ,
119
- "Error" , "error processing %q: %s" , DelayAnnotationName , err .Error ())
120
-
121
- return ctrl.Result {}, err
122
- }
123
-
124
- // if requeue is > 0, then we should do nothing more with this PackageRevision
125
- // for at least that long
126
- if requeue > 0 {
127
- r .recorder .Event (pr , corev1 .EventTypeNormal ,
128
- "NotApproved" , "delay time not met" )
129
- return ctrl.Result {RequeueAfter : requeue }, nil
130
- }
131
-
132
- // Check for the approval policy annotation
133
- policy , ok := pr .GetAnnotations ()[PolicyAnnotationName ]
106
+ // If we shouldn't process this at all, just return
107
+ policy , ok := shouldProcess (pr )
134
108
if ! ok {
135
- // no policy set, so just return, we are done
136
109
return ctrl.Result {}, nil
137
110
}
138
111
139
112
// If the package revision is owned by a PackageVariant, check the Ready condition
140
113
// of the package variant. If it is not Ready, then we should not approve yet. The
141
114
// lack of readiness could indicate an error which even impacts whether or not the
142
115
// readiness gates have been properly set.
143
- //
144
- //
145
116
pvReady , err := porchutil .PackageVariantReady (ctx , pr , r .porchClient )
146
117
if err != nil {
147
118
r .recorder .Event (pr , corev1 .EventTypeWarning ,
@@ -192,7 +163,32 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
192
163
return ctrl.Result {}, nil
193
164
}
194
165
195
- // policy met
166
+ // Delay if needed, and let the user know via an event
167
+ // We should be able to get rid of this if we add a policy to check
168
+ // the specializer condition. We need to check the *specific* condition,
169
+ // because if the condition has not been added to the readiness gates yet,
170
+ // we could pass all the gates even though that specific condition is missing.
171
+ // That check shouldn't be needed if the initial clone creates the readiness gate
172
+ // entry though (with the function pipeline run).
173
+ requeue , err := manageDelay (pr )
174
+ if err != nil {
175
+ r .recorder .Eventf (pr , corev1 .EventTypeWarning ,
176
+ "Error" , "error processing %q: %s" , DelayAnnotationName , err .Error ())
177
+
178
+ // Do not propagate the error; we do not want it to force an immediate requeue
179
+ // If we could not parse the annotation, it is a user error
180
+ return ctrl.Result {}, nil
181
+ }
182
+
183
+ // if requeue is > 0, then we should do nothing more with this PackageRevision
184
+ // for at least that long
185
+ if requeue > 0 {
186
+ r .recorder .Event (pr , corev1 .EventTypeNormal ,
187
+ "NotApproved" , "delay time not met" )
188
+ return ctrl.Result {RequeueAfter : requeue }, nil
189
+ }
190
+
191
+ // All policies met
196
192
if pr .Spec .Lifecycle == porchv1alpha1 .PackageRevisionLifecycleDraft {
197
193
pr .Spec .Lifecycle = porchv1alpha1 .PackageRevisionLifecycleProposed
198
194
err = r .Update (ctx , pr )
@@ -211,19 +207,33 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
211
207
return ctrl.Result {}, err
212
208
}
213
209
214
- func (r * reconciler ) manageDelay (ctx context.Context , pr * porchv1alpha1.PackageRevision ) (time.Duration , error ) {
210
+ func shouldProcess (pr * porchv1alpha1.PackageRevision ) (string , bool ) {
211
+ result := true
212
+
213
+ // If it is published, ignore it
214
+ result = result && ! porchv1alpha1 .LifecycleIsPublished (pr .Spec .Lifecycle )
215
+
216
+ // Check for the approval policy annotation
217
+ policy , ok := pr .GetAnnotations ()[PolicyAnnotationName ]
218
+ result = result && ok
219
+
220
+ return policy , result
221
+ }
222
+
223
+ func manageDelay (pr * porchv1alpha1.PackageRevision ) (time.Duration , error ) {
215
224
delay , ok := pr .GetAnnotations ()[DelayAnnotationName ]
216
225
if ! ok {
217
- delay = "2m"
226
+ // only delay if there is a delay annotation
227
+ return 0 , nil
218
228
}
229
+
219
230
d , err := time .ParseDuration (delay )
220
231
if err != nil {
221
- return 0 , fmt . Errorf ( "error parsing delay duration: %w" , err )
232
+ return 0 , err
222
233
}
223
234
224
- // force at least a 30 second delay
225
- if d < 30 * time .Second {
226
- d = 30 * time .Second
235
+ if d < 0 {
236
+ return 0 , fmt .Errorf ("invalid delay %q; delay must be 0 or more" , delay )
227
237
}
228
238
229
239
if time .Since (pr .CreationTimestamp .Time ) > d {
0 commit comments