Giter Club home page Giter Club logo

Comments (4)

christianh814 avatar christianh814 commented on August 21, 2024

@steve-todorov I read the thread. Do you have .spec.goTemplate set to true in your ApplicationSet resource?

from argo-cd.

steve-todorov avatar steve-todorov commented on August 21, 2024

@christianh814 yes I have it (updated the ticket to reflect this, sorry)

spec:
  goTemplate: true
  goTemplateOptions: ["missingkey=error"]

from argo-cd.

christianh814 avatar christianh814 commented on August 21, 2024

@steve-todorov It shouldn't "matter" but have you tried using '' instead? Like '{{.branch}}' and 'https://github.com/{{.organization}}/{{.repository}}'

from argo-cd.

steve-todorov avatar steve-todorov commented on August 21, 2024

@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: '[email protected]:{{.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: '[email protected]:{{.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:[email protected]: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?

from argo-cd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.