terratest icon indicating copy to clipboard operation
terratest copied to clipboard

Helm chart testing allows duplicate metadata labels

Open Mo0rBy opened this issue 8 months ago • 0 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: Screenshot 2023-10-26 at 10 14 47

And here is my k9s output showing that Helm is unable to install the chart due to the duplicate label: Screenshot 2023-10-26 at 10 20 17

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.

Mo0rBy avatar Oct 26 '23 09:10 Mo0rBy