argoproj / argo-cd

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

argocd app diff fails to render when templating CRDs #19527

Open danielftapiar opened 3 months ago

danielftapiar commented 3 months ago

Describe the bug

When trying to run an app diff on an the CLI it fails to generate any diffs that are currently on the release.

argocd app diff --grpc-web --server $ARGOCD_URL --auth-token $ARGOCD_TOKEN argocd --revision efcd51bc7c1c843fd4f4c303f1e9657445bd8280  --loglevel debug

It silently fails, but increasing the log level to debug you can see that it's having issues creating the CRDs that are part of the helm release

This only seems to be happening with custom resource definitions (CRDs) I have other releases that render the correct manifests.

To Reproduce

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: kong
  labels:
    service: kong
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
  - matrix:
      generators:
      - list:
          elements:
          # - cluster: ops
          - cluster: staging
      - list:
          elements:
          - type: internal
            valueFile: internal.yaml
          - type: external
            valueFile: external.yaml
          - type: doorman
            valueFile: doorman.yaml

  template:
    metadata:
      name: 'kong-{{.type}}-{{.cluster}}'
      labels:
        env: '{{.cluster}}'
        service: kong-{{.type}}
    spec:
      project: '{{.cluster}}-core'

      sources:

      - repoURL: https://charts.konghq.com
        chart: ingress
        targetRevision: '0.13.1'
        helm:
          releaseName: kong-{{.type}}
          valueFiles:
          - $values/core/kong/global.yaml
          - $values/core/kong/values/{{.cluster}}/{{.valueFile}}

      - repoURL: https://github.com/********.git
        targetRevision: main
        ref: values

      - repoURL: https://github.com/*********.git
        targetRevision: main
        path: core/kong/resources/{{.cluster}}/{{.type}}

      destination:
        name: '{{.cluster}}'
        namespace: kong

      syncPolicy:
        automated:
          prune: true
          selfHeal: true
          allowEmpty: false
        syncOptions:
        - ApplyOutOfSyncOnly=true 
        - CreateNamespace=true

  strategy:
    type: RollingSync
    rollingSync:
      steps:
        - matchExpressions:
            - key: env
              operator: In
              values:
                - staging

Expected behavior

app diff should render the diffs found on custom resources.

Checklist:

Screenshots 2024-08-14_09-37

Version

 argocd version
argocd: v2.12.0+ec30a48
  BuildDate: 2024-08-05T13:46:43Z
  GitCommit: ec30a48bce7a60046836e481cd2160e28c59231d
  GitTreeState: clean
  GoVersion: go1.22.5
  Compiler: gc
  Platform: linux/amd64
WARN[0000] Failed to invoke grpc call. Use flag --grpc-web in grpc calls. To avoid this warning message, use flag --grpc-web.
argocd-server: v2.11.7+e4a0246
  BuildDate: 2024-07-24T09:33:49Z
  GitCommit: e4a0246c4d920bc1e5ee5f9048a99eca7e1d53cb
  GitTreeState: clean
  GoVersion: go1.21.10
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v5.2.1 2023-10-19T20:13:51Z
  Helm Version: v3.14.4+g81c902a
  Kubectl Version: v0.26.11
  Jsonnet Version: v0.20.0

```shell
go version
go version go1.17.13 linux/amd64

Logs

INFO[0003] Could not create new object of type apiextensions.k8s.io/v1, Kind=CustomResourceDefinition: no kind "CustomResourceDefinition" is registered for version "apiextensions.k8s.io/v1" in scheme "pkg/runtime/scheme.go:100"
INFO[0003] Could not create new object of type argoproj.io/v1alpha1, Kind=AppProject: no kind "AppProject" is registered for version "argoproj.io/v1alpha1" in scheme "pkg/runtime/scheme.go:100"
INFO[0003] Could not create new object of type external-secrets.io/v1beta1, Kind=ExternalSecret: no kind "ExternalSecret" is registered for version "external-secrets.io/v1beta1" in scheme "pkg/runtime/scheme.go:100"
INFO[0003] Could not create new object of type external-secrets.io/v1beta1, Kind=SecretStore: no kind "SecretStore" is registered for version "external-secrets.io/v1beta1" in scheme "pkg/runtime/scheme.go:100"
INFO[0003] Could not create new object of type generators.external-secrets.io/v1alpha1, Kind=ECRAuthorizationToken: no kind "ECRAuthorizationToken" is registered for version "generators.external-secrets.io/v1alpha1" in scheme "pkg/runtime/scheme.go:100"
eugene70 commented 2 months ago

@danielftapiar , I tried to reproduce it by inserting CRD into the official sample. I definitely confirmed that the error message was output at the debug level, but the operation itself was fine. When I changed the value of CRD yaml, the diff value was output normally. Are you pointing out that there is a problem with the operation itself, or with the error message itself?

$ argocd app diff guestbook-3 --loglevel debug
INFO[0000] Could not create new object of type apiextensions.k8s.io/v1, Kind=CustomResourceDefinition: no kind "CustomResourceDefinition" is registered for version "apiextensions.k8s.io/v1" in scheme "pkg/runtime/scheme.go:100"
INFO[0000] Could not create new object of type apiextensions.k8s.io/v1, Kind=CustomResourceDefinition: no kind "CustomResourceDefinition" is registered for version "apiextensions.k8s.io/v1" in scheme "pkg/runtime/scheme.go:100"

===== apiextensions.k8s.io/CustomResourceDefinition /myresources.example.com ======
81c81
<     - mrx
---
>     - mr
danielftapiar commented 2 months ago

I did a few more updates and can corroborate what you say is true, error message shows up, but resources get deployed