Skip to content

Commit 03080ba

Browse files
authored
Merge pull request #942 from fluxcd/fix-strategy-validation
Make `.spec.update.strategy` optional
2 parents 8939b7b + b81e735 commit 03080ba

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

api/v1beta2/imageupdateautomation_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ const (
8383
// inlined here.
8484
type UpdateStrategy struct {
8585
// Strategy names the strategy to be used.
86-
// +required
86+
// +optional
8787
// +kubebuilder:default=Setters
88-
Strategy UpdateStrategyName `json:"strategy"`
88+
Strategy UpdateStrategyName `json:"strategy,omitempty"`
8989

9090
// Path to the directory containing the manifests to be updated.
9191
// Defaults to 'None', which translates to the root path

config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,6 @@ spec:
608608
enum:
609609
- Setters
610610
type: string
611-
required:
612-
- strategy
613611
type: object
614612
required:
615613
- interval

docs/api/v1beta2/image-automation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ UpdateStrategyName
874874
</em>
875875
</td>
876876
<td>
877+
<em>(Optional)</em>
877878
<p>Strategy names the strategy to be used.</p>
878879
</td>
879880
</tr>

internal/controller/imageupdateautomation_controller_test.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ func TestImageUpdateAutomationReconciler_e2e(t *testing.T) {
14091409
}
14101410
}
14111411

1412-
func TestImageUpdateAutomationReconciler_defaulting(t *testing.T) {
1412+
func TestImageUpdateAutomationReconciler_DefaultUpdate(t *testing.T) {
14131413
g := NewWithT(t)
14141414

14151415
branch := rand.String(8)
@@ -1468,6 +1468,70 @@ func TestImageUpdateAutomationReconciler_defaulting(t *testing.T) {
14681468
To(Equal(&imagev1.UpdateStrategy{Strategy: imagev1.UpdateStrategySetters}))
14691469
}
14701470

1471+
func TestImageUpdateAutomationReconciler_DefaultStrategy(t *testing.T) {
1472+
g := NewWithT(t)
1473+
1474+
branch := rand.String(8)
1475+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
1476+
defer cancel()
1477+
1478+
// Create a test namespace.
1479+
namespace, err := testEnv.CreateNamespace(ctx, "image-auto-test")
1480+
g.Expect(err).ToNot(HaveOccurred())
1481+
defer func() { g.Expect(testEnv.Delete(ctx, namespace)).To(Succeed()) }()
1482+
1483+
// Create an instance of ImageUpdateAutomation.
1484+
key := types.NamespacedName{
1485+
Name: "update-" + rand.String(5),
1486+
Namespace: namespace.Name,
1487+
}
1488+
auto := &imagev1.ImageUpdateAutomation{
1489+
ObjectMeta: metav1.ObjectMeta{
1490+
Name: key.Name,
1491+
Namespace: key.Namespace,
1492+
},
1493+
Spec: imagev1.ImageUpdateAutomationSpec{
1494+
SourceRef: imagev1.CrossNamespaceSourceReference{
1495+
Kind: "GitRepository",
1496+
Name: "garbage",
1497+
},
1498+
Interval: metav1.Duration{Duration: 2 * time.Hour},
1499+
GitSpec: &imagev1.GitSpec{
1500+
Checkout: &imagev1.GitCheckoutSpec{
1501+
Reference: sourcev1.GitRepositoryRef{
1502+
Branch: branch,
1503+
},
1504+
},
1505+
Commit: imagev1.CommitSpec{
1506+
Author: imagev1.CommitUser{
1507+
Email: testAuthorEmail,
1508+
},
1509+
MessageTemplate: "nothing",
1510+
},
1511+
},
1512+
Update: &imagev1.UpdateStrategy{
1513+
Path: "./test-path",
1514+
},
1515+
},
1516+
}
1517+
g.Expect(testEnv.Create(ctx, auto)).To(Succeed())
1518+
defer func() {
1519+
g.Expect(testEnv.Delete(ctx, auto)).To(Succeed())
1520+
}()
1521+
1522+
// Should default .spec.update to {strategy: Setters}.
1523+
var fetchedAuto imagev1.ImageUpdateAutomation
1524+
g.Eventually(func() bool {
1525+
err := testEnv.Get(ctx, key, &fetchedAuto)
1526+
return err == nil
1527+
}, timeout, time.Second).Should(BeTrue())
1528+
g.Expect(fetchedAuto.Spec.Update).
1529+
To(Equal(&imagev1.UpdateStrategy{
1530+
Strategy: imagev1.UpdateStrategySetters,
1531+
Path: "./test-path",
1532+
}))
1533+
}
1534+
14711535
func TestImageUpdateAutomationReconciler_notify(t *testing.T) {
14721536
g := NewWithT(t)
14731537
testPushResult, err := source.NewPushResult("branch", "rev", "test commit message")

0 commit comments

Comments
 (0)