oc/kubectl 补丁替换整行

oc/kubectl patch replaces whole line

我正在使用 oc 补丁和 op 来替换部署中的一个字符串,命令如下:-

oc patch dc abc --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "ab-repository/" },{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "bc-repository/" }]'

它正在做什么,它的变化如下:-

Before:- ab-repository/ab:1.0.0
After:- bc-repository/

我要的是这个:-

Before:- ab-repository/ab:1.0.0
After:- bc-repository/ab:1.0.0

请告诉我我做错了什么。

下面是 YAML

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  name: ruleengine
  namespace: apps
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    name: ruleengine
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      creationTimestamp: null
      labels:
        name: ruleengine
    spec:
      containers:
      - image: ab-repository/ab:1.0.0 ### containers should be provided in the form of an array

replace”操作的工作方式类似于 remove/add 整个值:

This operation is functionally identical to a "remove" operation for a value, followed immediately by an "add" operation at the same location with the replacement value.

没有 JSON 部分替换值的补丁操作 (RFC6902, RFC7386)

您可以获得如下图像:

oc get dc ruleengine -o=jsonpath='{..image}'

然后用sed操作这个值,用在'oc patch'