Skip to content

Commit fb26178

Browse files
authored
Merge pull request #27 from fluxcd/remove-poc-mode
Remove proof-of-concept update mode
2 parents 7318ecb + da2f23c commit fb26178

File tree

7 files changed

+0
-303
lines changed

7 files changed

+0
-303
lines changed

api/v1alpha1/imageupdateautomation_types.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222
)
2323

24-
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25-
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26-
2724
// ImageUpdateAutomationSpec defines the desired state of ImageUpdateAutomation
2825
type ImageUpdateAutomationSpec struct {
2926
// Checkout gives the parameters for cloning the git repository,
@@ -58,10 +55,6 @@ type GitCheckoutSpec struct {
5855
// UpdateStrategy is a union of the various strategies for updating
5956
// the git repository.
6057
type UpdateStrategy struct {
61-
// ImagePolicyRef if present means update all workloads using the
62-
// given policy's image, to the policy's latest image reference.
63-
// +optional
64-
ImagePolicyRef *corev1.LocalObjectReference `json:"imagePolicyRef,omitempty"`
6558
// Setters if present means update workloads using setters, via
6659
// fields marked in the files themselves.
6760
// +optional

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ spec:
9090
description: Update gives the specification for how to update the files
9191
in the repository
9292
properties:
93-
imagePolicyRef:
94-
description: ImagePolicyRef if present means update all workloads
95-
using the given policy's image, to the policy's latest image reference.
96-
properties:
97-
name:
98-
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
99-
TODO: Add other useful fields. apiVersion, kind, uid?'
100-
type: string
101-
type: object
10293
setters:
10394
description: Setters if present means update workloads using setters,
10495
via fields marked in the files themselves.

controllers/imageupdateautomation_controller.go

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,6 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
121121

122122
updateStrat := auto.Spec.Update
123123
switch {
124-
case updateStrat.ImagePolicyRef != nil:
125-
var policy imagev1alpha1_reflect.ImagePolicy
126-
policyName := types.NamespacedName{
127-
Namespace: auto.GetNamespace(),
128-
Name: updateStrat.ImagePolicyRef.Name,
129-
}
130-
if err := r.Get(ctx, policyName, &policy); err != nil {
131-
if client.IgnoreNotFound(err) == nil {
132-
log.Info("referenced ImagePolicy not found")
133-
// assume we'll be told if the image policy turns up, or if this resource changes
134-
return ctrl.Result{}, nil
135-
}
136-
return ctrl.Result{}, err
137-
}
138-
if err := updateAccordingToImagePolicy(ctx, tmp, &policy); err != nil {
139-
if err == errImagePolicyNotReady {
140-
log.Info("image policy does not have latest image ref", "imagepolicy", policyName)
141-
// assume we'll be told if the image policy or this resource changes
142-
return ctrl.Result{}, nil
143-
}
144-
return ctrl.Result{}, err
145-
}
146124
case updateStrat.Setters != nil:
147125
// For setters we first want to compile a list of _all_ the
148126
// policies in the same namespace (maybe in the future this
@@ -211,27 +189,12 @@ func (r *ImageUpdateAutomationReconciler) SetupWithManager(mgr ctrl.Manager) err
211189
return err
212190
}
213191

214-
// Index the image policy (if any) that each I-U-A refers to
215-
if err := mgr.GetFieldIndexer().IndexField(ctx, &imagev1alpha1.ImageUpdateAutomation{}, imagePolicyKey, func(obj runtime.Object) []string {
216-
updater := obj.(*imagev1alpha1.ImageUpdateAutomation)
217-
if ref := updater.Spec.Update.ImagePolicyRef; ref != nil {
218-
return []string{ref.Name}
219-
}
220-
return nil
221-
}); err != nil {
222-
return err
223-
}
224-
225192
return ctrl.NewControllerManagedBy(mgr).
226193
For(&imagev1alpha1.ImageUpdateAutomation{}).
227194
Watches(&source.Kind{Type: &sourcev1alpha1.GitRepository{}},
228195
&handler.EnqueueRequestsFromMapFunc{
229196
ToRequests: handler.ToRequestsFunc(r.automationsForGitRepo),
230197
}).
231-
Watches(&source.Kind{Type: &imagev1alpha1_reflect.ImagePolicy{}},
232-
&handler.EnqueueRequestsFromMapFunc{
233-
ToRequests: handler.ToRequestsFunc(r.automationsForImagePolicy),
234-
}).
235198
Complete(r)
236199
}
237200

@@ -274,26 +237,6 @@ func (r *ImageUpdateAutomationReconciler) automationsForGitRepo(obj handler.MapO
274237
return reqs
275238
}
276239

277-
// automationsForImagePolicy fetches all the automations that refer to
278-
// a particular source.ImagePolicy object.
279-
func (r *ImageUpdateAutomationReconciler) automationsForImagePolicy(obj handler.MapObject) []reconcile.Request {
280-
ctx := context.Background()
281-
var autoList imagev1alpha1.ImageUpdateAutomationList
282-
if err := r.List(ctx, &autoList, client.InNamespace(obj.Meta.GetNamespace()), client.MatchingFields{imagePolicyKey: obj.Meta.GetName()}); err != nil {
283-
r.Log.Error(err, "failed to list ImageUpdateAutomations for ImagePolicy", "name", types.NamespacedName{
284-
Name: obj.Meta.GetName(),
285-
Namespace: obj.Meta.GetNamespace(),
286-
})
287-
return nil
288-
}
289-
reqs := make([]reconcile.Request, len(autoList.Items), len(autoList.Items))
290-
for i := range autoList.Items {
291-
reqs[i].NamespacedName.Name = autoList.Items[i].GetName()
292-
reqs[i].NamespacedName.Namespace = autoList.Items[i].GetNamespace()
293-
}
294-
return reqs
295-
}
296-
297240
// --- git ops
298241

299242
type repoAccess struct {
@@ -387,24 +330,6 @@ func commitAllAndPush(ctx context.Context, repo *gogit.Repository, access repoAc
387330

388331
// --- updates
389332

390-
var errImagePolicyNotReady = errors.New("ImagePolicy resource is not ready")
391-
392-
// update the manifest files under path according to policy, by
393-
// replacing any mention of the policy's image repository with the
394-
// latest ref.
395-
func updateAccordingToImagePolicy(ctx context.Context, path string, policy *imagev1alpha1_reflect.ImagePolicy) error {
396-
// the function that does the update expects an original and a
397-
// replacement; but it only uses the repository part of the
398-
// original, and it compares canonical forms (with the defaults
399-
// filled in). Since the latest image will have the same
400-
// repository, I can just pass that as the original.
401-
latestRef := policy.Status.LatestImage
402-
if latestRef == "" {
403-
return errImagePolicyNotReady
404-
}
405-
return update.UpdateImageEverywhere(path, path, latestRef, latestRef)
406-
}
407-
408333
// updateAccordingToSetters updates files under the root by treating
409334
// the given image policies as kyaml setters.
410335
func updateAccordingToSetters(ctx context.Context, path string, policies []imagev1alpha1_reflect.ImagePolicy) error {

controllers/update_test.go

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -174,95 +174,6 @@ var _ = Describe("ImageUpdateAutomation", func() {
174174
Expect(k8sClient.Delete(context.Background(), policy)).To(Succeed())
175175
})
176176

177-
Context("with ImagePolicyRef strategy", func() {
178-
179-
var (
180-
updateKey types.NamespacedName
181-
updateByImagePolicy *imagev1alpha1.ImageUpdateAutomation
182-
)
183-
184-
BeforeEach(func() {
185-
updateKey = types.NamespacedName{
186-
Namespace: gitRepoKey.Namespace,
187-
Name: "update-" + randStringRunes(5),
188-
}
189-
updateByImagePolicy = &imagev1alpha1.ImageUpdateAutomation{
190-
ObjectMeta: metav1.ObjectMeta{
191-
Name: updateKey.Name,
192-
Namespace: updateKey.Namespace,
193-
},
194-
Spec: imagev1alpha1.ImageUpdateAutomationSpec{
195-
Checkout: imagev1alpha1.GitCheckoutSpec{
196-
GitRepositoryRef: corev1.LocalObjectReference{
197-
Name: gitRepoKey.Name,
198-
},
199-
Branch: defaultBranch,
200-
},
201-
Update: imagev1alpha1.UpdateStrategy{
202-
ImagePolicyRef: &corev1.LocalObjectReference{
203-
Name: policyKey.Name,
204-
},
205-
},
206-
Commit: imagev1alpha1.CommitSpec{
207-
MessageTemplate: commitMessage,
208-
},
209-
},
210-
}
211-
Expect(k8sClient.Create(context.Background(), updateByImagePolicy)).To(Succeed())
212-
waitForNewHead(localRepo)
213-
})
214-
215-
AfterEach(func() {
216-
Expect(k8sClient.Delete(context.Background(), updateByImagePolicy)).To(Succeed())
217-
})
218-
219-
It("updates to the most recent image", func() {
220-
// having passed the BeforeEach, we should see a commit
221-
head, _ := localRepo.Head()
222-
commit, err := localRepo.CommitObject(head.Hash())
223-
Expect(err).ToNot(HaveOccurred())
224-
Expect(commit.Message).To(Equal(commitMessage))
225-
226-
tmp, err := ioutil.TempDir("", "gotest-imageauto")
227-
Expect(err).ToNot(HaveOccurred())
228-
defer os.RemoveAll(tmp)
229-
230-
_, err = git.PlainClone(tmp, false, &git.CloneOptions{
231-
URL: repoURL,
232-
ReferenceName: plumbing.NewBranchReferenceName(defaultBranch),
233-
})
234-
Expect(err).ToNot(HaveOccurred())
235-
test.ExpectMatchingDirectories(tmp, "testdata/appconfig-expected")
236-
})
237-
238-
It("makes a commit when the policy changes", func() {
239-
// make sure the first commit happened
240-
head, _ := localRepo.Head()
241-
commit, err := localRepo.CommitObject(head.Hash())
242-
Expect(err).ToNot(HaveOccurred())
243-
Expect(commit.Message).To(Equal(commitMessage))
244-
245-
// change the status and
246-
// make sure there's a commit for that.
247-
policy.Status.LatestImage = evenLatestImage
248-
Expect(k8sClient.Status().Update(context.Background(), policy)).To(Succeed())
249-
250-
Expect(err).ToNot(HaveOccurred())
251-
waitForNewHead(localRepo)
252-
253-
tmp, err := ioutil.TempDir("", "gotest-imageauto")
254-
Expect(err).ToNot(HaveOccurred())
255-
defer os.RemoveAll(tmp)
256-
257-
_, err = git.PlainClone(tmp, false, &git.CloneOptions{
258-
URL: repoURL,
259-
ReferenceName: plumbing.NewBranchReferenceName(defaultBranch),
260-
})
261-
Expect(err).ToNot(HaveOccurred())
262-
test.ExpectMatchingDirectories(tmp, "testdata/appconfig-expected2")
263-
})
264-
})
265-
266177
Context("with Setters", func() {
267178

268179
var (

pkg/update/imagepolicy.go

Lines changed: 0 additions & 91 deletions
This file was deleted.

pkg/update/update_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,6 @@ func TestUpdate(t *testing.T) {
1818
RunSpecs(t, "Update suite")
1919
}
2020

21-
var _ = Describe("Update image everywhere from policy", func() {
22-
It("leaves a different image alone", func() {
23-
tmp, err := ioutil.TempDir("", "gotest")
24-
Expect(err).ToNot(HaveOccurred())
25-
defer os.RemoveAll(tmp)
26-
Expect(UpdateImageEverywhere("testdata/leave/original", tmp, "notused", "notused:v1.0.1")).To(Succeed())
27-
test.ExpectMatchingDirectories(tmp, "testdata/leave/expected")
28-
})
29-
30-
It("replaces the given image", func() {
31-
tmp, err := ioutil.TempDir("", "gotest")
32-
Expect(err).ToNot(HaveOccurred())
33-
defer os.RemoveAll(tmp)
34-
Expect(UpdateImageEverywhere("testdata/replace/original", tmp, "used", "used:v1.1.0")).To(Succeed())
35-
test.ExpectMatchingDirectories(tmp, "testdata/replace/expected")
36-
})
37-
38-
It("keeps comments intact", func() {
39-
tmp, err := ioutil.TempDir("", "gotest")
40-
Expect(err).ToNot(HaveOccurred())
41-
defer os.RemoveAll(tmp)
42-
Expect(UpdateImageEverywhere("testdata/replace/commented", tmp, "used", "used:v1.1.0")).To(Succeed())
43-
test.ExpectMatchingDirectories(tmp, "testdata/replace/commented-expected")
44-
})
45-
})
46-
4721
var _ = Describe("Update image via kyaml setters2", func() {
4822
It("updates the image marked with the image policy (setter) ref", func() {
4923
tmp, err := ioutil.TempDir("", "gotest")

0 commit comments

Comments
 (0)