Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Boolean parameter values are not passed properly to oc process #115

Closed
tiwillia opened this issue Jan 17, 2020 · 1 comment · Fixed by #116
Closed

Boolean parameter values are not passed properly to oc process #115

tiwillia opened this issue Jan 17, 2020 · 1 comment · Fixed by #116
Labels

Comments

@tiwillia
Copy link

Boolean parameter values are not properly passed to oc process.

If I have the following parameters specified in a saasherder service config:

paramters:
  SUSPEND_CRON: "true"

And the following template is used with a parameter that is interpolated as a non-string boolean parameter in the cronjob spec:

---
kind: Template
apiVersion: v1
metadata:
  name: bug-tester-template
  annotations:
    description: Test bug where booleans are being interpolated with quotes using non-string interpolation
labels:
  template: bug-tester-template
parameters:
  - name: SUSPEND_CRON
    description: "Suspend a cron job, requires boolean true/false"
    required: true
objects:
  - kind: CronJob
    apiVersion: batch/v1beta1
    metadata:
      name: bug-tester-cron
      labels:
        app: bug-tester-cron
    spec:
      suspend: ${{SUSPEND_CRON}}
      jobTemplate:
        spec:
          template:
            spec:
              containers:
              - name: bug-tester
                image: centos/centos
                command:
                - echo "cron ran"

Saasherder generates the oc process command similar to the following:

oc process --local --output yaml -f templates/bug-template.yml SUSPEND_CRON=True

Note that the value is True, not true as specified in the saasherder config.

The process command succeeds, but results in an invalid cron definition:

error: error validating "STDIN": error validating data: [ValidationError(CronJob.spec.suspend): invalid ValidationError(CronJob.spec.suspend): invalid type for io.k8s.api.batch.v1beta1.CronJobSpec.suspend: got "string", expected "boolean"]; if you choose to ignore these errors, turn validation off with --validate=false

The resulting suspend field in the cron object looks like:

"suspend": "True"

When running the same oc process command with SUSPEND_CRON=true rather than SUSPEND_CRON=True, the parameter is correctly recognized as a non-string parameter:

"suspend": true
@maorfr
Copy link
Contributor

maorfr commented Jan 18, 2020

We need to add a check here:
https://github.com/openshiftio/saasherder/blob/master/saasherder/saasherder.py#L347

Something super simple, like:

if val is True:
    val ='true'
elif val is False:
    val = 'false'

I'll fix this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants