Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker how to use boolean value on spec.container.env.value

Is there a way to pass a boolean value for spec.container.env.value ? I want to override, with helm, a boolean env variables in a docker parent image (https://github.com/APSL/docker-thumbor) : UPLOAD_ENABLED

I made a simpler test

If you try the following yaml :

apiVersion: v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: gcr.io/google-samples/node-hello:1.0
    env:
    - name: DEMO_GREETING
      value: true

And try to create it with kubernetes, you got the following error :

kubectl create -f envars.yaml

the error :

error: error validating "envars.yaml": error validating data: expected type string, for field spec.containers[0].env[0].value, got bool; if you choose to ignore these errors, turn validation off with --validate=false

with validate=false

Error from server (BadRequest): error when creating "envars.yaml": Pod in version "v1" cannot be handled as a Pod: [pos 192]: json: expect char '"' but got char 't'

It doesn't work with integer values too

like image 843
Damien GOUYETTE Avatar asked Jun 21 '17 14:06

Damien GOUYETTE


People also ask

Can environment variables be Boolean?

Environment variables can never be a boolean, they are always a string (or not present).

How can I see environment variables in container?

Fetch Using docker exec Command Here, we are executing the /usr/bin/env utility inside the Docker container. Using this utility, you can view all the environment variables set inside Docker containers.


Video Answer


2 Answers

spec.container.env.value is defined as string. see here: https://kubernetes.io/docs/api-reference/v1.6/#envvar-v1-core

You'd have to cast/convert/coerse to boolean in your container when using this value

like image 56
Chen Fisher Avatar answered Oct 20 '22 15:10

Chen Fisher


Try escaping the value. The below worked for me:

- name: DEMO_GREETING
  value: "'true'"
like image 20
Ziemek Avatar answered Oct 20 '22 14:10

Ziemek