You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I have a template yaml that uses an enabled switch in the values.yaml that determines if the template should be rendered or not:
{{- if .Values.security.authorizationPolicy.enabled }}
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: {{ .Values.serviceName }}
# This continues with more yaml
{{- end }}
The values.yaml has security.authorizationPolicy.enabled which is set to false when I don't want to include an authorization-policy resource and it is set to true when I do want that resource.
When the enabled switch is set to false I get a exit status 1; Error: could not find template templates/authorization-policy.yaml in chart.
I was actually wanting the rendering to fail if I set the enabled switch to disabled and then I could assert that the render failed or that it produced an empty string or something similar, but this error is sort of wrong? It would indicate to me that the yaml template doesn't exist within the chart at all.
To Reproduce
Here's the part of my code where I set the enabled switch option and then attempt to get the Helm output for the template:
I imagine that this could be reproduced with any kubernetes resource, you just need to have an enabled switch at the top of the yaml template.
Expected behavior
When I realised why this was erroring, it sort of made sense, clearly the yaml template is not rendered because the switch is not enabled, but the error message is confusing. I think it would be better if this error message stated that the Helm template was rendered successfully, but the output was nothing, or empty, or something else indicating that the render itself worked, but no output was produced.
In the helm helm-unittest plugin it is possible to perform this kind of assertion using the hasDocuments assertion (see assertion types here).
For now, I am just going to use helm.RenderTemplateE and assert the error, because I know for a fact that the yaml template is there and my other tests will prove this when I set the switch to enabled, but I do think that a new error should be created to more effectively state what is wrong with the test, or this functionality should be implemented that allows you to assert that no documents were generated in the Helm output.
Here is some code and terminal screenshots to help show what I am describing:
Context("enabled switch", func() {
It("should not render when set to 'disabled'", func() {
options := &helm.Options{ SetValues: map[string]string{ "security.authorizationPolicy.enabled": "true" }} # This value is what is modified
output := helm.RenderTemplate(GinkgoT(), options, helmChartPath, "authorization-policy", []string{"templates/authorization-policy.yaml"})
outputNoSourceString := regexp.ReplaceAllString(output, "")
helm.UnmarshalK8SYaml(GinkgoT(), outputNoSourceString, &authorizationPolicy)
})
})
Describe the bug
I have a template yaml that uses an enabled switch in the values.yaml that determines if the template should be rendered or not:
The values.yaml has
security.authorizationPolicy.enabled
which is set to false when I don't want to include an authorization-policy resource and it is set to true when I do want that resource.When the enabled switch is set to false I get a
exit status 1; Error: could not find template templates/authorization-policy.yaml in chart
.I was actually wanting the rendering to fail if I set the enabled switch to disabled and then I could assert that the render failed or that it produced an empty string or something similar, but this error is sort of wrong? It would indicate to me that the yaml template doesn't exist within the chart at all.
To Reproduce
Here's the part of my code where I set the enabled switch option and then attempt to get the Helm output for the template:
I imagine that this could be reproduced with any kubernetes resource, you just need to have an enabled switch at the top of the yaml template.
Expected behavior
When I realised why this was erroring, it sort of made sense, clearly the yaml template is not rendered because the switch is not enabled, but the error message is confusing. I think it would be better if this error message stated that the Helm template was rendered successfully, but the output was nothing, or empty, or something else indicating that the render itself worked, but no output was produced.
In the helm
helm-unittest
plugin it is possible to perform this kind of assertion using thehasDocuments
assertion (see assertion types here).For now, I am just going to use
helm.RenderTemplateE
and assert the error, because I know for a fact that the yaml template is there and my other tests will prove this when I set the switch to enabled, but I do think that a new error should be created to more effectively state what is wrong with the test, or this functionality should be implemented that allows you to assert that no documents were generated in the Helm output.Here is some code and terminal screenshots to help show what I am describing:
When the enabled switch is true:
When the enabled switch is false:
Nice to have
Versions
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: