1
1
package operator
2
2
3
3
import (
4
- "context"
5
4
"fmt"
6
5
"strings"
7
6
"time"
8
7
9
- batchv1 "k8s.io/api/batch/v1"
10
- corev1 "k8s.io/api/core/v1"
11
8
"k8s.io/apimachinery/pkg/api/errors"
12
- "k8s.io/apimachinery/pkg/labels"
13
- "k8s.io/apimachinery/pkg/selection"
14
- utilerrors "k8s.io/apimachinery/pkg/util/errors"
9
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
10
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
16
11
"k8s.io/apimachinery/pkg/util/wait"
17
12
batchv1informers "k8s.io/client-go/informers/batch/v1"
@@ -25,7 +20,6 @@ import (
25
20
"k8s.io/klog/v2"
26
21
27
22
configapiv1 "github.com/openshift/api/config/v1"
28
- operatorv1 "github.com/openshift/api/operator/v1"
29
23
configv1informers "github.com/openshift/client-go/config/informers/externalversions/config/v1"
30
24
configlisters "github.com/openshift/client-go/config/listers/config/v1"
31
25
imageregistryv1informers "github.com/openshift/client-go/imageregistry/informers/externalversions/imageregistry/v1"
@@ -172,7 +166,6 @@ func (c *AzurePathFixController) sync() error {
172
166
return nil
173
167
}
174
168
175
- ctx := context .TODO ()
176
169
imageRegistryConfig , err := c .imageRegistryConfigLister .Get ("cluster" )
177
170
if err != nil {
178
171
return err
@@ -203,110 +196,27 @@ func (c *AzurePathFixController) sync() error {
203
196
c .kubeconfig ,
204
197
)
205
198
206
- progressingCondition := operatorv1.OperatorCondition {
207
- Type : "AzurePathFixProgressing" ,
208
- Status : operatorv1 .ConditionUnknown ,
209
- }
210
- degradedCondition := operatorv1.OperatorCondition {
211
- Type : "AzurePathFixControllerDegraded" ,
212
- Status : operatorv1 .ConditionFalse ,
213
- Reason : "AsExpected" ,
214
- }
215
-
216
- jobObj , err := gen .Get ()
199
+ // this controller was created to aid users migrating from 4.13.z to >=4.14.z.
200
+ // once users have migrated to an OCP version and have run this job at least once,
201
+ // this job is no longer needed. on OCP versions >=4.17 we can be certain that
202
+ // this has already migrated the blobs to the correct place, and we can now
203
+ // safely remove the job. see OCPBUGS-29003 for details.
204
+ _ , err = gen .Get ()
217
205
if errors .IsNotFound (err ) {
218
- progressingCondition .Status = operatorv1 .ConditionTrue
219
- progressingCondition .Reason = "NotFound"
220
- progressingCondition .Message = "The job does not exist"
206
+ return nil
221
207
} else if err != nil {
222
- progressingCondition .Reason = "Unknown"
223
- progressingCondition .Message = fmt .Sprintf ("Unable to check job progress: %s" , err )
208
+ return err
224
209
} else {
225
- job := jobObj .(* batchv1.Job )
226
- jobProgressing := true
227
- var jobCondition batchv1.JobConditionType
228
- for _ , cond := range job .Status .Conditions {
229
- if (cond .Type == batchv1 .JobComplete || cond .Type == batchv1 .JobFailed ) && cond .Status == corev1 .ConditionTrue {
230
- jobProgressing = false
231
- jobCondition = cond .Type
232
- break
233
- }
234
- }
235
-
236
- if jobProgressing {
237
- progressingCondition .Reason = "Migrating"
238
- progressingCondition .Message = fmt .Sprintf ("Azure path fix job is progressing: %d pods active; %d pods failed" , job .Status .Active , job .Status .Failed )
239
- progressingCondition .Status = operatorv1 .ConditionTrue
210
+ gracePeriod := int64 (0 )
211
+ propagationPolicy := metav1 .DeletePropagationForeground
212
+ opts := metav1.DeleteOptions {
213
+ GracePeriodSeconds : & gracePeriod ,
214
+ PropagationPolicy : & propagationPolicy ,
240
215
}
241
-
242
- if jobCondition == batchv1 .JobComplete {
243
- progressingCondition .Reason = "AsExpected"
244
- progressingCondition .Status = operatorv1 .ConditionFalse
245
- }
246
-
247
- if jobCondition == batchv1 .JobFailed {
248
- progressingCondition .Reason = "Failed"
249
- progressingCondition .Status = operatorv1 .ConditionFalse
250
- degradedCondition .Reason = "Failed"
251
- degradedCondition .Status = operatorv1 .ConditionTrue
252
-
253
- // if the job still executing (i.e there are attempts left before backoff),
254
- // we don't want to report degraded, but we let users know that some attempt(s)
255
- // failed, and the job is still progressing.
256
-
257
- requirement , err := labels .NewRequirement ("batch.kubernetes.io/job-name" , selection .Equals , []string {gen .GetName ()})
258
- if err != nil {
259
- // this is extremely unlikely to happen
260
- return err
261
- }
262
- pods , err := c .podLister .List (labels .NewSelector ().Add (* requirement ))
263
- if err != nil {
264
- // there's not much that can be done about an error here,
265
- // the next reconciliation(s) are likely to succeed.
266
- return err
267
- }
268
-
269
- if len (pods ) == 0 {
270
- msg := "Migration failed but no job pods are left to inspect"
271
- progressingCondition .Message = msg
272
- degradedCondition .Message = msg
273
- }
274
-
275
- if len (pods ) > 0 {
276
- mostRecentPod := pods [0 ]
277
- for _ , pod := range pods {
278
- if mostRecentPod .CreationTimestamp .Before (& pod .CreationTimestamp ) {
279
- mostRecentPod = pod
280
- }
281
- }
282
-
283
- if len (mostRecentPod .Status .ContainerStatuses ) > 0 {
284
- status := mostRecentPod .Status .ContainerStatuses [0 ]
285
- msg := fmt .Sprintf ("Migration failed: %s" , status .State .Terminated .Message )
286
- progressingCondition .Message = msg
287
- degradedCondition .Message = msg
288
- }
289
- }
216
+ if err := gen .Delete (opts ); err != nil {
217
+ return err
290
218
}
291
219
}
292
-
293
- err = resource .ApplyMutator (gen )
294
- if err != nil {
295
- _ , _ , updateError := v1helpers .UpdateStatus (
296
- ctx ,
297
- c .operatorClient ,
298
- v1helpers .UpdateConditionFn (progressingCondition ),
299
- v1helpers .UpdateConditionFn (degradedCondition ),
300
- )
301
- return utilerrors .NewAggregate ([]error {err , updateError })
302
- }
303
-
304
- _ , _ , err = v1helpers .UpdateStatus (
305
- ctx ,
306
- c .operatorClient ,
307
- v1helpers .UpdateConditionFn (progressingCondition ),
308
- v1helpers .UpdateConditionFn (degradedCondition ),
309
- )
310
220
return err
311
221
}
312
222
0 commit comments