@@ -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
299242type 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.
410335func updateAccordingToSetters (ctx context.Context , path string , policies []imagev1alpha1_reflect.ImagePolicy ) error {
0 commit comments