argoproj / argo-cd

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

Application Sets using project parameter from cluster secret #18814

Open allevimi opened 3 weeks ago

allevimi commented 3 weeks ago

Summary

As described on Application Sets Cluster Generator, some parameters from cluster secret definition could be used as AppSet definition like name, server, labels, but optional project parmater it is not avilable.

Motivation

In my case, I have 3 project that identifies 3 gcp environment, their respective gke cluster have project secret parameter set as respective project name; after that I have an AppSet definition that uses a cluster generator that deploys common manifests for all clusters, but Application spec needs project field. At the moment I inserted a project label field and use it.

apiVersion: v1
kind: Secret
type: Opaque
metadata:
  labels:
    argocd.argoproj.io/secret-type: cluster
    environment: dev
    project: project1
  name: argocd-cluster-cluster1
  namespace: argocd
stringData:
  config: <config>
  name: cluster1
  project: project1
  server: http://server.local
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: app-set
  namespace: argocd
spec:
  goTemplate: true
  goTemplateOptions:
  - missingkey=error
  generators:
  - clusters: {}
  template:
    metadata:
      name: '{{.name}}-app-set'
    spec:
      destination:
        name: '{{.name}}'
      project: '{{index .metadata.labels "project"}}'
      source:
        path: app-set
        repoURL: https://repo.git
        targetRevision: main

Proposal

My proposal is to make available also project parameter from cluster secret definition, in order to have an Application Set definition like this

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: app-set
  namespace: argocd
spec:
  goTemplate: true
  goTemplateOptions:
  - missingkey=error
  generators:
  - clusters: {}
  template:
    metadata:
      name: '{{.name}}-app-set'
    spec:
      project: '{{.project}}'
      source:
        path: app-set
        repoURL: https://repo.git
        targetRevision: main
      destination:
        name: '{{.name}}'
christianh814 commented 3 weeks ago

This is a +1 for me and would support a PR that implements this