|
9 | 9 | batchv1 "k8s.io/api/batch/v1" |
10 | 10 | corev1 "k8s.io/api/core/v1" |
11 | 11 | "k8s.io/apimachinery/pkg/api/errors" |
| 12 | + metaapi "k8s.io/apimachinery/pkg/apis/meta/v1" |
12 | 13 | "k8s.io/apimachinery/pkg/labels" |
13 | 14 | "k8s.io/apimachinery/pkg/selection" |
14 | 15 | utilerrors "k8s.io/apimachinery/pkg/util/errors" |
@@ -207,7 +208,8 @@ func (c *AzurePathFixController) sync() error { |
207 | 208 | } |
208 | 209 |
|
209 | 210 | jobObj, err := gen.Get() |
210 | | - if errors.IsNotFound(err) { |
| 211 | + jobExists := !errors.IsNotFound(err) |
| 212 | + if !jobExists { |
211 | 213 | progressingCondition.Status = operatorv1.ConditionTrue |
212 | 214 | progressingCondition.Reason = "NotFound" |
213 | 215 | progressingCondition.Message = "The job does not exist" |
@@ -283,15 +285,51 @@ func (c *AzurePathFixController) sync() error { |
283 | 285 | } |
284 | 286 | } |
285 | 287 |
|
286 | | - err = resource.ApplyMutator(gen) |
287 | | - if err != nil { |
288 | | - _, _, updateError := v1helpers.UpdateStatus( |
289 | | - ctx, |
290 | | - c.operatorClient, |
291 | | - v1helpers.UpdateConditionFn(progressingCondition), |
292 | | - v1helpers.UpdateConditionFn(degradedCondition), |
293 | | - ) |
294 | | - return utilerrors.NewAggregate([]error{err, updateError}) |
| 288 | + switch imageRegistryConfig.Spec.ManagementState { |
| 289 | + case operatorv1.Removed: |
| 290 | + progressingCondition.Reason = "Removed" |
| 291 | + progressingCondition.Message = "The job is removed" |
| 292 | + progressingCondition.Status = operatorv1.ConditionFalse |
| 293 | + degradedCondition.Reason = "Removed" |
| 294 | + degradedCondition.Message = "The job is removed" |
| 295 | + degradedCondition.Status = operatorv1.ConditionFalse |
| 296 | + |
| 297 | + if jobExists { |
| 298 | + gracePeriod := int64(0) |
| 299 | + propagationPolicy := metaapi.DeletePropagationForeground |
| 300 | + opts := metaapi.DeleteOptions{ |
| 301 | + GracePeriodSeconds: &gracePeriod, |
| 302 | + PropagationPolicy: &propagationPolicy, |
| 303 | + } |
| 304 | + if err := gen.Delete(opts); err != nil { |
| 305 | + // TODO: set condition? |
| 306 | + // TODO: aggregate error and don't return? |
| 307 | + return err |
| 308 | + } |
| 309 | + progressingCondition.Reason = "Removing" |
| 310 | + progressingCondition.Status = operatorv1.ConditionTrue |
| 311 | + degradedCondition.Reason = "Removing" |
| 312 | + degradedCondition.Status = operatorv1.ConditionFalse |
| 313 | + } |
| 314 | + case operatorv1.Managed, operatorv1.Force: |
| 315 | + if azureStorage == nil || azureStorage.AccountName == "" || azureStorage.Container == "" { |
| 316 | + // we don't know the storage account details yet, so we can't create the job. |
| 317 | + // this isn't an error state though - once the CR gets updated with the details |
| 318 | + // a resync will trigger and we'll get a change to create the job. |
| 319 | + return nil |
| 320 | + } |
| 321 | + err = resource.ApplyMutator(gen) |
| 322 | + if err != nil { |
| 323 | + _, _, updateError := v1helpers.UpdateStatus( |
| 324 | + ctx, |
| 325 | + c.operatorClient, |
| 326 | + v1helpers.UpdateConditionFn(progressingCondition), |
| 327 | + v1helpers.UpdateConditionFn(degradedCondition), |
| 328 | + ) |
| 329 | + return utilerrors.NewAggregate([]error{err, updateError}) |
| 330 | + } |
| 331 | + case operatorv1.Unmanaged: |
| 332 | + // ignore |
295 | 333 | } |
296 | 334 |
|
297 | 335 | _, _, err = v1helpers.UpdateStatus( |
|
0 commit comments