Implement and test Suspend in controller
Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
parent
5cac345a43
commit
8bc349d4e2
|
@ -87,6 +87,21 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
|
|||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||
}
|
||||
|
||||
if auto.Spec.Suspend {
|
||||
msg := "ImageUpdateAutomation is suspended, skipping automation run"
|
||||
imagev1.SetImageUpdateAutomationReadiness(
|
||||
&auto,
|
||||
metav1.ConditionFalse,
|
||||
meta.SuspendedReason,
|
||||
msg,
|
||||
)
|
||||
if err := r.Status().Update(ctx, &auto); err != nil {
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
}
|
||||
log.Info(msg)
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
// failWithError is a helper for bailing on the reconciliation.
|
||||
failWithError := func(err error) (ctrl.Result, error) {
|
||||
r.event(auto, events.EventSeverityError, err.Error())
|
||||
|
|
|
@ -36,10 +36,13 @@ import (
|
|||
. "github.com/onsi/gomega"
|
||||
"github.com/otiai10/copy"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1alpha1"
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
"github.com/fluxcd/pkg/gittestserver"
|
||||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
|
||||
|
||||
|
@ -273,6 +276,22 @@ var _ = Describe("ImageUpdateAutomation", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
test.ExpectMatchingDirectories(tmp, expected)
|
||||
})
|
||||
|
||||
It("stops updating when suspended", func() {
|
||||
// suspend it, and check that it is marked as unready.
|
||||
var updatePatch imagev1.ImageUpdateAutomation
|
||||
updatePatch.Name = updateKey.Name
|
||||
updatePatch.Namespace = updateKey.Namespace
|
||||
updatePatch.Spec.Suspend = true
|
||||
Expect(k8sClient.Patch(context.Background(), &updatePatch, client.Merge)).To(Succeed())
|
||||
Eventually(func() bool {
|
||||
if err := k8sClient.Get(context.Background(), updateKey, updateBySetters); err != nil {
|
||||
return false
|
||||
}
|
||||
ready := apimeta.FindStatusCondition(updateBySetters.Status.Conditions, meta.ReadyCondition)
|
||||
return ready != nil && ready.Status == metav1.ConditionFalse && ready.Reason == meta.SuspendedReason
|
||||
}, timeout, time.Second).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue