argoproj / argo-cd

Declarative Continuous Deployment for Kubernetes
https://argo-cd.readthedocs.io
Apache License 2.0
17.74k stars 5.41k forks source link

Source path must contain a `kustomization.yaml` when using `kustomize.patches` #16352

Open morey-tech opened 11 months ago

morey-tech commented 11 months ago

Checklist:

Describe the bug The docs (add in https://github.com/crenshaw-dev/argo-cd/pull/20/) state that:

Patches are a way to kustomize resources using inline configurations in Argo CD applications. This allows for kustomizing without [a] kustomization file.

However, when using the kustomize.patches field, the Application expects the path to contain a kustomization.yaml file. Without one, the sync will fail with the error open <path to cached source>/<path>/kustomization.yaml: no such file or directory.

Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = Unknown desc = Manifest generation error (cached): failed to load kustomization.yaml: open <path to cached source>/guestbook/kustomization.yaml: no such file or directory

To Reproduce Deploy the Application from the example in the docs:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: kustomize-inline-guestbook
spec:
  destination:
    namespace: default
    name: in-cluster
  project: default
  source:
    path: guestbook
    repoURL: https://github.com/argoproj/argocd-example-apps.git
    targetRevision: HEAD

## In-line Kustomize on plain Kubernetes manifests.
    kustomize:
      patches:
        - target:
            kind: Deployment
            name: guestbook-ui
          patch: |-
            - op: replace
              path: /spec/template/spec/containers/0/ports/0/containerPort
              value: 443

Expected behavior

The Application should ignore a missing kustomization.yaml file in the path when kustomize.patches is used. Or some equivalent (e.g. a toggle to allow missing).

Screenshots

Xnapper-2023-11-15-14 19 54

Version

Paste the output from `argocd version` here.

Logs

Paste any relevant application logs here.
crenshaw-dev commented 11 months ago

I think this is actually an enhancement request, i.e. automatically create kustomization.yaml for the user if spec.source.kustomize is populated and the file doesn't already exist.

morey-tech commented 11 months ago

Good point. The bug is the wording and example in the docs. The feature request is the expected behaviour. I'll put in a PR for the former.

alexmt commented 11 months ago

@morey-tech as I understand the use case is to allow users to apply last mile customization to any application (plain yaml, helm, plugin etc), correct? In this case Argo CD cannot just auto-create kustomization.yaml. E.g. app is helm-based then auto-creating kustomization.yaml would switch app to kustomize rendering and just break manifest generation. I think it is an entirely different feature. Argo CD would need to generate manifests first, then store result in e.g. all.yaml and leverage kustomize to apply patches on top. This would require a new field in the application spec:

spec:
...
## The field definitely should not be kustomize, because kustomize holds "inputs" for kustomize based apps.
    overrides:
      patches:
        - target:
            kind: Deployment
            name: guestbook-ui
          patch: |-
            - op: replace
              path: /spec/template/spec/containers/0/ports/0/containerPort
              value: 443
acelinkio commented 10 months ago

@alexmt My thought when contributing to the docs was the inline kustomization feature was to avoid needing any kustomize.yaml

Definitely would appreciate a built in way to do last mile modifications to resources.

Until then I created a quick plugin for doing kustomizations inline.

echo "$ARGOCD_ENV_KUSTOMIZATION_YAML" > kustomization.yaml;
kustomize build

And able to consume do everything inline

https://github.com/acelinkio/argocd-homelab/blob/main/manifest/knative-serving.yaml

I'll try to create an equivalent one for doing last mile modification to helm charts. (Definitely do not want to leverage kustomize to use the helm binanry and do a helm release)

SaschaJohn commented 3 months ago

@morey-tech is there any possibility to get this roadmaped? Thanks in advance