argoproj / argo-cd

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

the Argo CD API does not currently support creating ApplicationSets with templated `project` fields" #13665

Open sahotay opened 1 year ago

sahotay commented 1 year ago

Summary

Is it possible to add feature to create ApplicationSet with templated project files

Error:

FATA[0001] rpc error: code = Unknown desc = error validating ApplicationSets: the Argo CD API does not currently support creating ApplicationSets with templated `project` fields 
morey-tech commented 1 year ago

Additional context here: https://github.com/argoproj/argo-cd/pull/9584#pullrequestreview-1059424970

sahotay commented 1 year ago

thanks @morey-tech Do you know if this feature got added ? i see this is part of the documentation now but it seems i do get the same error

project refers to the [Argo CD Project](https://argo-cd.readthedocs.io/en/stable/user-guide/projects/) in use (default may be used here to utilize the default Argo CD Project)

morey-tech commented 1 year ago

@sahotay I believe the spec.template.spec.project field still can not be templated. Also, the ApplicationSet documentation has been moved into the Argo CD docs, so this would be the correct page now. That section describes what the spec.template fields of the ApplicationSet relate to on an Application. The docs could use an enhancement to clarify that you can't template that field.

dyatlov commented 1 year ago

Managed to get around this via generators template:

spec:
  generators:
  - list:
      elements:
      - project: serviceentry
        extraParam: a
      - project: default
        extraParam: b
      template:
        spec:
          project: '{{project}}'
  template:
    spec:
      project: default

Project is correctly replaced then.

jasperjorna commented 8 months ago

Managed to get around this via generators template:

spec:
  generators:
  - list:
      elements:
      - project: serviceentry
        extraParam: a
      - project: default
        extraParam: b
      template:
        spec:
          project: '{{project}}'
  template:
    spec:
      project: default

Project is correctly replaced then.

Is this possible with the git directory generator as well?

rtomadpg commented 3 weeks ago

@jasperjorna got it working with argocd v2.12.0 like this:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: my-appset
  namespace: argocd
spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]
  generators:
    - git: 
        repoURL: my-git-repo
        revision: main
        files:
          - path: applications/*/cluster-a/.argocd.yaml
        template:
          metadata: {}
          spec:
            project: '{{ dig "project" "default" . }}' # lookup from .argocd.yaml, defaults to 'default'
            destination: {}
  template:
    metadata:
      name: '{{ index .path.segments 1 }}' # the application name
    spec:
      project: default # will be overriden by git generator's template.spec.project
      ...

I am using a git generator searching for a specific file, which is a YAML file containing several keys but specific to this issue it has a "project" key.

Hope this helps you / others.