简体   繁体   English

oc/kubectl 补丁替换整行

[英]oc/kubectl patch replaces whole line

I am using oc patch with op to replace one string in deployment, following is the command:-我正在使用带有 op 的 oc 补丁来替换部署中的一个字符串,以下是命令:-

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/" }]'

what it is doing is it changes below:-它正在做的是它在下面改变:-

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

what I want is this:-我想要的是这个:-

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

Please let me know what i am doing wrong here.请让我知道我在这里做错了什么。

Below is the YAML下面是 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

The ' replace ' operation works like remove/add entire value: 替换”操作的工作原理类似于删除/添加整个值:

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.此操作在功能上与对某个值的“删除”操作相同,紧接着是在与替换值相同的位置执行“添加”操作。

There's no such JSON patch operation as replace value partially ( RFC6902 , RFC7386 )没有像部分替换值这样的 JSON 补丁操作( RFC6902RFC7386

You can get image like:你可以得到像这样的图像:

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

Then manipulate the value with sed and use it in 'oc patch'然后用 sed 操作该值并在 'oc patch' 中使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM