Reputation: 111
I'm trying to set multiline values (contents of a ca certificate file) to kustomize environment file for a particular key as displayed in the code below. Is there a way to achieve this?
Note: Adding quotes to the value in some_params.env isn't working.
kustomize.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
role: authentication
bases:
- ./somebase
configMapGenerator:
- name: some-parameters
env: some_params.env
vars:
- name: ca_contents
objref:
kind: ConfigMap
name: some-parameters
apiVersion: v1
fieldref:
fieldpath: data.ca_contents
configurations:
- some_params.yaml
some_params.yaml
varReference:
- path: data/ca.pem
kind: ConfigMap
some_params.env
ca_contents= |
-----BEGIN CERTIFICATE-----
YOUR CA CERTIFICATE CONTENTS
-----END CERTIFICATE-----
Running the following command:
kustomize build base
Returns:
Error: NewResMapFromConfigMapArgs: NewResMapFromConfigMapArgs: env source file: some_params.env: "-----BEGIN CERTIFICATE-----" is not a valid key name: a valid environment variable name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name', or 'MY_ENV.NAME', or 'MyEnvName1', regex used for validation is '[-._a-zA-Z][-._a-zA-Z0-9]*')
Upvotes: 8
Views: 7052
Reputation: 738
This answer comes a bit late, but it is the most up-to-date one as of 2024.
The official documentation recommends against using vars
as it is deprecated, and configMapGenerator
, secretGenerator
, and replacements
are considered to be a more modern approach in these cases1.
As such, a minimum reproducible example includes the following:
.
├── ca.key
├── ca.pem
└── kustomization.yml
And the contents:
# kustomization.yml
configMapGenerator:
- name: some-parameters
files:
- ca.pem
- ca.key
And the result of kustomize build
will be similar to this:
apiVersion: v1
data:
ca.key: |
-----BEGIN RSA PRIVATE KEY-----
YOUR RSA PRIVATE KEY CONTENTS
-----END RSA PRIVATE KEY-----
ca.pem: |
-----BEGIN CERTIFICATE-----
YOUR CA CERTIFICATE CONTENTS
-----END CERTIFICATE-----
kind: ConfigMap
metadata:
labels:
role: authentication
name: some-parameters-b9hkc26mct
In general, Kustomize will throw a deprecation warning in your CLI. It also instructs you to upgrade them using the built-in kustomize edit fix
for ease of migration.
Upvotes: 0
Reputation: 625
I think your problem is indentation. Kustomize thinks your some_params.env file consists of keys only. To be conformant with the YAML specification, multiline strings need to be indented by one tab. So some_params.env should look like this:
ca_contents= |
-----BEGIN CERTIFICATE-----
YOUR CA CERTIFICATE CONTENTS
-----END CERTIFICATE-----
If you want more details on multiline strings, have a look at these sources:
Upvotes: 0