"oc process" converting special characters "&" and ">" into unicode

5/13/2019

I am trying to create openshift deployment config using below template -

$ cat test-template.yaml
apiVersion: template.openshift.io/v1
kind: Template
metadata:
  annotations:
    description: This pod will run IO on underlined PVC.
  name: cirros-with-io
objects:
- kind: 'DeploymentConfig'
  apiVersion: 'v1'
  metadata:
    name: test-dc
  spec:
    template:
      metadata:
        labels:
          name: test-dc
      spec:
        restartPolicy: 'Always'
        volumes:
        - name: 'cirros-vol'
          persistentVolumeClaim:
            claimName: ${CLAIM_NAME}
        containers:
        - name: 'cirros'
          image: 'cirros'
          imagePullPolicy: 'IfNotPresent'
          volumeMounts:
          - mountPath: '/mnt'
            name: 'cirros-vol'
          command: ['sh']
          args:
          - '-ec'
          - 'while true; do
                 (mount | grep /mnt) && (head -c 1048576 < /dev/urandom > /mnt/random-data.log) || exit 1;
                 sleep 20 ;
             done'
          livenessProbe:
            exec:
              command:
              - 'sh'
              - '-ec'
              - 'mount | grep /mnt && head -c 1024 < /dev/urandom >> /mnt/random-data.log'
            initialDelaySeconds: 3
            periodSeconds: 3
    replicas: 1
    triggers:
      - type: 'ConfigChange'
    paused: false
    revisionHistoryLimit: 2
parameters:
- description: Name of the PVC
  displayName: PVC Name
  name: CLAIM_NAME
  required: true

when converting this template with CLAIM_NAME parameter to json using "oc process" command, "&" and ">" are getting converted into unicodes as below

$ oc process -f test-template.yaml CLAIM_NAME=claim01
{
    "kind": "List",
    "apiVersion": "v1",
    "metadata": {},
    "items": [
        {
            "apiVersion": "apps.openshift.io/v1",
            "kind": "DeploymentConfig",
            "metadata": {
                "name": "test-dc"
            },
            "spec": {
                "paused": false,
                "replicas": 1,
                "revisionHistoryLimit": 2,
                "template": {
                    "metadata": {
                        "labels": {
                            "name": "test-dc"
                        }
                    },
                    "spec": {
                        "containers": [
                            {
                                "args": [
                                    "-ec",
                                    "while true; do (mount | grep /mnt) \u0026\u0026 (head -c 1048576 \u003c /dev/urandom \u003e /mnt/random-data.log) || exit 1; sleep 20 ; done"
                                ],
                                "command": [
                                    "sh"
                                ],
                                "image": "cirros",
                                "imagePullPolicy": "IfNotPresent",
                                "livenessProbe": {
                                    "exec": {
                                        "command": [
                                            "sh",
                                            "-ec",
                                            "mount | grep /mnt \u0026\u0026 head -c 1024 \u003c /dev/urandom \u003e\u003e /mnt/random-data.log"
                                        ]
                                    },
                                    "initialDelaySeconds": 3,
                                    "periodSeconds": 3
                                },
                                "name": "cirros",
                                "volumeMounts": [
                                    {
                                        "mountPath": "/mnt",
                                        "name": "cirros-vol"
                                    }
                                ]
                            }
                        ],
                        "restartPolicy": "Always",
                        "volumes": [
                            {
                                "name": "cirros-vol",
                                "persistentVolumeClaim": {
                                    "claimName": "claim01"
                                }
                            }
                        ]
                    }
                },
                "triggers": [
                    {
                        "type": "ConfigChange"
                    }
                ]
            }
        }
    ]
}

Here the two lines -

"while true; do (mount | grep /mnt) \u0026\u0026 (head -c 1048576 \u003c /dev/urandom \u003e /mnt/random-data.log) || exit 1; sleep 20 ; done"

"mount | grep /mnt \u0026\u0026 head -c 1024 \u003c /dev/urandom \u003e\u003e /mnt/random-data.log"

Is there any way to avoid this conversion?

-- vsmahajan
kubernetes
openshift
openshift-3

0 Answers