argoproj / applicationset

The ApplicationSet controller manages multiple Argo CD Applications as a single ApplicationSet unit, supporting deployments to large numbers of clusters, deployments of large monorepos, and enabling secure Application self-service.
https://argocd-applicationset.readthedocs.io/
Apache License 2.0
586 stars 279 forks source link

Is it possible to use duck-type generator with cluster wide resources? #519

Open RustamGimadiev opened 2 years ago

RustamGimadiev commented 2 years ago

I started to use such thing with the following configuration:

apiVersion: v1
kind: ConfigMap
metadata:
  name: spaces
  namespace: argocd
data:
  apiVersion: some.domain/v1
  kind: spaces
  statusListKey: configurations
  matchKey: cluster
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: spaces
  namespace: argocd
spec:
  generators:
    - clusterDecisionResource:
        configMapRef: spaces
        labelSelector:
          matchLabels:
            status.some.domain: ready
        requeueAfterSeconds: 30
apiVersion: some.domain/v1
kind: space
metadata:
  name: example
  labels:
    status.some.domain: ready
status:
  configurations:
    - owner: example
      configMap: example
      secret: example

also, controller was configured with clusterRole with required permissions to list spaces, but for some reasons controller failed with

time="2022-02-25T08:22:20Z" level=info msg="Alloc=6295 TotalAlloc=585594 Sys=73553 NumGC=607 Goroutines=70"
time="2022-02-25T08:32:20Z" level=info msg="Alloc=7959 TotalAlloc=591326 Sys=73553 NumGC=612 Goroutines=70"
time="2022-02-25T08:34:15Z" level=info msg="Kind.Group/Version Reference" kind.apiVersion=spaces.some.domain/v1
time="2022-02-25T08:34:15Z" level=debug msg="decoded Ref" kind.group.version=spaces.some.domain/v1
time="2022-02-25T08:34:15Z" level=info msg="selection type" listOptions.LabelSelector="status.some.domain=ready"
time="2022-02-25T08:34:15Z" level=warning msg="resources were not found" GVK="some.domain/v1, Resource=spaces"
time="2022-02-25T08:34:15Z" level=error msg="error generating params" error="the server could not find the requested resource" generator="&{0xc000054030 0xc000582a80 0xc0003ae840 argocd 0xc00030c180}"
time="2022-02-25T08:34:15Z" level=error msg="error generating application from params" error="the server could not find the requested resource" generator="{<nil> <nil> <nil> <nil> 0xc000162340 <nil> <nil> <nil>}"
2022-02-25T08:34:15.289Z    ERROR   controller-runtime.manager.controller.applicationset    Reconciler error    {"reconciler group": "argoproj.io", "reconciler kind": "ApplicationSet", "name": "spaces", "namespace": "argocd", "error": "the server could not find the requested resource"}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
    /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.9.0/pkg/internal/controller/controller.go:253
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
    /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.9.0/pkg/internal/controller/controller.go:214
time="2022-02-25T08:42:20Z" level=info msg="Alloc=7213 TotalAlloc=594794 Sys=73553 NumGC=617 Goroutines=70"
RustamGimadiev commented 2 years ago

seems like dynamic client try to looking for resources in argocd namespace by default, as it passed to list call:

duckResources, err := g.dynClient.Resource(duckGVR).Namespace(g.namespace).List(g.ctx, listOptions)