Helm chart testing allows duplicate metadata labels
Mo0rBy opened this issue · comments
Describe the bug
I accidentally had a duplicate label in my deployment.yaml template and TerraTest was still able to unmarshal it into a k8s Deployment struct. Because of this, my template tests passed and this chart was deployed into my cluster, where the chart was not able to install. Should this be allowed?
One of the really useful features of unmarshaling into a k8s struct means that the template is tested to see if kubernetes can actually read the template and can use it as a k8s object. Here is the console output of Terratest showing this duplicate label and that it was unmarshaled with no errors:
And here is my k9s output showing that Helm is unable to install the chart due to the duplicate label:
To Reproduce
Create a deployment.yaml template with a duplicate mapping in the spec.template.metadata.labels
section.
Use TerraTest's helm.UnmarshalK8SYaml()
function to unmarshal the template into a k8s deployment struct.
Deploy the chart to a cluster and see the installation fail due to duplicate key.
Here is a snippet of my render template and unmarshal steps:
BeforeAll(func() {
options := &helm.Options{
ValuesFiles: []string{"values/required.yaml"},
}
renderedOutput := helm.RenderTemplate(GinkgoT(), options, helmChartPath, microService, []string{"templates/deployment.yaml"})
helm.UnmarshalK8SYaml(GinkgoT(), renderedOutput, &deployment)
})
Expected behavior
I would expect the helm.UnmarshalK8SYaml()
to result in a failure due to the duplicate key mapping in the deployment.yaml template as this is what happens when the Helm chart is deployed into a cluster.
Nice to have
- [ x ] Terminal output
- [ x ] Screenshots
Versions
- Terratest version: v0.43.13
- Environment details A custom Linux ci-build-tools image + M1 MacOS Ventura 13.6
Additional context
Add any other context about the problem here.