Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
flavianmissi committed Nov 18, 2024
1 parent 50f1b20 commit 015ad4a
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions pkg/operator/azurepathfixcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metaapi "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
Expand Down Expand Up @@ -207,7 +208,8 @@ func (c *AzurePathFixController) sync() error {
}

jobObj, err := gen.Get()
if errors.IsNotFound(err) {
jobExists := !errors.IsNotFound(err)
if !jobExists {
progressingCondition.Status = operatorv1.ConditionTrue
progressingCondition.Reason = "NotFound"
progressingCondition.Message = "The job does not exist"
Expand Down Expand Up @@ -283,15 +285,45 @@ func (c *AzurePathFixController) sync() error {
}
}

err = resource.ApplyMutator(gen)
if err != nil {
_, _, updateError := v1helpers.UpdateStatus(
ctx,
c.operatorClient,
v1helpers.UpdateConditionFn(progressingCondition),
v1helpers.UpdateConditionFn(degradedCondition),
)
return utilerrors.NewAggregate([]error{err, updateError})
switch imageRegistryConfig.Spec.ManagementState {
case operatorv1.Removed:
progressingCondition.Reason = "Removed"
progressingCondition.Message = "The job is removed"
progressingCondition.Status = operatorv1.ConditionFalse
degradedCondition.Reason = "Removed"
degradedCondition.Message = "The job is removed"
degradedCondition.Status = operatorv1.ConditionFalse

if jobExists {
gracePeriod := int64(0)
propagationPolicy := metaapi.DeletePropagationForeground
opts := metaapi.DeleteOptions{
GracePeriodSeconds: &gracePeriod,
PropagationPolicy: &propagationPolicy,
}
if err := gen.Delete(opts); err != nil {
// TODO: set condition?
// TODO: aggregate error and don't return?
return err
}
progressingCondition.Reason = "Removing"
progressingCondition.Status = operatorv1.ConditionTrue
degradedCondition.Reason = "Removing"
degradedCondition.Status = operatorv1.ConditionFalse
}
case operatorv1.Managed:
err = resource.ApplyMutator(gen)
if err != nil {
_, _, updateError := v1helpers.UpdateStatus(
ctx,
c.operatorClient,
v1helpers.UpdateConditionFn(progressingCondition),
v1helpers.UpdateConditionFn(degradedCondition),
)
return utilerrors.NewAggregate([]error{err, updateError})
}
case operatorv1.Unmanaged:
// ignore
}

_, _, err = v1helpers.UpdateStatus(
Expand Down

0 comments on commit 015ad4a

Please sign in to comment.