Skip to content

Commit 8bc349d

Browse files
committed
Implement and test Suspend in controller
Signed-off-by: Michael Bridgen <[email protected]>
1 parent 5cac345 commit 8bc349d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

controllers/imageupdateautomation_controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
8787
return ctrl.Result{}, client.IgnoreNotFound(err)
8888
}
8989

90+
if auto.Spec.Suspend {
91+
msg := "ImageUpdateAutomation is suspended, skipping automation run"
92+
imagev1.SetImageUpdateAutomationReadiness(
93+
&auto,
94+
metav1.ConditionFalse,
95+
meta.SuspendedReason,
96+
msg,
97+
)
98+
if err := r.Status().Update(ctx, &auto); err != nil {
99+
return ctrl.Result{Requeue: true}, err
100+
}
101+
log.Info(msg)
102+
return ctrl.Result{}, nil
103+
}
104+
90105
// failWithError is a helper for bailing on the reconciliation.
91106
failWithError := func(err error) (ctrl.Result, error) {
92107
r.event(auto, events.EventSeverityError, err.Error())

controllers/update_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ import (
3636
. "github.com/onsi/gomega"
3737
"github.com/otiai10/copy"
3838
corev1 "k8s.io/api/core/v1"
39+
apimeta "k8s.io/apimachinery/pkg/api/meta"
3940
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4041
"k8s.io/apimachinery/pkg/types"
42+
"sigs.k8s.io/controller-runtime/pkg/client"
4143

4244
imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1alpha1"
45+
"github.com/fluxcd/pkg/apis/meta"
4346
"github.com/fluxcd/pkg/gittestserver"
4447
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
4548

@@ -273,6 +276,22 @@ var _ = Describe("ImageUpdateAutomation", func() {
273276
Expect(err).ToNot(HaveOccurred())
274277
test.ExpectMatchingDirectories(tmp, expected)
275278
})
279+
280+
It("stops updating when suspended", func() {
281+
// suspend it, and check that it is marked as unready.
282+
var updatePatch imagev1.ImageUpdateAutomation
283+
updatePatch.Name = updateKey.Name
284+
updatePatch.Namespace = updateKey.Namespace
285+
updatePatch.Spec.Suspend = true
286+
Expect(k8sClient.Patch(context.Background(), &updatePatch, client.Merge)).To(Succeed())
287+
Eventually(func() bool {
288+
if err := k8sClient.Get(context.Background(), updateKey, updateBySetters); err != nil {
289+
return false
290+
}
291+
ready := apimeta.FindStatusCondition(updateBySetters.Status.Conditions, meta.ReadyCondition)
292+
return ready != nil && ready.Status == metav1.ConditionFalse && ready.Reason == meta.SuspendedReason
293+
}, timeout, time.Second).Should(BeTrue())
294+
})
276295
})
277296
})
278297
})

0 commit comments

Comments
 (0)