github.com/argoproj/argo-cd/v2@v2.10.9/docs/operator-manual/applicationset/Generators-Cluster-Decision-Resource.md (about) 1 # Cluster Decision Resource Generator 2 3 The cluster decision resource generates a list of Argo CD clusters. This is done using [duck-typing](https://pkg.go.dev/knative.dev/pkg/apis/duck), which does not require knowledge of the full shape of the referenced Kubernetes resource. The following is an example of a cluster-decision-resource-based ApplicationSet generator: 4 ```yaml 5 apiVersion: argoproj.io/v1alpha1 6 kind: ApplicationSet 7 metadata: 8 name: guestbook 9 namespace: argocd 10 spec: 11 goTemplate: true 12 goTemplateOptions: ["missingkey=error"] 13 generators: 14 - clusterDecisionResource: 15 # ConfigMap with GVK information for the duck type resource 16 configMapRef: my-configmap 17 name: quak # Choose either "name" of the resource or "labelSelector" 18 labelSelector: 19 matchLabels: # OPTIONAL 20 duck: spotted 21 matchExpressions: # OPTIONAL 22 - key: duck 23 operator: In 24 values: 25 - "spotted" 26 - "canvasback" 27 # OPTIONAL: Checks for changes every 60sec (default 3min) 28 requeueAfterSeconds: 60 29 template: 30 metadata: 31 name: '{{.name}}-guestbook' 32 spec: 33 project: "default" 34 source: 35 repoURL: https://github.com/argoproj/argocd-example-apps/ 36 targetRevision: HEAD 37 path: guestbook 38 destination: 39 server: '{{.clusterName}}' # 'server' field of the secret 40 namespace: guestbook 41 ``` 42 The `quak` resource, referenced by the ApplicationSet `clusterDecisionResource` generator: 43 ```yaml 44 apiVersion: mallard.io/v1beta1 45 kind: Duck 46 metadata: 47 name: quak 48 spec: {} 49 status: 50 # Duck-typing ignores all other aspects of the resource except 51 # the "decisions" list 52 decisions: 53 - clusterName: cluster-01 54 - clusterName: cluster-02 55 ``` 56 The `ApplicationSet` resource references a `ConfigMap` that defines the resource to be used in this duck-typing. Only one ConfigMap is required per `ArgoCD` instance, to identify a resource. You can support multiple resource types by creating a `ConfigMap` for each. 57 ```yaml 58 apiVersion: v1 59 kind: ConfigMap 60 metadata: 61 name: my-configmap 62 data: 63 # apiVersion of the target resource 64 apiVersion: mallard.io/v1beta1 65 # kind of the target resource 66 kind: ducks 67 # status key name that holds the list of Argo CD clusters 68 statusListKey: decisions 69 # The key in the status list whose value is the cluster name found in Argo CD 70 matchKey: clusterName 71 ``` 72 73 (*The full example can be found [here](https://github.com/argoproj/argo-cd/tree/master/applicationset/examples/clusterDecisionResource).*) 74 75 This example leverages the cluster management capabilities of the [open-cluster-management.io community](https://open-cluster-management.io/). By creating a `ConfigMap` with the GVK for the `open-cluster-management.io` Placement rule, your ApplicationSet can provision to different clusters in a number of novel ways. One example is to have the ApplicationSet maintain only two Argo CD Applications across 3 or more clusters. Then as maintenance or outages occur, the ApplicationSet will always maintain two Applications, moving the application to available clusters under the Placement rule's direction. 76 77 ## How it works 78 The ApplicationSet needs to be created in the Argo CD namespace, placing the `ConfigMap` in the same namespace allows the ClusterDecisionResource generator to read it. The `ConfigMap` stores the GVK information as well as the status key definitions. In the open-cluster-management example, the ApplicationSet generator will read the kind `placementrules` with an apiVersion of `apps.open-cluster-management.io/v1`. It will attempt to extract the **list** of clusters from the key `decisions`. It then validates the actual cluster name as defined in Argo CD against the **value** from the key `clusterName` in each of the elements in the list. 79 80 The ClusterDecisionResource generator passes the 'name', 'server' and any other key/value in the duck-type resource's status list as parameters into the ApplicationSet template. In this example, the decision array contained an additional key `clusterName`, which is now available to the ApplicationSet template. 81 82 !!! note "Clusters listed as `Status.Decisions` must be predefined in Argo CD" 83 The cluster names listed in the `Status.Decisions` *must* be defined within Argo CD, in order to generate applications for these values. The ApplicationSet controller does not create clusters within Argo CD. 84 85 The Default Cluster list key is `clusters`.