Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/v1beta2/imageupdateautomation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const (
// inlined here.
type UpdateStrategy struct {
// Strategy names the strategy to be used.
// +required
// +optional
// +kubebuilder:default=Setters
Strategy UpdateStrategyName `json:"strategy"`
Strategy UpdateStrategyName `json:"strategy,omitempty"`

// Path to the directory containing the manifests to be updated.
// Defaults to 'None', which translates to the root path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,6 @@ spec:
enum:
- Setters
type: string
required:
- strategy
type: object
required:
- interval
Expand Down
1 change: 1 addition & 0 deletions docs/api/v1beta2/image-automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ UpdateStrategyName
</em>
</td>
<td>
<em>(Optional)</em>
<p>Strategy names the strategy to be used.</p>
</td>
</tr>
Expand Down
66 changes: 65 additions & 1 deletion internal/controller/imageupdateautomation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ func TestImageUpdateAutomationReconciler_e2e(t *testing.T) {
}
}

func TestImageUpdateAutomationReconciler_defaulting(t *testing.T) {
func TestImageUpdateAutomationReconciler_DefaultUpdate(t *testing.T) {
g := NewWithT(t)

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

func TestImageUpdateAutomationReconciler_DefaultStrategy(t *testing.T) {
g := NewWithT(t)

branch := rand.String(8)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

// Create a test namespace.
namespace, err := testEnv.CreateNamespace(ctx, "image-auto-test")
g.Expect(err).ToNot(HaveOccurred())
defer func() { g.Expect(testEnv.Delete(ctx, namespace)).To(Succeed()) }()

// Create an instance of ImageUpdateAutomation.
key := types.NamespacedName{
Name: "update-" + rand.String(5),
Namespace: namespace.Name,
}
auto := &imagev1.ImageUpdateAutomation{
ObjectMeta: metav1.ObjectMeta{
Name: key.Name,
Namespace: key.Namespace,
},
Spec: imagev1.ImageUpdateAutomationSpec{
SourceRef: imagev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Name: "garbage",
},
Interval: metav1.Duration{Duration: 2 * time.Hour},
GitSpec: &imagev1.GitSpec{
Checkout: &imagev1.GitCheckoutSpec{
Reference: sourcev1.GitRepositoryRef{
Branch: branch,
},
},
Commit: imagev1.CommitSpec{
Author: imagev1.CommitUser{
Email: testAuthorEmail,
},
MessageTemplate: "nothing",
},
},
Update: &imagev1.UpdateStrategy{
Path: "./test-path",
},
},
}
g.Expect(testEnv.Create(ctx, auto)).To(Succeed())
defer func() {
g.Expect(testEnv.Delete(ctx, auto)).To(Succeed())
}()

// Should default .spec.update to {strategy: Setters}.
var fetchedAuto imagev1.ImageUpdateAutomation
g.Eventually(func() bool {
err := testEnv.Get(ctx, key, &fetchedAuto)
return err == nil
}, timeout, time.Second).Should(BeTrue())
g.Expect(fetchedAuto.Spec.Update).
To(Equal(&imagev1.UpdateStrategy{
Strategy: imagev1.UpdateStrategySetters,
Path: "./test-path",
}))
}

func TestImageUpdateAutomationReconciler_notify(t *testing.T) {
g := NewWithT(t)
testPushResult, err := source.NewPushResult("branch", "rev", "test commit message")
Expand Down