argoproj / argo-cd

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

Templating issue with `valuesObject`: Failed to unmarshal "xxxxx.yaml": <nil> #17288

Open papanito opened 7 months ago

papanito commented 7 months ago

Checklist:

Describe the bug

An applicationSet cannot be synchronized when using templating and certain helm values are enabled, while I use valuesObject:

Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = FailedPrecondition desc = Failed to unmarshal "kured.yaml": <nil>

To Reproduce

Setup the following applicationSet

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: kured
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
  - list:
      elements:
      - cluster: cluster1
        project: p-n6fht
        rebootDays: [mon,tue,wed,thu,fri]
        notifyUrl: teams://<redacted>
      - cluster: cluster2
        project: p-tbck6
        rebootDays: [mon,tue,wed,thu]
        notifyUrl: teams://<redacted>
    metadata:
      name: kured-{{.cluster}}
      namespace: argocd
      labels:
        swisscard.ch/ea-app-id: "424"
    spec:
      destination:
        namespace: kured
        name: "{{.cluster}}"
      project: container-platform-tooling
      source:
        repoURL: https://helm.intra
        targetRevision: 4.4.1
        chart: kured
        helm:
          valuesObject:
            updateStrategy: RollingUpdate 
            image:
              repository: docker.intra/kubereboot/kured
              tag: 1.12.2 # should match the recommended version at https://github.com/weaveworks/kured
            configuration:
              period: 5m # reboot check period (default 1h0m0s)
              startTime: 6am
              endTime: 6pm
              timeZone: Europe/Zurich
              #rebootDays: {{.rebootDays}}
              blockingPodSelector: ["app=artifactory"]
              #notifyUrl: {{.notifyUrl}}
            tolerations:
              - effect: NoSchedule
                operator: Exists
              - key: CriticalAddonsOnly
                operator: Exists
              - effect: NoExecute
                operator: Exists
      syncPolicy:
        managedNamespaceMetadata:
          labels:
            field.cattle.io/projectId: "{{.project}}"
        automated:
          prune: true
          selfHeal: true
        syncOptions:
        - CreateNamespace=true

So far, this synchronizes fine, but then if you comment either of these lines

#rebootDays: {{.rebootDays}}
#notifyUrl: {{.notifyUrl}}

If I set

rebootDays: [mon,tue,wed,thu]

All is good, so it seems the issue is related with templating.

I also tried without

  goTemplate: true
  goTemplateOptions: ["missingkey=error"]

But I have the exact same behaviour.

When I switch to values: | the issue is gone, and sync is fine.

Expected behavior

Synchronisation is ok

Screenshots

Version

v2.10.1+a79e0ea

Logs

Failed to load target state: failed to generate manifest for source 1 of 1: rpc error: code = FailedPrecondition desc = Failed to unmarshal "kured.yaml": <nil>
blakepettersson commented 7 months ago

Is the issue that if any key within valuesObject is commented out, an unmarshaling error occurs? (i.e does this issue happen with any other key than the ones you mentioned)?

papanito commented 7 months ago

Yes any key which contains a "templating" value ({{xxxx}}) and is un-commented, will cause the error. I added for instance startTime: 6am as template (startTime: {{.startTime}} and deployed it, which resulted in the error.