json 的 Kubectl 补丁在 Cloud Build 上失败
Kubectl patch with json fails on Cloud Build
我可以使用 kubectl 运行 从 cli 修补我的入口资源,命令如下:
kubectl patch ingress ingress-resource --type=json -p='[{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/service/name", "value":"node-app-blue-helm-chart"}]'
当我将以下步骤添加到 cloudbuild.yaml 并执行时,它失败并出现以下错误。
Step #3: Running: kubectl patch ingress ingress-resource --type=json -p='[{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/service/name", "value":"node-app-blue-helm-chart"}]'
Step #3: Error from server (BadRequest): json: cannot unmarshal string into Go value of type jsonpatch.Patch
Finished Step #3
我使用的步骤:
- name: 'gcr.io/cloud-builders/kubectl'
args:
- 'patch'
- 'ingress'
- 'ingress-resource'
- '--type=json'
- '-p=''[{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/service/name", "value":"node-app-green-helm-chart"}]'' '
env:
- 'CLOUDSDK_COMPUTE_ZONE=----'
- 'CLOUDSDK_CONTAINER_CLUSTER=----'
什么可以缺少?
为了解决这个问题,我尝试像这里提到的那样转义所有“”()。它没有解决问题。但后来我也划分了“-p”和其余部分,并且还使用了“第二部分。于是工作步骤变成了这样:
- name: 'gcr.io/cloud-builders/kubectl'
args:
- "patch"
- "ingress"
- "ingress-resource"
- "--type=json"
- "-p"
- "[{\"op\": \"replace\", \"path\": \"/spec/rules/0/http/paths/0/backend/service/name\", \"value\":\"node-app-green-helm-chart\"}]"
env:
- 'CLOUDSDK_COMPUTE_ZONE=----'
- 'CLOUDSDK_CONTAINER_CLUSTER=----'
我可以使用 kubectl 运行 从 cli 修补我的入口资源,命令如下:
kubectl patch ingress ingress-resource --type=json -p='[{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/service/name", "value":"node-app-blue-helm-chart"}]'
当我将以下步骤添加到 cloudbuild.yaml 并执行时,它失败并出现以下错误。
Step #3: Running: kubectl patch ingress ingress-resource --type=json -p='[{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/service/name", "value":"node-app-blue-helm-chart"}]'
Step #3: Error from server (BadRequest): json: cannot unmarshal string into Go value of type jsonpatch.Patch
Finished Step #3
我使用的步骤:
- name: 'gcr.io/cloud-builders/kubectl'
args:
- 'patch'
- 'ingress'
- 'ingress-resource'
- '--type=json'
- '-p=''[{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/service/name", "value":"node-app-green-helm-chart"}]'' '
env:
- 'CLOUDSDK_COMPUTE_ZONE=----'
- 'CLOUDSDK_CONTAINER_CLUSTER=----'
什么可以缺少?
为了解决这个问题,我尝试像这里提到的那样转义所有“”(
- name: 'gcr.io/cloud-builders/kubectl'
args:
- "patch"
- "ingress"
- "ingress-resource"
- "--type=json"
- "-p"
- "[{\"op\": \"replace\", \"path\": \"/spec/rules/0/http/paths/0/backend/service/name\", \"value\":\"node-app-green-helm-chart\"}]"
env:
- 'CLOUDSDK_COMPUTE_ZONE=----'
- 'CLOUDSDK_CONTAINER_CLUSTER=----'