argoproj / argo-cd

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

Application.argoproj.io "{{.path.basename}}" is invalid: metadata.name: Invalid value #20145

Closed droslean closed 1 month ago

droslean commented 1 month ago

Checklist:

Describe the bug

{{path.basename}} doesn't work on a specific case only.

To Reproduce

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: monitoring
  namespace: argocd
spec:
  generators:
  - git:
      repoURL: https://github.com/my-org/my-repo.git
      revision: master
      directories:
      - path: cluster-resources/monitoring/*
  template:
    metadata:
      name: '{{.path.basename}}'
    spec:
      project: monitoring
      source:
        repoURL: https://github.com/my-org/my-repo.git
        targetRevision: master
        path: "{{path}}"
      destination:
        server: https://kubernetes.default.svc
      syncPolicy:
        automated:
          selfHeal: true
        syncOptions:
        - Prune=false

folder structure:

monitoring/
└── monitoring-stack
    ├── manifests.yaml
Status:
  Conditions:
    Last Transition Time:  2024-09-28T13:15:23Z
    Message:               Application.argoproj.io "{{.path.basename}}" is invalid: metadata.name: Invalid value: "{{.path.basename}}": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
    Reason:                UpdateApplicationError
    Status:                True
    Type:                  ErrorOccurred
    Last Transition Time:  2024-09-28T13:15:23Z
    Message:               Successfully generated parameters for all Applications
    Reason:                ParametersGenerated
    Status:                True
    Type:                  ParametersGenerated
    Last Transition Time:  2024-09-28T13:15:23Z
    Message:               Application.argoproj.io "{{.path.basename}}" is invalid: metadata.name: Invalid value: "{{.path.basename}}": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
    Reason:                UpdateApplicationError
    Status:                False
    Type:                  ResourcesUpToDate
Events:                    <none>

Version

$ argocd version
argocd: v2.10.17+6e33cba
  BuildDate: 2024-09-26T07:23:50Z
  GitCommit: 6e33cba80e65f7f60f1a1e8f677a6e2dce315368
  GitTreeState: clean
  GoVersion: go1.21.13
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.12.3+6b9cd82
  BuildDate: 2024-08-27T11:57:48Z
  GitCommit: 6b9cd828c6e9807398869ad5ac44efd2c28422d6
  GitTreeState: clean
  GoVersion: go1.22.4
  Compiler: gc
  Platform: linux/amd64
  Kustomize Version: v5.4.2 2024-05-22T15:19:38Z
  Helm Version: v3.15.2+g1a500d5
  Kubectl Version: v0.29.6
  Jsonnet Version: v0.20.0
dhruvang1 commented 1 month ago

Prefix . is only used when spec.goTemplate: true. Without that, you can refer the variable as path.basename https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/GoTemplate/#migration-guide