0

I want to pass parameter dynamically while patching any deployment config

oc patch dc/action-msa -p "$(cat msa-patch.yml)" --param service_account=msa-service-account

  spec:
     template:
       spec:
       serviceAccountName: ${service_account}
       restartPolicy: "Always"

       initContainers:
         - name: vault-init
           image: ${init_container_image}
           imagePullPolicy: Always
       containers:
        - name: ${SERVICE_NAME}-java-service
          image: ${main_container_image}

Is there any option or way to pass service_account, init_container_image and service_name dynamically while patching using openshift oc?

1 Answers1

0

You would need template layer for this solution such as Kustomize, HELM and etc. Or you can use environment file as a source before deploying your yaml files something like below

Your deployment.yaml looks like this:

  spec:
     template:
       spec:
       serviceAccountName: {{service_account}}
       restartPolicy: "Always"

       initContainers:
         - name: vault-init
           image: {{init_container_image}}
           imagePullPolicy: Always
       containers:
        - name: {{SERVICE_NAME}}
          image: {{main_container_image}}

your env.file looks like this:

service_account="some_account"
init_container_image="some_image"
SERVICE_NAME="service_name"

Then run

oc patch dc/action-msa -p \
"$(source env.file && cat deployment.yml  | \
sed "s/{{service_account}}/service_account/g"| \
sed "s/{{init_container_image}}/init_container_image/g"| \
sed "s/{{SERVICE_NAME}}/SERVICE_NAME/g")" --param service_account=msa-service-account

Hope it helps

clxoid
  • 2,577
  • 12
  • 21