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

Helm testing: Cannot map configmap.data correctly when using a Literal Block Scalar #1335

Open
Mo0rBy opened this issue Aug 31, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Mo0rBy
Copy link

Mo0rBy commented Aug 31, 2023

I think this is probably a bug with Kubernetes go-client rather than TerraTest, but I think it's valuable to post it here for other users.

I have a configmap helm template that should produce an output that looks something like this:

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: release-name
  name: release-name
data:
  thisIsSomeDataKey: |
    configmap-data-value-1;
    configmap-data-value-2;

You can see that I am using a "Literal Block Scalar" (search the term here to see more info) for my key thisIsSomeDataKey.

I am rendering my template and then unmarshalling the result into ConfigMap object:

var configmap v1.ConfigMap

options := &helm.Options{
	ValuesFiles: []string{"values/required.yaml"},
	BuildDependencies: true,
}

renderedOutput := helm.RenderTemplate(GinkgoT(), options, helmChartPath, microService, []string{"templates/configmap.yaml"})
helm.UnmarshalK8SYaml(GinkgoT(), renderedOutput, &configmap)

But I can see the output of the template in my console log and the configmap.data values are not present. When performing a manual helm template --debug command, I can see these values in the output template as expected.

Output of the TerraTest helm unmarshal (I also added a print statement to just see what the value was as well)

logger.go:66: apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: sir-webapp
  name: sir-webapp
data:
  thisIsSomeDataKey: |                        // The values should be seen here
configmap_test.go:42: map[thisIsSomeDataKey:]

Output of a manual helm template command:

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: release-name
  name: release-name
data:
  thisIsSomeDataKey: |
    configmap-data-value-1;      // The values can be seen, as expected
    configmap-data-value-2;

As I said, I think this might be an issue with the unmarshalling, as the ConfigMap.Data field is supposed to be a map[string]string, and using the "Literal Block Scalar" means that this is a bit confusing. Reading the documentation I linked to above, it seems like I should have 1 value, that spans multiple lines, so I would need to include newline characters, however, printing out the value of ConfigMap.Data["thisIsSomeDataKey"] shows that it has no value at all.

Versions

  • Terratest version: v0.43.13
  • Environment details: MacOS Ventura 13.5.1

Additional context
If this should be posted somewhere else as a Kubernetes bug, can you tell me where the best place would be please.

@Mo0rBy Mo0rBy added the bug Something isn't working label Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant