Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help wanted with dynamic kustomize resource configuration. #429

Open
AbstractVersion opened this issue Feb 24, 2024 · 1 comment
Open

Help wanted with dynamic kustomize resource configuration. #429

AbstractVersion opened this issue Feb 24, 2024 · 1 comment

Comments

@AbstractVersion
Copy link

AbstractVersion commented Feb 24, 2024

I am trying to set a dynamic configuration of manifests using Argocd, kustomize, helm and the lovely plugin. For example want to dynamically change the host of an ingress resource.

This is a reference kustomization file that uses grafana helm chart:

# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization


helmCharts:
- name: grafana
  includeCRDs: true
  releaseName: grafana
  version: 7.3.0
  repo: https://grafana.github.io/helm-charts
  valuesFile: values.yaml
  # namespace: demo

I would like to dynamically configure the ingress host name through the argo application or application set. I saw on the docs that I can use LOVELY_KUSTOMIZE_PATCH env variable to set kustomization patches. My issue is that I cant understand how to define the target resource (eg. kind :Ingress, name: grafana-ingress).
An example Argocd Application is the following

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: kustomize-grafana-helm
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  destination:
    namespace: demo
    server: https://kubernetes.default.svc
  project: default
  source:
    path: resources/kustomize/grafana # <- points to the above kustomization file
    repoURL: <eg-repo>
    targetRevision: HEAD
    plugin:
      name: lovely-vault-plugin
      env:
        - name: LOVELY_KUSTOMIZE_PATCH
          value: '[{"op": "replace", "path": "/spec/rules/0/host", "value": "grafana-test.demo.com"}]'

The problem with the above application is that I don't see how can I reference the Ingress resource and naturally argocd throws an error of :

Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = Unknown desc = Manifest generation error (cached): plugin sidecar failed. error generating manifests in cmp: rpc error: code = Unknown desc = error generating manifests: `argocd-lovely-plugin` failed exit status 1: 2024/02/24 15:30:22 replace operation does not apply: doc is missing path: /spec/rules/0/host: missing value

I might not be in the right path to do this, so any suggestions would be much appreciated.

Thanks in advance.

@Joibel
Copy link
Contributor

Joibel commented Feb 26, 2024

LOVELY_KUSTOMIZE_PATCH is patching the kustomization.yaml file.

It can do what you want, but you need to write the correct patch. Start by writing what you need into a kustomization.yaml without the patching happening. This will need to identify the object needed to be patched (an ingress). You can then convert this into an appropriate patch.

What you have written there is patching kustomization.yaml as though it were the ingress object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants