kuberneteskustomizefluxcd

Flux CD does not work with Kustomize Kind: Component


I have the following structure:

├───base
│   └───redis
│           kustomization.yaml
│           release.yaml
│
├───components
│   └───target-namespace
│           kustomization.yaml
│
└───prod
    └───redis
            kustomization.yaml

Redis overlay looks like this:

kind: Kustomization
namespace: flux-system
resources:
  - ../../base/redis
components:
  - ../base/components/target-namespace
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
patches:
  - patch: |-
      apiVersion: helm.toolkit.fluxcd.io/v2beta1
      kind: HelmRelease
      metadata:
        name: not-used
      spec:
        targetNamespace: default
    target:
      kind: HelmRelease
When I run kustomize 
build .\prod\redis\ 

locally it works! But when I push it to FluxCD and expect it to work it gives me the following error:

/components/target-namespace is a directory': expected kind != 'Component'

Does anyone encounter this issue?


Solution

  • As per the official FluxCD documentations 1

    .spec.components is an optional list used to specify Kustomize components. This allows using reusable pieces of configuration logic that can be included from multiple overlays.

    Although you did not provide your FluxCD Kustomize CRD definition in your question, I'd say your issue lies in the path you're referencing the target component.

    What I'm trying to say is that any path you specify in your components is relative to the kustomization.yaml.

    Which, in essence, means that in your prod/redis/kustomization.yaml, you will need to modify the components to the following to make it work:

    kind: Kustomization
    namespace: flux-system
    resources:
      - ../../base/redis
    components:
      - ../../base/components/target-namespace # <- change this
    

    Again, any path you specify in your components is relative to the kustomization.yaml and should be accessible just like a normal cd command would be able to.