Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applicationset git generator with empty yaml files does #12895

Closed
GijsvanDulmen opened this issue Mar 16, 2023 · 3 comments · Fixed by #15661
Closed

Applicationset git generator with empty yaml files does #12895

GijsvanDulmen opened this issue Mar 16, 2023 · 3 comments · Fixed by #15661
Assignees
Labels
bug Something isn't working component:application-sets Bulk application management related good first issue Good for newcomers

Comments

@GijsvanDulmen
Copy link

GijsvanDulmen commented Mar 16, 2023

Describe the bug

So I'm having a potential issue with the Git Generator using file matching. We're having a file match on certain yaml files to be available. But when a certain yaml file is completely empty (containing no yaml only a newline for example) it isn't detected as a matched file. I can see that the following code (https://github.com/argoproj/argo-cd/blob/master/applicationset/generators/git.go#L138-L148) does a "yaml to array" try. This succeeds on empty files but will result in an empty array. I consider this a bug ... but I'm not sure if others feel the same about it. Or am I missing something?

To Reproduce

Our setup was as follows:
/directory/values/production.yaml (empty file)
/directory/Chart.yaml (helm chart stuff)
/directory/values.yaml (containing generic values stuff used combined with the production.yaml)

Expected behavior
A created application within the applicationsets.

Version
v2.5.8 (OpenShift GitOps)

@GijsvanDulmen GijsvanDulmen added the bug Something isn't working label Mar 16, 2023
@GijsvanDulmen
Copy link
Author

See https://cloud-native.slack.com/archives/C01TSERG0KZ/p1678890329839499 for a bit of discussion as well.

@crenshaw-dev crenshaw-dev added the component:application-sets Bulk application management related label Mar 29, 2023
@jwenz723
Copy link

jwenz723 commented Aug 4, 2023

I ran into this issue today.

My desire was to use the existence of an argocd.yaml file to trigger the appset to generate application(s). If the argocd.yaml file is empty then default settings should be used in the generated application(s). I wanted to allow this file to be used to optional override application settings like ignoreDifferences.

Personally, I would consider the current behavior of ignoring empty yaml files a bug. But at this point, changing the behavior may cause problems for people who have implemented a solution which expects an empty file to do nothing.

@renaudguerin
Copy link
Contributor

renaudguerin commented Sep 13, 2023

I just ran into the same issue and asked about it on Slack.

In my case, I rely on default functions a lot in the app template (Go template). For most apps, we can just go with that and don't need any overrides. I still provide an "empty" config file to make the files-based generator happy (actually, it contains --- and a bunch of commented out parameter overrides for human reference). I guess could use the directory-based git generator, but I do need the ability to override parameters sometimes.

However, looking at the Git generator source code, I don't understand why it shouldn't work.

I'm not a Go wizard, but ChatGPT seems to agree:

When a YAML file only contains --- and commented out entries, the yaml.Unmarshal function will not fail, but it will not populate objectsFound with any actual data entries. Instead, it will create an empty map for each --- separator it encounters.

So, if your YAML file contains only one --- separator and commented out entries, objectsFound will be a slice containing a single empty map. If your YAML file contains multiple --- separators and commented out entries, objectsFound will be a slice containing multiple empty maps.

Then, the function iterates over objectsFound. For each objectFound (which is an empty map in this case), it creates a params map. If useGoTemplate is true, it attempts to copy the key-value pairs from objectFound to params. Since objectFound is an empty map, no key-value pairs will be copied, but params will still be created.

Next, the function creates a paramPath map and populates it based on the filePath parameter of the generateParamsFromGitFile function, not on the contents of objectFound. This paramPath map is then added to params.

Finally, the function appends params to res and returns res after the loop. So, even if the YAML file contains no values, the function should still return a slice containing a map with the paramPath values for each --- separator in the YAML file.

Any thoughts ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component:application-sets Bulk application management related good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants