Javascript 如何正确格式化和发送应用程序/json修补程序+;json

Javascript 如何正确格式化和发送应用程序/json修补程序+;json,javascript,node.js,kubernetes,webhooks,Javascript,Node.js,Kubernetes,Webhooks,我正在尝试使用Godaddy的K8s客户端来修补CRD 以下是我尝试过的: 直接翻译他们的例子: const patchService = await client.apis["serving.knative.dev"].v1alpha1.namespaces('default').services.patch({body: { "spec": { "template": {

我正在尝试使用Godaddy的K8s客户端来修补CRD

以下是我尝试过的:

直接翻译他们的例子:

                const patchService = await client.apis["serving.knative.dev"].v1alpha1.namespaces('default').services.patch({body: {
                  "spec": {
                    "template": {
                      "spec": {
                        "containers": [
                          {
                            "image": "docker.io/quantomworks/mcsh-site:" + build.metadata.annotations['hook-to-k8s']
                          }
                        ]
                      }
                    }
                  }
                }})

                console.log("Patch result:")
                console.log(patchService)
手动创建服务修补程序对象

获取一个yaml文件,我可以使用与成功的
kubectl修补程序services.service.knative.dev mcserverhosting网站匹配的内容运行该文件--键入json-p

- op: replace
  path: /spec/runLatest/configuration/revisionTemplate/spec/container/image
  value: docker.io/quantomworks/mcsh-site:latest
然后直接发布

const patchService = await client.apis["serving.knative.dev"].v1alpha1.namespaces('default').services('mcserverhosting-net-site').patch(servicePatch)
所有这些都会导致以下错误:

node-webhook┊ (node:17) UnhandledPromiseRejectionWarning: Error: the body of the request was in an unknown format - accepted media types include: application/json-patch+json, application/merge-patch+json
node-webhook┊     at /usr/src/app/node_modules/kubernetes-client/lib/backends/request.js:189:25
node-webhook┊     at Request._callback (/usr/src/app/node_modules/kubernetes-client/lib/backends/request.js:148:14)
node-webhook┊     at Request.self.callback (/usr/src/app/node_modules/request/request.js:185:22)
node-webhook┊     at Request.emit (events.js:196:13)
node-webhook┊     at Request.<anonymous> (/usr/src/app/node_modules/request/request.js:1161:10)
node-webhook┊     at Request.emit (events.js:196:13)
node-webhook┊     at IncomingMessage.<anonymous> (/usr/src/app/node_modules/request/request.js:1083:12)
node-webhook┊     at Object.onceWrapper (events.js:284:20)
node-webhook┊     at IncomingMessage.emit (events.js:201:15)
node-webhook┊     at endReadableNT (_stream_readable.js:1130:12)
node-webhook┊ (node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with
.catch(). (rejection id: 2)
节点webhook┊ (节点:17)未经处理的PromisejectionWarning:错误:请求正文的格式未知-接受的媒体类型包括:application/json patch+json、application/merge patch+json
节点webhook┊     at/usr/src/app/node_modules/kubernetes client/lib/backends/request.js:189:25
节点webhook┊     应请求。\回调(/usr/src/app/node\u modules/kubernetes-client/lib/backends/Request.js:148:14)
节点webhook┊     at Request.self.callback(/usr/src/app/node_modules/Request/Request.js:185:22)
节点webhook┊     at Request.emit(events.js:196:13)

节点webhook┊ 应要求

这不是一个完整的答案,而是另一个选择。切换了
put
而不是
patch
<代码>kubectl应用
等效值。还知道我没有为API类型
services.service.knative.dev
修改规范版本,但是这已经完成了,撤销了,然后在代码中重新更正。还是不接受我给它的任何东西。一个更干净的解决方案会更好。目前必须以这种方式增加
[ResourceVersion][1]
,这还不错。

这不是一个完整的答案,而是一个替代方案。切换了
put
而不是
patch
<代码>kubectl应用等效值。还知道我没有为API类型
services.service.knative.dev
修改规范版本,但是这已经完成了,撤销了,然后在代码中重新更正。还是不接受我给它的任何东西。一个更干净的解决方案会更好。目前必须以这种方式递增
[ResourceVersion][1]
,这还不错。

我注意到,在他们的示例中,对象字段是不带引号的:
body:{spec:{template:{spec:{containers
,而在您的实现中,您引用了字段:
{body:{“spec”:{“template”:{“spec”:{“containers”:[
这会导致问题吗?这不起作用。我注意到,在他们的示例中,对象字段是不带引号的:
body:{spec:{template:{spec:{containers
在您的实现中,您引用了以下字段:
{body:{“spec”:{“template”:{“spec”:{“containers”:[
这会导致问题吗?这不起作用。
node-webhook┊ (node:17) UnhandledPromiseRejectionWarning: Error: the body of the request was in an unknown format - accepted media types include: application/json-patch+json, application/merge-patch+json
node-webhook┊     at /usr/src/app/node_modules/kubernetes-client/lib/backends/request.js:189:25
node-webhook┊     at Request._callback (/usr/src/app/node_modules/kubernetes-client/lib/backends/request.js:148:14)
node-webhook┊     at Request.self.callback (/usr/src/app/node_modules/request/request.js:185:22)
node-webhook┊     at Request.emit (events.js:196:13)
node-webhook┊     at Request.<anonymous> (/usr/src/app/node_modules/request/request.js:1161:10)
node-webhook┊     at Request.emit (events.js:196:13)
node-webhook┊     at IncomingMessage.<anonymous> (/usr/src/app/node_modules/request/request.js:1083:12)
node-webhook┊     at Object.onceWrapper (events.js:284:20)
node-webhook┊     at IncomingMessage.emit (events.js:201:15)
node-webhook┊     at endReadableNT (_stream_readable.js:1130:12)
node-webhook┊ (node:17) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with
.catch(). (rejection id: 2)