argoproj / argo-cd

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

ApplicationSet does not generate labels with SCM provider generator #15218

Open mishanchus opened 1 year ago

mishanchus commented 1 year ago

Checklist:

Describe the bug

The documentation says that when using the SCM provider generator, several parameters are generated for use within the ApplicationSet resource template. Including labels:

labels: A comma-separated list of repository labels.

I am using gitlab. I have labeled the repositories and the group and these labels can be seen in /api/v4/projects/.../labels. In ApplicationSet, I'm trying to use these labels, but it's giving an error that index is out of range.

  template:
    metadata:
      name: "{{`{{ .repository }}`}}-{{`{{ .branch }}`}}"
      labels:
        type: "{{`{{ index .labels 1}}`}}"

An example of an error from the applicationsetcontroller logs:

time="2023-08-24T08:26:14Z" level=error msg="error generating application from params" error="failed to execute go template {{ index .labels 1}}: template: :1:3: executing \"\" at <index .labels 1>: error calling index: index out of range: 1" generator="{nil nil nil &SCMProviderGenerator{Github:nil,Gitlab:&SCMProviderGeneratorGitlab{Group:XXX,IncludeSubgroups:true,API:https://gitlab.XXX.XXXXX.XXXX/,TokenRef:&SecretRef{SecretName:gitlab-token,Key:token,},AllBranches:true,},Bitbucket:nil,BitbucketServer:nil,Gitea:nil,AzureDevOps:nil,Filters:[]SCMProviderGeneratorFilter{SCMProviderGeneratorFilter{RepositoryMatch:nil,PathsExist:[],PathsDoNotExist:[],LabelMatch:nil,BranchMatch:*^dev,},},CloneProtocol:https,RequeueAfterSeconds:nil,Template:ApplicationSetTemplate{ApplicationSetTemplateMeta:ApplicationSetTemplateMeta{Name:,Namespace:,Labels:map[string]string{},Annotations:map[string]string{},Finalizers:[],},Spec:ApplicationSpec{Source:nil,Destination:ApplicationDestination{Server:,Namespace:,Name:,},Project:,SyncPolicy:nil,IgnoreDifferences:[]ResourceIgnoreDifferences{},Info:[]Info{},RevisionHistoryLimit:nil,Sources:[]ApplicationSource{},},},} nil nil nil nil nil}" params="[map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx-test sha:59d1908666554f77dc1d89293021e94a66f5b2f6 short_sha:59d19086 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx-test.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:9121e0589311b83143e13d693c261162d2a579e7 short_sha:9121e058 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx-xxxxxx sha:637eba3e94f06b4cae110ddd45631ab7d659d71d short_sha:637eba3e url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx-xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:37541fca91b993e8b7c6255ea77d63788087fe33 short_sha:37541fca url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:078a1288309594e95c6f33b9f6fe4dc39f644907 short_sha:078a1288 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:f98e87993ac81fdae7a95d975f38de6c97a44c92 short_sha:f98e8799 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:1061b2245beac8d47b637e02d048395dd1543c48 short_sha:1061b224 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:adc7d196b00fd89d3f570c10c36f264a3f68ceaa short_sha:adc7d196 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:6432006f387ce4d5ca1ce127c6f988a1739e7c46 short_sha:6432006f url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:bfb7bdbb2e974773842d59128a121bb6e25b5601 short_sha:bfb7bdbb url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git]]"

Here you can see that there are no labels generated for any repository - just an empty space after "labels:".

To Reproduce

Use ApplicationSet with scmProvider generator and Gitlab. There should be labels on repositories in Gitlab. And you need to add .labels to the template part of the ApplicationSet.

Expected behavior

Labels are generated by ApplicationSet and can be used in templates.

Screenshots

image

image Version

argocd: v2.7.5+a2430af
  BuildDate: 2023-06-16T15:00:03Z
  GitCommit: a2430af1c356b283e5e3fc5bde1f5e2b5199f258
  GitTreeState: clean
  GoVersion: go1.19.10
  Compiler: gc
  Platform: linux/amd64
argocd-server: v2.7.2+cbee7e6.dirty

Logs

time="2023-08-24T08:26:14Z" level=error msg="error generating application from params" error="failed to execute go template {{ index .labels 1}}: template: :1:3: executing \"\" at <index .labels 1>: error calling index: index out of range: 1" generator="{nil nil nil &SCMProviderGenerator{Github:nil,Gitlab:&SCMProviderGeneratorGitlab{Group:XXX,IncludeSubgroups:true,API:https://gitlab.XXX.XXXXX.XXXX/,TokenRef:&SecretRef{SecretName:gitlab-token,Key:token,},AllBranches:true,},Bitbucket:nil,BitbucketServer:nil,Gitea:nil,AzureDevOps:nil,Filters:[]SCMProviderGeneratorFilter{SCMProviderGeneratorFilter{RepositoryMatch:nil,PathsExist:[],PathsDoNotExist:[],LabelMatch:nil,BranchMatch:*^dev,},},CloneProtocol:https,RequeueAfterSeconds:nil,Template:ApplicationSetTemplate{ApplicationSetTemplateMeta:ApplicationSetTemplateMeta{Name:,Namespace:,Labels:map[string]string{},Annotations:map[string]string{},Finalizers:[],},Spec:ApplicationSpec{Source:nil,Destination:ApplicationDestination{Server:,Namespace:,Name:,},Project:,SyncPolicy:nil,IgnoreDifferences:[]ResourceIgnoreDifferences{},Info:[]Info{},RevisionHistoryLimit:nil,Sources:[]ApplicationSource{},},},} nil nil nil nil nil}" params="[map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx-test sha:59d1908666554f77dc1d89293021e94a66f5b2f6 short_sha:59d19086 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx-test.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:9121e0589311b83143e13d693c261162d2a579e7 short_sha:9121e058 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx-xxxxxx sha:637eba3e94f06b4cae110ddd45631ab7d659d71d short_sha:637eba3e url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx-xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:37541fca91b993e8b7c6255ea77d63788087fe33 short_sha:37541fca url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:078a1288309594e95c6f33b9f6fe4dc39f644907 short_sha:078a1288 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:f98e87993ac81fdae7a95d975f38de6c97a44c92 short_sha:f98e8799 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:1061b2245beac8d47b637e02d048395dd1543c48 short_sha:1061b224 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:adc7d196b00fd89d3f570c10c36f264a3f68ceaa short_sha:adc7d196 url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:6432006f387ce4d5ca1ce127c6f988a1739e7c46 short_sha:6432006f url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git] map[branch:develop branchNormalized:develop labels: organization:XXX repository:xxx sha:bfb7bdbb2e974773842d59128a121bb6e25b5601 short_sha:bfb7bdbb url:https://gitlab.XXX.XXXXX.XXXX/XXX/xxx.git]]"
jjsiv commented 1 year ago

Hi, I just had a quick look and what are considered labels in case of Gitlab are project topics rather than actual labels (used on issues and PRs)

mishanchus commented 1 year ago

Hello @jjsiv, Yes, you are right. Using topics instead of labels helped.

prune998 commented 1 year ago

Gitlab labels are deprecated and superseded by topics