Skip to content

Why ImagePolicy immediately trigger IA to commit update? #313

Closed

Description

@lictw

Hi!

For what there are .Interval in IA CRD? I want to implement more batched update. In my logic ImageRepository (IR) scanning with interval and provides image list, ImagePolicy (IP) selects, then IA with interval push all changes, but my setup where IR.Interval eq. 1m and IA.Interval eq. 15m pushes update immediately after the related IP selects new image even if IA already starts ~1 minute ago.

image

Activity

  1. changed the title [-]Why ImagePolicy immediately trigger IA to commit update[/-] [+]Why ImagePolicy immediately trigger IA to commit update?[/+] on Feb 10, 2022
  2. Wuzyn commented on Feb 18, 2022

    @Wuzyn

    I have the same problem and it's causing my helm upgrades to overlap, which is obviously causing problems :/

  3. stefanprodan commented on Feb 18, 2022

    @stefanprodan
    Member

    You can bundle multiple updates by telling IAC to create a branch. Then it's in your power to decide when to merge the changes to the branch synced by Flux.

    Docs here: https://fluxcd.io/docs/guides/image-update/#push-updates-to-a-different-branch

  4. Wuzyn commented on Feb 18, 2022

    @Wuzyn

    Well, that kind of defeats the purpose of having it in a first place if I have to manually check PR and merge it. Any chance we can get a feature request for batch update? On my setup, I noticed that it sometimes commits few images instead of one. Why is that?
    Screenshot 2022-02-18 at 13 01 10

  5. stefanprodan commented on Feb 18, 2022

    @stefanprodan
    Member

    IAC reacts to events sent by the ImageRepository objects, if by chance the scanning happens in parallel for multiple repos and all of them have updates, those will be included in the same commit.

  6. Wuzyn commented on Feb 18, 2022

    @Wuzyn

    I have 7 ImageRepository objects defined, each of them having interval set to 1m. My IAC have interval set to 10m. So that means IAC is ignoring it's interval property?

    If I had ImageRepository interval set to 1h with IAC set to 10m would IAC trigger repository scanning every 10 minutes?

  7. stefanprodan commented on Feb 18, 2022

    @stefanprodan
    Member

    So that means IAC is ignoring it's interval property?

    Yes, all Flux controllers do this, the interval is there in case Kubernetes API goes down while an ImageRepository event is issued.

    If I had ImageRepository interval set to 1h with IAC set to 10m would IAC trigger repository scanning every 10 minutes?

    No it's the other way around, IAC reacts to ImageRepository pulling new tags.

  8. Wuzyn commented on Feb 22, 2022

    @Wuzyn

    @stefanprodan Is HelmRelease behaves the same way? Once it gets image update, it runs helm upgrade ignoring the interval?

  9. stefanprodan commented on Feb 22, 2022

    @stefanprodan
    Member

    Yes, any change event triggers a reconciliation outside the interval, no matter the Flux object.

  10. lictw commented on Feb 22, 2022

    @lictw
    Author

    Okay, I understand how KS/HR works and what is reconcile (sync) interval. But this logic seems strange to me for IR/IP/IA..

    From docs: (https://fluxcd.io/docs/components/image/imageupdateautomations/)
    The ImageUpdateAutomation type defines an automation process that will update a git repository, based on image policy objects in the same namespace.

    And will be nice if IA updates repository based on IP, not IP triggers IA. I don't see any advantages in the current approach, you can describe it, it's interesting, but in my situation, for big, unicorn chart, where 20+ policies relate single automation and CI performs parallel builds for many apps, i see how single update iteration stretch into multiply commits/updates and it's overlap.

    I already inderstand that it's by design and you can close issue if everything works as it should. Sorry for my English, i hope my main minds are clean!

  11. Wuzyn commented on Feb 24, 2022

    @Wuzyn

    This is what I did as a workaround:

    • set bigger intervals in ImageRepository objects. I set it to 720h
    • create flux webhook to trigger all ImageRepository reconciliation, this webhook is pinged by my CI, after all images have been built. This is causing all image updates to be in one commit
    • additionally, I put my helm release values to config map. It causes every change to helm release be deployed during interval reconcilation

    ConfigMap and Secret values overrides. Changes to these do not trigger an immediate reconciliation, but will be handled upon the next reconciliation. This is to avoid a large number of upgrades occurring when multiple resources are updated.

    https://fluxcd.io/docs/components/helm/helmreleases/#reconciliation

  12. lictw commented on Mar 1, 2022

    @lictw
    Author

    In general it very complicated in my case (builds come not from single repo), but i did not know about configMap behav., thanks for this! Okay, it will be 5 commits in 3 minutes, but it will be single reconcilation every 5 minutes for example. It's really what i want!

  13. lictw commented on Mar 9, 2022

    @lictw
    Author

    additionally, I put my helm release values to config map.

    Via kustomize configmap generator ofk? Image Update Automation wants YAML structure to change images.

  14. kingdonb commented on Mar 25, 2022

    @kingdonb
    Member

    additionally, I put my helm release values to config map. It causes every change to help release be deployed during interval reconcilation

    Via kustomize configmap generator ofk? Image Update Automation wants YAML structure to change images.

    @lictw No, this is a clever workaround. Using the kustomize configmap generator strategy ensures that every change to the configmap gets applied right away, because the configmap has a name with hash suffix, and the hash changes every time the content changes (and so does the HelmRelease, because configmap generator is shown with nameReference.fieldSpecs configuration in the example that you referenced.)

    This approach works for the intended purpose as @Wuzyn describes precisely because it does not take any hash or update right away. It must wait around for the interval, and not reconcile immediately on every change. HelmRelease does not have any subscription to the ConfigMap that it lists in valuesFrom, it only knows to update whenever its spec changes, when it is notified by a source that has changed, or when it is reconciled after any input changed (either manually reconciled or due to the interval expiration).

  15. lictw commented on Apr 18, 2022

    @lictw
    Author

    @kingdonb I didn't fully understand your idea.. Cause of IUA wants to deal with yaml files, I didn't see way other than configmapGenerator, so I did it with generatorOption.disableNameSuffixHash and it's work fine.

    About every change to the configmap gets applied right away, because the configmap has a name with hash suffix:
    How? I can't apply this schema, my kustomize don't apply hash at configmap's name referenced in HelmRelease, I tried to achieve this in other task, what's wrong?

    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    resources:
    - release.yaml
    configMapGenerator:
    - name: config
      files:
      - config.yaml
    ....................................
    $ kustomize build .
    apiVersion: v1
    data:
      config.yaml: |
        foo: bar
    kind: ConfigMap
    metadata:
      name: config-8f8ccm888f
    ---
    apiVersion: helm.toolkit.fluxcd.io/v2beta1
    kind: HelmRelease
    metadata:
      name: test
    spec:
      values:
        existingConfigmap: config
      valuesFrom:
      - kind: ConfigMap
        name: config
    
  16. kingdonb commented on Apr 25, 2022

    @kingdonb
    Member

    The example linked provides this snippet:

    nameReference:
    - kind: ConfigMap
      version: v1
      fieldSpecs:
      - path: spec/valuesFrom/name
        kind: HelmRelease
    

    In this case, spec/valuesFrom/name is the path in the HelmRelease which Kustomize searches for values of secret (or configmap) names that are matching the secret (or cm) generator, so that Kustomize can substitute the generated name with the hash suffix there. That's what it looks like you're missing, you need to add:

    configurations:
      - kustomizeconfig.yaml
    

    or whatever name you prefer for this Kustomize config file, and then Kustomize will make the substitutions whenever the secret/cm has changed in the generator.

  17. Spittal commented on Jun 25, 2024

    @Spittal

    Hey, I understand that ImageAutomationController reacting to ImageRepository and the subsequent ImagePolicy updates is desired behaviour but I wish there was a 'window' to capture changes.

    For example we have 4 ImageRepository objects with corresponding ImagePolicy and they update ~10 seconds of each other. Sometimes we get lucky and a single ImageAutomationController commit will contain multiple image updates, but often we get a separate commit per ImagePolicy update. This ends up being noise in our commit history, and is something I wish we had more control over.

    A solution could be that on the ImageAutomationController.spec there could exist a window parameter that will wait a certain amount of time after a reconciliation was triggered to 'collect' any more ImagePolicy updates that might be coming before committing to the repo.

  18. makkes commented on Jun 26, 2024

    @makkes
    Member

    @Spittal One way to mitigate having multiple commits in your history is to let IAC push to a specific branch and automatically create a PR (or MR in GitLab terms) from that branch. Then you can squash the commits before merging.

  19. kingdonb commented on Jun 26, 2024

    @kingdonb
    Member

    A challenge to implement a wait is that maybe the images usually arrive within 10s of each other, but maybe it's sometimes a bit longer. How do you decide the timeout? The longer you make it, the longer people perceive that it takes for IUA to do its job.

    Pull requests that get merged at a point in time are a good solution for this. You wait until you see all the necessary changes, then merge it. With squash merges you won't necessarily even be able to tell they weren't one commit.

    It could still be a nice feature but it sounds like a hack. If another image comes in, do you reset the timeout or keep counting? If people set the timeout too long and have too many imageupdateautomations, it will hang the controller. They will have to increase the concurrency and things will generally take longer.

    What you're looking for is probably better served by a tool like Kargo (Christian Hernandez presented this at Bug Scrub last week and the week before!)

    It can work with Flux!

  20. Spittal commented on Jun 26, 2024

    @Spittal

    It could still be a nice feature, but it sounds like a hack.

    Yeah, it certainly has that feeling. We spoke internally at length about this because the only "downside" we identified with the current Flux behavior is that it's creating multiple commits, which feels unintuitive. However, when our images inevitably diverge in the speed of building, then an IAC window feature becomes a moving target like you described above.

    Furthermore, another way to look at this is that Flux is attempting to update as fast as possible, and that's something we actually want in our deployments.

    I think something that would've been really helpful for us to come to that conclusion earlier would be a mention in all interval docs that describes this.

    Yes, any change event triggers a reconciliation outside the interval, no matter the Flux object.

    If that's something that you'd be interested in I can take a swing at a PR for this doc change BTW.

    Thanks for the quick replies!

    P.S. Thanks for the Kargo recommendation. We have seen this floating around but haven't dug into it. Looking forward to taking a look!

  21. fhoekstra commented on Sep 4, 2026

    @fhoekstra

    We have the same situation and desire as Spittal describes above: we reconcile new images in staging via ImageUpdateAutomation, and many images are built/pushed within seconds of each other, cluttering up our git log with image update commits.

    We don't mind waiting a few minutes when a new image is pushed, to have a cleaner commit log.

    Furthermore, another way to look at this is that Flux is attempting to update as fast as possible, and that's something we actually want in our deployments.

    For us, it's a trade-off in commit log spam in our monorepo vs speed. That's why batching should be opt-in.

    I envision adding a spec.batching field with spec.batching.enabled, spec.batching.window and any future additions (batching strategy?) could go under spec.batching too if desired? Alternatively, just a spec.batchingWindow that is null by default.

    If another image comes in, do you reset the timeout or keep counting? If people set the timeout too long and have too many imageupdateautomations, it will hang the controller. They will have to increase the concurrency and things will generally take longer.

    Thanks for raising this! I see 3 possible ways to do batching:

    1. reset on new pushes: bad, could hang indefinitely
    2. keep counting: requires a stateful component (status field?) to keep track of when the window started. Introduces significant complexity
    3. throttling: this seems like the easiest way to implement: 2 subsequent updates will still cause 2 commits, but if you have significantly more than 2 imagerepositories, this will limit the git log spam by throttling. Furthermore, it may not require any additional stateful component: we can just throttle based on lastPushTime.

    the third way seems sensible, if this is going to be implemented at all, as this is clearly not a very hot topic (it's been quiet on this issue for 2 years), and that way introduces the least complexity and maintenance burden to the project.

    Would you be open to further discussion or a PR for this?

  22. matheuscscp commented on Sep 4, 2026

    @matheuscscp
    Member

    There's no way for a Reconcile() to know what triggered it: an ImagePolicy watch event or the interval.

    If you need time-based image automation I recommend using Flux Operator's ResourceSet:

    https://fluxoperator.dev/docs/resourcesets/time-based-delivery/

  23. fhoekstra commented on Sep 9, 2026

    @fhoekstra

    Thanks for your pointer @matheuscscp : ResourceSets are not just useful for time-based automation, but also simply keeping things in sync with an OCI registry without requiring commits to the GitOps repo.

    We have set up something like the following, where we:

    • Generate a FluxCD Kustomization with an images: block from a generic ResourceSet (essentially a template)
    • Use a ResourceSetInputProvider for each app, which points to a specific image and tag

    This ensures each app is continuously updated with a new digest as new images get pushed to that tag, without anything getting automatically committed to Git by Flux.

    Of course, we could also add a cron to the ResourceSet to limit when or how often it updates, but we find we just wanted to reduce the number of automated commits in our Git log, not actually slow down the sync.

    It looks something like this:

    ---
    # yaml-language-server: $schema=https://github.com/datreeio/CRDs-catalog/raw/refs/heads/main/fluxcd.controlplane.io/resourceset_v1.json
    apiVersion: fluxcd.controlplane.io/v1
    kind: ResourceSet
    metadata:
      name: company-name-image-sync
      namespace: flux-system
      annotations:
        fluxcd.controlplane.io/reconcileTimeout: "5m"
    spec:
      inputsFrom:
        - kind: ResourceSetInputProvider
          selector:
            matchLabels:
              company-name.eu/component: image-sync
      resources:
        - apiVersion: kustomize.toolkit.fluxcd.io/v1
          kind: Kustomization
          metadata:
            name: << inputs.app >>
            namespace: flux-system
          spec:
            path: << inputs.path | quote >>
            prune: true
            wait: true
            interval: 10m
            sourceRef:
              kind: GitRepository
              name: flux-system
            images:
              - name: << inputs.image >>
                newTag: << inputs.tag | quote >>
                digest: << inputs.digest | quote >>
    ---
    # yaml-language-server: $schema=https://github.com/datreeio/CRDs-catalog/raw/refs/heads/main/fluxcd.controlplane.io/resourcesetinputprovider_v1.json
    apiVersion: fluxcd.controlplane.io/v1
    kind: ResourceSetInputProvider
    metadata:
      name: my-specific-app-images
      namespace: flux-system
      labels:
        company-name.eu/component: image-sync
      annotations:
        fluxcd.controlplane.io/reconcileEvery: "5m"
        fluxcd.controlplane.io/reconcileTimeout: "1m"
    spec:
      type: OCIArtifactTag
      url: oci://company-name.registry-name.eu/my-specific-app
      filter:
        includeTag: "^develop-latest$"
        limit: 1
      defaultValues:
        app: my-specific-app
        image: company-name.registry-name.eu/my-specific-app
        path: ./path/to/my-specific-app/manifests
    ---
    # yaml-language-server: $schema=https://github.com/datreeio/CRDs-catalog/raw/refs/heads/main/fluxcd.controlplane.io/resourcesetinputprovider_v1.json
    apiVersion: fluxcd.controlplane.io/v1
    kind: ResourceSetInputProvider
    metadata:
      name: my-other-app-images
      namespace: flux-system
      labels:
        company-name.eu/component: image-sync
      annotations:
        fluxcd.controlplane.io/reconcileEvery: "5m"
        fluxcd.controlplane.io/reconcileTimeout: "1m"
    spec:
      type: OCIArtifactTag
      url: oci://company-name.registry-name.eu/my-other-app
      filter:
        includeTag: "^develop-latest$"
        limit: 1
      defaultValues:
        app: my-other-app
        image: company-name.registry-name.eu/my-other-app
        path: ./path/to/my-other-app/manifests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions