argoproj / argo-cd

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

appset: Git generator do not tolerate templating in `spec.template.spec.project` #18906

Open dacofr opened 5 days ago

dacofr commented 5 days ago

Checklist:

Describe the bug

I think that since #18545 we are not able to use templating in project attribute of application we are generating. Git generator raise this error getting project : AppProject.argoproj.io \"{{ path.basename }}\" not found and applications are not generated (path.basename is coming from my test suite).

cf. GenerateParams

    var project string
    if strings.Contains(appSet.Spec.Template.Spec.Project, "{{") {
        project = appSetGenerator.Git.Template.Spec.Project
    } else {
        project = appSet.Spec.Template.Spec.Project
    }

    appProject := &argoprojiov1alpha1.AppProject{}
    if err := client.Get(context.TODO(), types.NamespacedName{Name: appSet.Spec.Template.Spec.Project, Namespace: appSet.Namespace}, appProject); err != nil {
        return nil, fmt.Errorf("error getting project %s: %w", project, err)
    }

Even if we have a variable project we do not use it when we request k8s API.

To Reproduce

Expected behavior

No error, applications are generated, and we can use a template in project field.

Version

Running locally based on this commit : b96be4c5e4b44d684182444bc403936ff8505470

Logs

ERRO[2348] error generating application from params      applicationset=argocd/hello-git-appset error="error getting project : AppProject.argoproj.io \"{{ path.basename }}\" not found" generator="{nil nil &GitGenerator{RepoURL:https://github.com/dacofr/hello-appset.git,Directories:[]GitDirectoryGeneratorItem{},Files:[]GitFileGeneratorItem{GitFileGeneratorItem{Path:envs/**/config.json,},},Revision:main,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{},},},PathParamPrefix:,Values:map[string]string{},} nil nil nil nil nil nil nil}"
ERRO[2358] error generating params                       error="error getting project : AppProject.argoproj.io \"{{ path.basename }}\" not found" generator="&{0xc00014ff00}"
christianh814 commented 5 days ago

I wonder what's happening is that since the config.json file is empty, that it's erroring the whole thing out.

I agree, in this specific use case, I'd expect it to work (even with an empty config.json file).

Does it still not work if you add dummy data?

like in the config.json you put...

{
    "argo": "iscool"
}

...and see if it still errors out?

dacofr commented 5 days ago

Yes, even with dummy values in config.json, we still have errors.