Starting from the FluxCD two cluster example at https://github.com/fluxcd/flux2-kustomize-helm-example, I'm having difficulty applying a patch to the infrastructure GitRepo.
When applying the patch as below, I am getting the error:
kustomize build failed: no resource matches strategic merge patch "HelmRelease.v2beta2.helm.toolkit.fluxcd.io/ingress-nginx.ingress-nginx": no matches for Id HelmRelease.v2beta2.helm.toolkit.fluxcd.io/ingress-nginx.ingress-nginx; failed to find unique target for patch HelmRelease.v2beta2.helm.toolkit.fluxcd.io/ingress-nginx.ingress-nginx
Moving the content of ingress-nginx.yaml into infrastructure/controllers/kustomization.yaml yields the same error
If I move the ingress-nginx.yaml to clusters/dev, and update the resources declaration to reflect the change, the patch applies correctly.
It seems that I can't apply a patch to a resource that's been defined in a GitRepo?
Relevant files below..
# clusters/dev/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./flux-system
- ../base/infrastructure.yaml
patches:
- patch: |-
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: ingress-nginx
namespace: ingress-nginx
spec:
values:
controller:
service:
type: "LoadBalancer"
# ../base/infrastructure.yaml
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: infra-controllers
namespace: flux-system
spec:
interval: 1h
retryInterval: 1m
timeout: 5m
sourceRef:
kind: GitRepository
name: flux-system
path: ./infrastructure/controllers
prune: true
wait: true
# ./infrastructure/controllers
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ingress-nginx.yaml
and finally,
# ingress-nginx.yaml
---
apiVersion: v1
kind: Namespace
metadata:
name: ingress-nginx
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
name: ingress-nginx
namespace: ingress-nginx
spec:
interval: 24h
url: https://kubernetes.github.io/ingress-nginx
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: ingress-nginx
namespace: ingress-nginx
spec:
interval: 30m
chart:
spec:
chart: ingress-nginx
version: "*"
sourceRef:
kind: HelmRepository
name: ingress-nginx
namespace: ingress-nginx
interval: 12h
values:
controller:
service:
type: "NodePort"
admissionWebhooks:
enabled: false