Open steve-todorov opened 3 days ago
@steve-todorov I read the thread. Do you have .spec.goTemplate
set to true
in your ApplicationSet resource?
@christianh814 yes I have it (updated the ticket to reflect this, sorry)
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
@steve-todorov It shouldn't "matter" but have you tried using ''
instead? Like '{{.branch}}'
and 'https://github.com/{{.organization}}/{{.repository}}'
@christianh814 My code slightly evolved since I've opened the ticket, because I've introduced a custom plugin that generates some additional parameters based on the branch name. I've tried a few combinations but none of them work (again showing either a missing .branch
, .organization
, repository
error or .case_number
one).
Basically the idea is to have the scmProvider
scan for the repos, then have the plugin
generate dynamic properties based on branch name convention and finally give an option to manually override properties via a git path in the same repository when a file with the same case number exists.
Example 1:
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- matrix:
generators:
- scmProvider:
cloneProtocol: ssh
github:
organization: my-organization
allBranches: true
tokenRef:
secretName: github-token
key: token
filters:
- repositoryMatch: ^my-repository$
branchMatch: ^kustomize|scm/([0-9]+).*$
pathsExist: [deployment/kubernetes/kustomization.yaml]
- plugin:
configMapRef:
# produces some parameters based on the branch naming convention (i.e. case_number)
name: applicationset-branch-generator-plugin
input:
parameters:
branch: '{{.branch}}'
project_code: 'exmpl'
organization: '{{.organization}}'
repository: '{{.repository}}'
requeueAfterSeconds: 30
- git:
repoURL: 'git@github.com:{{.organization}}/{{.repository}}.git'
revision: '{{.branch}}'
files:
- path: 'deployment/kubernetes/properties/{{.case_number}}.yml'
Example 2:
spec:
goTemplate: true
goTemplateOptions: ["missingkey=error"]
generators:
- matrix:
generators:
- scmProvider:
cloneProtocol: ssh
github:
organization: my-organization
allBranches: true
tokenRef:
secretName: github-token
key: token
filters:
- repositoryMatch: ^my-repository$
branchMatch: ^kustomize|scm/([0-9]+).*$
pathsExist: [deployment/kubernetes/kustomization.yaml]
- matrix:
generators:
- plugin:
configMapRef:
# produces some parameters based on the branch naming convention (i.e. case_number)
name: applicationset-branch-generator-plugin
input:
parameters:
branch: '{{.branch}}'
project_code: 'exmpl'
organization: '{{.organization}}'
repository: '{{.repository}}'
requeueAfterSeconds: 30
- git:
repoURL: 'git@github.com:{{.organization}}/{{.repository}}.git'
revision: '{{.branch}}'
files:
- path: 'deployment/kubernetes/properties/{{.case_number}}.yml'
Here's an example output of the generator plugin:
10.0.0.8 - - [02/Jul/2024 12:19:19] "POST /api/v1/getparams.execute HTTP/1.1" 200 -
Received arguments: {'applicationSetName': 'exmpl-staging-scm-preview', 'input': {'parameters': {'branch': 'scm/35765-some-title', 'organization': 'my-organization', 'project_code': 'exmpl', 'repository': 'my-repository'}}}
Output parameters: {'case_number': '35765', 'subdomain': '35765-exmpl-staging-scm', 'memoryRequest': '500Mi', 'memoryLimit': '700Mi', 'keycloakServerUrl': 'https://keycloak-staging.local.domain/auth', 'branch': 'scm/35765-some-title', 'organization': 'my-organization', 'project_code': 'exmpl', 'repository': 'my-repository'}
So the plugin does receive the proper values and switching from double quotes "
to single quotes '
seems to be resolving the .branch
/ .organization
/ .repository
error. Unfortunately now it's unable to resolve the .case_number
that's generated by the custom generator
plugin.
ERRO[301695] error interpolating generator with other generator's parameter error="failed to replace parameters in generator: failed to execute go template deployment/kubernetes/properties/{{.case_number}}.yml: template: :1:35: executing \"\" at <.case_number>: map has no entry for key \"case_number\"" interpolatedGenerator=nil
ERRO[301695] error interpolating params for generator error="failed to replace parameters in generator: failed to execute go template deployment/kubernetes/properties/{{.case_number}}.yml: template: :1:35: executing \"\" at <.case_number>: map has no entry for key \"case_number\"" genParams="map[branch:kustomize branchNormalized:kustomize labels: organization:my-organization repository:my-repository sha:xdfe8ccb3609e14d1ada9cf1967568f9e277075 short_sha:abdfe8cc short_sha_7:abdfe8c url:git@github.com:my-organization/my-repository.git]"
ERRO[301695] error generating params error="failed to get params for second generator in the matrix generator: child generator returned an error on parameter generation: failed to replace parameters in generator: failed to execute go template deployment/kubernetes/properties/{{.case_number}}.yml: template: :1:35: executing \"\" at <.case_number>: map has no entry for key \"case_number\"" generator="&{map[ClusterDecisionResource:0xc001383590 Clusters:0xc001383540 Git:0xc0013e7a70 List:0x75e9dc0 Matrix:0xc0013980e0 Merge:0xc0013980e8 Plugin:0xc001560bc0 PullRequest:0xc001395680 SCMProvider:0xc001395620]}"
ERRO[301695] error generating application from params applicationset=argocd/exmpl-staging-scm-preview error="failed to get params for second generator in the matrix generator: child generator returned an error on parameter generation: failed to replace parameters in generator: failed to execute go template deployment/kubernetes/properties/{{.case_number}}.yml: template: :1:35: executing \"\" at <.case_number>: map has no entry for key \"case_number\"" generator="{nil nil nil nil nil nil &MatrixGenerator{Generators:[]ApplicationSetNestedGenerator{ApplicationSetNestedGenerator{List:nil,Clusters:nil,Git:nil,SCMProvider:&SCMProviderGenerator{Github:&SCMProviderGeneratorGithub{Organization:my-organization,API:,TokenRef:&SecretRef{SecretName:github-token,Key:token,},AppSecretName:,AllBranches:true,},Gitlab:nil,Bitbucket:nil,BitbucketServer:nil,Gitea:nil,AzureDevOps:nil,Filters:[]SCMProviderGeneratorFilter{SCMProviderGeneratorFilter{RepositoryMatch:*^my-repository$,PathsExist:[deployment/kubernetes/kustomization.yaml],PathsDoNotExist:[],LabelMatch:nil,BranchMatch:*^kustomize|scm/([0-9]+).*$,},},CloneProtocol:ssh,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{},},},Values:map[string]string{},AWSCodeCommit:nil,},ClusterDecisionResource:nil,PullRequest:nil,Matrix:nil,Merge:nil,Selector:nil,Plugin:nil,},ApplicationSetNestedGenerator{List:nil,Clusters:nil,Git:nil,SCMProvider:nil,ClusterDecisionResource:nil,PullRequest:nil,Matrix:&v11.JSON{Raw:*[ shortened ],},Merge:nil,Selector:nil,Plugin: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}"
INFO[301720] generated 1 applications
Not sure what I'm doing wrong here. Any ideas?
Checklist:
argocd version
.Describe the bug
We are using a
matrix
generator together with amerge
generator and agit file
generator. The interpolation inside therepoURL
andrevision
parameters of thegit file
generator are not wodking. When you try to reference the{{.branch}}
parameter you will get the literal{{.branch}}
instead of the actual value.I went back to v2.4.0 where this was introduced and it looks like the
interpolation
is supposed to work only forvalues
which seems to be very odd?https://github.com/argoproj/argo-cd/compare/v2.3.0...v2.4.0#diff-e18bda08876f1471ded096f197d58778d250cd942ca66539391b067d5f069f79
Here's the slack thread where I discussed this with @crenshaw-dev: https://cloud-native.slack.com/archives/C01TSERG0KZ/p1719585649594259
To Reproduce
Expected behavior
Interpolation should work in the
git file
generator parameters.Version
Logs
Different variations of this error (depending on the version I tried)