argoproj / argo-cd

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

ApplicationSet - Cluster Resources generator #12656

Open aslafy-z opened 1 year ago

aslafy-z commented 1 year ago

Summary

Add an ArgoCD ApplicationSet generator that use results from downstream cluster's APIServer

Motivation

Generate resources from other resources can help in some cases.

Proposal

Add the ability to generate Applications from downstream cluster resources, eg:

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: monitoring-addon
  namespace: argocd
spec:
  generators:
    - clusterResource:
        clusters: {}  
        resources:
          apiVersion: tenant.io/v1
          kind: Tenant
          # namespace: <optional>
          labelSelector:
            matchLabels:
              tenant.io/sync: 'true'
  template:
    metadata:
      name: '{{resource.metadata.name}}-sample-app'
    spec:
      project: default
      source:
        repoURL: https://github.com/argoproj/argocd-example-apps/
        targetRevision: HEAD
        path: guestbook
      destination:
        server: '{{server}}'
        namespace: '{{resource.metadata.namespace}}'
apiVersion: tenant.io/v1
kind: Tenant
metadata:
  name: tenant1
  labels:
    tenant.io/sync: 'true'
spec: {}
apiVersion: tenant.io/v1
kind: Tenant
metadata:
  name: tenant2
  labels:
    tenant.io/sync: 'true'
spec: {}

ArgoCD should generate two applications from these resources.

crenshaw-dev commented 1 year ago

I like the idea. Is the idea to only make the metadata accessible in the template? Or would you want the full resource?

aslafy-z commented 1 year ago

The metadata would be an awesome step but yes, I was thinking of passing down spec fields as helm values. Not sure about the performance implications it would have tho.