fluxcd/flux2

Cross git repository nested flux kustomization losses defined source ref

moenzuel opened this issue · 2 comments

Describe the bug

The root git repository has a flux kustomization that uses a different git repository for it's sourceRef. Inside the second repository another flux kustomization with a sourceRef with a value of something other than the root git repository gets overridden with the root git repository. This leads to a kustomization path not found error because flux looks for the path in the root repository.

Steps to reproduce

In repo 1 (cluster-root) have

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: apps
  namespace: flux-system
spec:
  interval: 30m
  path: ./apps
  prune: true
  wait: false
  sourceRef:
    kind: GitRepository
    name: cluster-apps

Then in repo 2 (cluster-apps) have

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: apps-appA
  namespace: flux-system
spec:
  interval: 30m
  path: ./apps/appA
  prune: true
  wait: false
  sourceRef:
    kind: GitRepository
    name: cluster-apps

See that the apps-appA kustomization's sourceRef.name changes from cluster-apps to cluster-root.

Expected behavior

sourceRef in nested secondary repository is not overridden.

Screenshots and recordings

No response

OS / Distro

Talos 1.8.1

Flux version

v2.4.0

Flux check

► checking prerequisites
✔ Kubernetes 1.31.1 >=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

No response

Container Registry provider

No response

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

sourceRef is not overwritten unless you explicitly patch it, looking at the samples you posted here this seems to be a typo, both Kustomization have the same sourceRef.