8000 Export configmap should convert numerical and boolean values to string first · Issue #718 · configu/configu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Export configmap should convert numerical and boolean values to string first #718

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

Open
dipsywong98 opened this issue Mar 6, 2025 · 2 comments · May be fixed by #719
Open

Export configmap should convert numerical and boolean values to string first #718

dipsywong98 opened this issue Mar 6, 2025 · 2 comments · May be fixed by #719
Labels
community feat New feature or request triage The issue is new and needs to be triaged by a maintainer

Comments

@dipsywong98
Copy link

Suggestion

Hi team, thanks for the nice project and we are trying to use configu to manage our configs in k8s deployments! However, we start seeing some issues when trying to adopt configu and this is a major one

Kubenetes config maps expect all values to be string, but configu has some type conversion to make numerical string into number and booleanic string to Boolean, but as the formatter is just putting the values as it is, so it will output config map with non string value. I could not find a way to stop this type convertion.

For example with this example.cfgu.yaml

$schema: 'https://files.configu.com/schema/.cfgu.json'
keys:
  NUM:
    default: 123
  BOOL:
    default: true
  NUM_S:
    default: '123'
  BOOL_S:
    default: 'true'
  STRING:
    default: 'some-string'
  STRING_SPACE:
    default: 'some string'

and run configu eval | configu export --format config-map, I will expect it to give

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: 2025-03-06T15:35:24.271Z
data:
  NUM: '123'
  BOOL: 'true'
  NUM_S: '123'
  BOOL_S: 'true'
  STRING: some-string
  STRING_SPACE: some string

but actually, it is

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: 2025-03-06T15:35:24.271Z
data:
  NUM: 123
  BOOL: true
  NUM_S: 123
  BOOL_S: true
  STRING: some-string
  STRING_SPACE: some string

I have also try some work around - export to dotenv and use kubectl to create configmap from dotenv file, but this does not work. Reusing the same example, configu eval | configu export --format dotenv > my.env will give

NUM=123
BOOL=true
NUM_S=123
BOOL_S=true
STRING=some-string
STRING_SPACE="some string"

Then convert to config map using kubectl create configmap my-config --from-env-file=my.env --dry-run -o yaml

apiVersion: v1
data:
  BOOL: "true"
  BOOL_S: "true"
  NUM: "123"
  NUM_S: "123"
  STRING: some-string
  STRING_SPACE: '"some string"'
kind: ConfigMap
metadata:
  creationTimestamp: null
  name: my-config

Looks like it can solve the above two points, have name and all values are string, but the value of STRING_SPACE now got extra quotes. It is due to k8s considers the quote in env file as part of the literal, and maintainer expects the env to have the quotes removed at the first place instead of assuming k8s will remove it. (Maybe can also consider removing the extra quotes in dotenv export?)

kubernetes-sigs/kustomize#4525 (comment)

https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-files

So the only "working" workaround for putting bool/number value to configmap is putting extra quotes

$schema: 'https://files.configu.com/schema/.cfgu.json'
keys:
  NUM_SS:
    default: '"123"'
  BOOL_SS:
    default: '"true"'

can give

apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: 2025-03-06T15:50:18.155Z
data:
  NUM_SS: "123"
  BOOL_SS: "true"

However this workaround will leads to extra quote when outputting in other format, which I dont think is a proper way to solve the problem. So to really make the configmap export work nicely, I think configu need to convert the values to string before putting them into the yaml file, as no one would expect number and boolean value in a config map.

I have a quick implementation for this, will submit PR shortly.

Motivation

No response

Context

No response

@dipsywong98 dipsywong98 added the feat New feature or request label Mar 6, 2025
@github-actions github-actions bot added triage The issue is new and needs to be triaged by a maintainer community labels Mar 6, 2025
@dipsywong98
Copy link
Author
dipsywong98 commented Mar 7, 2025

Update: my colleague is so strong that he find that export to ini format will not generate the extra quote for string value that contains space.

So for now anyone facing the same problem can use the below script (at least working at the moment of writing)

configu eval | configu export --format ini > my.env
kubectl create configmap my-config --from-env-file=my.env --dry-run -o yaml

@rannn505
Copy link
Contributor
rannn505 commented Mar 16, 2025

Thanks for bringing this up @dipsywong98! I totally agree we should standardize the config-map formatter, and we'll address this ASAP. I reviewed your PR (#719)—thanks for submitting! While it provides a quick fix, I'd suggest involving the official Kubernetes SDK to ensure full alignment with the Kubernetes specification.

Meanwhile, as a workaround, you can leverage Configu’s built-in export --template feature to control exactly how your ConfigMaps are formatted.

Here's a quick example:

myconfigmap.tmpl.yaml (Inspired by the official Kubernetes docs)

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ $.configs.ConfigMapName.value }}
data:
{{ _.chain($.configs).map(({ key, value }) => `  ${key}: "${value}"`).join('\n').value() }}

myschema.cfgu.yaml

$schema: https://files.configu.com/schema/.cfgu.json
keys:
  ConfigMapName:
    default: 'myconfigmap'
  NUM:
    default: '123'

Then generate the ConfigMap YAML:

configu eval ... | configu export --template './myconfigmap.tmpl.yaml' > ./myconfigmap.yaml

This gives you immediate control over formatting while we properly fix the built-in formatter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community feat New feature or request triage The issue is new and needs to be triaged by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0