kubernetes-client/java:Scale报错400 BadRequest 或 500 cannot unmarshal object

问题现象

使用kubernetes-client/java 对 Deployment、ReplicaSet或者StatefulSet 进行Scale(手动扩缩容),修改实例数

客户端版本

<!--k8s-->
<dependency>
    <groupId>io.kubernetes</groupId>
    <artifactId>client-java</artifactId>
    <version>6.0.1</version>
    <!--<scope>compile</scope>-->
</dependency>

操作实例 StatefulSet

@Test
    public void AppsV1ApiTest(){
        AppsV1Api apiInstance = new AppsV1Api();

        String jsonPatchStr = "{\"op\":\"replace\",\"path\":\"/spec/replicas\", \"value\": " + 2 + " }";
        V1Patch patch = new V1Patch(jsonPatchStr);
        
        try {
            apiInstance.patchNamespacedStatefulSet("资源名称", "分区名称", patch, "false", null, null, null);
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }

报错信息

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"json: cannot unmarshal object into Go value of type jsonpatch.Patch","code":500}

操作实例 Deployment

@Test
    public void ExtensionsApiTest(){
        ExtensionsV1beta1Api apiInstance = new ExtensionsV1beta1Api();
        String jsonPatchStr = "{\"op\":\"replace\",\"path\":\"/spec/replicas\", \"value\": " + 2 + " }";
        V1Patch patch = new V1Patch(jsonPatchStr);
        try {
            ApiResponse<ExtensionsV1beta1Scale> apiResponse = apiInstance.
                    patchNamespacedDeploymentScaleWithHttpInfo("资源名称",
                            "分区名称", patch, "false", null, null, null);
        } catch (ApiException e) {
            e.printStackTrace();
        }
    }

报错信息

问题分析:

使用jsonpatch 更新或修改一个资源对象时,需要是数组形式,不能是一个对象

问题解决:

new V1Patch(jsonPatchStr)的内容,改为数组格式

String jsonPatchStr = "[{\"op\":\"replace\",\"path\":\"/spec/replicas\", \"value\": " + 2 + " }]";

JSON Patch讲解

原始内容

{
  "baz": "qux",
  "foo": "bar"
}

通过JSONPath操作

[
  { "op": "replace", "path": "/baz", "value": "boo" },
  { "op": "add", "path": "/hello", "value": ["world"] },
  { "op": "remove", "path": "/foo" }
]

输出结果

{
  "baz": "boo",
  "hello": ["world"]
}

测试JSONPath还支持

Copy(复制

{ "op": "copy", "from": "/biscuits/0", "path": "/best_biscuit" }

将值从JSON文档中的一个位置复制到另一个位置。这两个frompath是JSON指针。

Move(移动

{ "op": "move", "from": "/biscuits", "path": "/cookies" }

将值从一个位置移动到另一位置。这两个frompath是JSON指针。

Test(测试

{ "op": "test", "path": "/best_biscuit/name", "value": "Choco Leibniz" }

测试是否在文档中设置了指定的值。如果测试失败,则整个补丁都不适用。

 

参考链接:

 

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
2 400 index.vue:399 QiniuRequestError {name: 'RequestError', message: 'xhr request failed, code: 400 response: {"error":"…field CompleteMultipart.mimeType of type string"}', stack: 'Error\n at QiniuRequestError.QiniuError (webpack…node_modules/qiniu-js/esm/utils/helper.js:248:24)', code: 400, reqId: 'Mm0AAACDvvroC2YX', …} code : 400 data : error : "json: cannot unmarshal array into Go struct field CompleteMultipart.mimeType of type string" [[Prototype]] : Object constructor : ƒ Object() hasOwnProperty : ƒ hasOwnProperty() isPrototypeOf : ƒ isPrototypeOf() propertyIsEnumerable : ƒ propertyIsEnumerable() toLocaleString : ƒ toLocaleString() toString : ƒ toString() valueOf : ƒ valueOf() __defineGetter__ : ƒ __defineGetter__() __defineSetter__ : ƒ __defineSetter__() __lookupGetter__ : ƒ __lookupGetter__() __lookupSetter__ : ƒ __lookupSetter__() __proto__ : (...) get __proto__ : ƒ __proto__() set __proto__ : ƒ __proto__() isRequestError : true message : "xhr request failed, code: 400 response: {\"error\":\"json: cannot unmarshal array into Go struct field CompleteMultipart.mimeType of type string\"}" name : "RequestError" reqId : "Mm0AAACDvvroC2YX" stack : "Error\n at QiniuRequestError.QiniuError (webpack-internal:///./node_modules/qiniu-js/esm/errors/index.js:47:22)\n at new QiniuRequestError (webpack-internal:///./node_modules/qiniu-js/esm/errors/index.js:55:28)\n at xhr.onreadystatechange (webpack-internal:///./node_modules/qiniu-js/esm/utils/helper.js:248:24)" [[Prototype]] : QiniuError constructor : ƒ QiniuRequestError(code, reqId, message, data) [[Prototype]] : Object
06-07

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

琦彦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值