首页 > 解决方案 > “oc进程”将特殊字符“&”和“>”转换为unicode

问题描述

我正在尝试使用以下模板创建 openshift 部署配置 -

$ 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

当使用“oc process”命令将此带有 CLAIM_NAME 参数的模板转换为 json 时,“&”和“>”将被转换为 unicode,如下所示

$ 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"
                    }
                ]
            }
        }
    ]
}

这里有两行 -

“虽然是真的;做 (mount | grep /mnt) \u0026\u0026 (head -c 1048576 \u003c /dev/urandom \u003e /mnt/random-data.log) || 退出 1; 睡眠 20 ; 完成”

“挂载 | grep /mnt \u0026\u0026 头 -c 1024 \u003c /dev/urandom \u003e\u003e /mnt/random-data.log”

有什么办法可以避免这种转换?

标签: kubernetesopenshiftopenshift-3

解决方案


推荐阅读