Skip to content

Commit ac3c3af

Browse files
committed
wip
1 parent 50f1b20 commit ac3c3af

File tree

1 file changed

+48
-10
lines changed

1 file changed

+48
-10
lines changed

pkg/operator/azurepathfixcontroller.go

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
batchv1 "k8s.io/api/batch/v1"
1010
corev1 "k8s.io/api/core/v1"
1111
"k8s.io/apimachinery/pkg/api/errors"
12+
metaapi "k8s.io/apimachinery/pkg/apis/meta/v1"
1213
"k8s.io/apimachinery/pkg/labels"
1314
"k8s.io/apimachinery/pkg/selection"
1415
utilerrors "k8s.io/apimachinery/pkg/util/errors"
@@ -207,7 +208,8 @@ func (c *AzurePathFixController) sync() error {
207208
}
208209

209210
jobObj, err := gen.Get()
210-
if errors.IsNotFound(err) {
211+
jobExists := !errors.IsNotFound(err)
212+
if !jobExists {
211213
progressingCondition.Status = operatorv1.ConditionTrue
212214
progressingCondition.Reason = "NotFound"
213215
progressingCondition.Message = "The job does not exist"
@@ -283,15 +285,51 @@ func (c *AzurePathFixController) sync() error {
283285
}
284286
}
285287

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
295333
}
296334

297335
_, _, err = v1helpers.UpdateStatus(

0 commit comments

Comments
 (0)