How to pass param file when applying a new yaml

1.8k views Asked by At

I am on on openshift 4.6. I want to pass parameters when to a yaml file so i tried the below code but it threw an error

oc apply -f "./ETCD Backup/etcd_backup_cronjob.yaml" --param master-node = oc get nodes -o name |  grep "master-0" | cut -d'/' -f2

Error: unknown flag --param

1

There are 1 answers

0
Simon On BEST ANSWER

What you most likely want to use is OpenShift Templates. Using Templates you can have variables in your YAML files and then change them using oc process.

So your YAML would look like so:

kind: Template
apiVersion: v1
metadata:
  name: my-template
objects:
  - apiVersion: batch/v1beta1
    kind: CronJob
    metadata:
      name: pi
    spec:
      schedule: "*/1 * * * *"  
      concurrencyPolicy: "Replace" 
      startingDeadlineSeconds: 200 
      suspend: true            
      successfulJobsHistoryLimit: 3 
      failedJobsHistoryLimit: 1     
      jobTemplate:             
        spec:
          template:
            metadata:
              labels:          
                 parent: "cronjobpi"
            spec:
              containers:
              - name: pi
                image: perl
                command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(${{DIGITS}})"]
              restartPolicy: OnFailure 
parameters:
  - name: DIGITS 
    displayName: Number of digits 
    description: Digits to compute
    value: 200 
    required: true

Then you can use oc process like so:

oc process my-template.yml --param=DIGITS=300 | oc apply -f -