fluxcd / flux2

Open and extensible continuous delivery solution for Kubernetes. Powered by GitOps Toolkit.
https://fluxcd.io
Apache License 2.0
6.56k stars 607 forks source link

imageupdate automation rewrites a `items: []` manifest on a weird location #5064

Open srgvg opened 1 week ago

srgvg commented 1 week ago

Describe the bug

Incidently bumped into this; not sure or just a bug, or partlly a feature. We got kustomization directory containing amongst others 1 yaml file:

apiVersion: v1
items:
- apiVersion: apps/v1
  kind: Deployment
    (...)
- apiVersion: v1
  kind: Service
    name: web-api
    (...)
kind: List

located at clusters/cosmorak/applications/buut/web-api/webapi.yaml in the git repo Next to that an imageupdateautomation:

apiVersion: image.toolkit.fluxcd.io/v1beta2
kind: ImageUpdateAutomation
metadata:
  name: web-api-update-automation
  namespace: flux-system  # The namespace where Flux resources reside
spec:
  interval: 1m0s  # Check every 1 minute for image updates
  sourceRef:
    kind: GitRepository
    name: flux-system  # The name of the GitRepository resource (from kubectl output)
    namespace: flux-system  # The namespace of the GitRepository resource
  git:
    checkout:
      ref:
        branch: main  # The branch of your repository to track ops repo changes
    commit:
      author:
       (...)
     messageTemplate: 'update image to {{range .Updated.Images}}{{println .}}{{end}}'
    push:
      branch: main  # Push changes to the main branch of the ops repo
  update:
    path: ./clusters/cosmorak 
    strategy: Setters  # Automatically update the image tag in your manifest

What then happens, is the weird part: there's a tag to update in the a forementioned deployment, but instead of just updating it in the file clusters/cosmorak/applications/buut/web-api/webapi.yaml, the controller creates two new files at another location:

Steps to reproduce

flux version v2.4.0

Expected behavior

flux updates the original file clusters/cosmorak/buut/service_web-api.yaml and does not create new files on an unexpected location

Screenshots and recordings

No response

OS / Distro

Ubuntu 24.04

Flux version

flux version flux: v2.4.0 distribution: flux-v2.4.0 helm-controller: v1.1.0 image-automation-controller: v0.39.0 image-reflector-controller: v0.33.0 kustomize-controller: v1.4.0 notification-controller: v1.4.0 source-controller: v1.4.1

Flux check

└➞ flux check ► checking prerequisites ✔ Kubernetes 1.30.5+k3s1 >=1.28.0-0 ► checking version in cluster ✔ distribution: flux-v2.4.0 ✔ bootstrapped: true ► checking controllers ✔ helm-controller: deployment ready ► ghcr.io/fluxcd/helm-controller:v1.1.0 ✔ image-automation-controller: deployment ready ► ghcr.io/fluxcd/image-automation-controller:v0.39.0 ✔ image-reflector-controller: deployment ready ► ghcr.io/fluxcd/image-reflector-controller:v0.33.0 ✔ kustomize-controller: deployment ready ► ghcr.io/fluxcd/kustomize-controller:v1.4.0 ✔ notification-controller: deployment ready ► ghcr.io/fluxcd/notification-controller:v1.4.0 ✔ source-controller: deployment ready ► ghcr.io/fluxcd/source-controller:v1.4.1 ► checking crds ✔ alerts.notification.toolkit.fluxcd.io/v1beta3 ✔ buckets.source.toolkit.fluxcd.io/v1 ✔ gitrepositories.source.toolkit.fluxcd.io/v1 ✔ helmcharts.source.toolkit.fluxcd.io/v1 ✔ helmreleases.helm.toolkit.fluxcd.io/v2 ✔ helmrepositories.source.toolkit.fluxcd.io/v1 ✔ imagepolicies.image.toolkit.fluxcd.io/v1beta2 ✔ imagerepositories.image.toolkit.fluxcd.io/v1beta2 ✔ imageupdateautomations.image.toolkit.fluxcd.io/v1beta2 ✔ kustomizations.kustomize.toolkit.fluxcd.io/v1 ✔ ocirepositories.source.toolkit.fluxcd.io/v1beta2 ✔ providers.notification.toolkit.fluxcd.io/v1beta3 ✔ receivers.notification.toolkit.fluxcd.io/v1 ✔ all checks passed

Git provider

github

Container Registry provider

github

Additional context

No response

Code of Conduct

makkes commented 5 days ago

You should store your YAML either as a multi-doc file or as several separate files.