Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy

  • 视频教程:https://shop57709059.taobao.com/
  • 版本信息:Rancher 1.6.26
  • 服务器IP地址:192.168.1.18
  • 请求内容(以CURL请求为例):
    curl -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" \
    -X POST \
    -H 'Accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{"inServiceStrategy":null, "toServiceStrategy":null}' \
    'http://develop.operate.jia-r.com:18080/v2-beta/projects/1a5/services/1s12/?action=upgrade'

     

错误提示:

{"id":"215634bf-4139-4106-aaa8-1d554c47b1a0","type":"error","links":{},"actions":{},"status":422,"code":"MissingRequired","message":null,"detail":null,"fieldName":"Upgrade strategy needs to be set","baseType":"error"}

注意:Upgrade strategy needs to be set

从该提示我们不难看出,当前的请求中,缺少必要的参数。但提示中并未明确指明是哪个位置缺少参数信息,针对该错误信息进行搜索相关错误信息,google查到的一个有提示性的内容:

Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy_第1张图片

由上图可以看出,在inServiceStrategy参数后面,是需要指定相关参数。查看了rancher的相关文档,该参数是用于指明调用upgrade操作的API时,需要指明调用的镜像名称、启动的策略(是否先启动新的容器再停止旧的容器)等

Thank You,  Google ~ 

 

好了,修改了请求参数 :{"inServiceStrategy": {"startFirst": true} }

再次发起请求(以CURL请求为例):

curl -u "${CATTLE_ACCESS_KEY}:${CATTLE_SECRET_KEY}" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"inServiceStrategy":{"startFirst": true}, "toServiceStrategy":null}' \
'http://develop.operate.jia-r.com:18080/v2-beta/projects/1a5/services/1s12/?action=upgrade'

 

错误提示:

{"id":"2faf41e2-69fc-4a62-96db-3aa40d8dca7e","type":"error","links":{},"actions":{},"status":422,"code":"InvalidOption","message":null,"detail":null,"fieldName":"LaunchConfig\/secondaryLaunchConfigs need to be specified for inService strategy","baseType":"error"}

 

注意:LaunchConfig secondaryLaunchConfigs need to be specified for inService strategy

经过google查找相关内容,文章只有为数不多的几篇,查看其中的解答,各种各样,但似乎没有非常完美的答复。Google搜索“rancher 1.6 api upgrade”的文章,看到了一篇官方给出的一个API调用upgrade的示例(如下图),答案已经很明显了,在Rancher 1.6中,调用upgrade接口需要设置inServiceStrategy的参数很多

https://rancher.com/docs/rancher/v1.5/en/api/v1/api-resources/service/

Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy_第2张图片

 

问题的原因已经找到了,需要将inServiceStrategy的参数都填写上,才能通过API调用rancher的upgrade接口。那么,这个inServiceStrategy的参数,在哪里找呢?

...

找了也挺久的,一直没有思路,不知道Rancher的这个参数放在哪里。偶然间,打开Rancher的管理界面,在升级选项所属菜单中看到“API查看”的菜单,这个... 是什么来的呢?

Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy_第3张图片

API查看菜单里,是这么一些内容:

Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy_第4张图片

仔细看看,再回想刚才的报错信息:secondaryLaunchConfigs need to be specified for inService strategy

Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy_第5张图片

 

找到了吧,这个“API查看”菜单中,存放着各种需要调用的接口信息。问题到这里,基本找到解决办法了。将upgrade中inServiceStrategy开头的参数都copy,覆盖掉之前的curl请求的inServiceStrategy配置。

Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy_第6张图片

 

执行curl命令,看到如下效果图,代表你已经成功了~

Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy_第7张图片

 

实际使用过程中,可能会遇到这个报错信息:

{"id":"873a73e3-b7a5-4b6d-80d3-9c2bffcd114a","type":"error","links":{},"actions":{},"status":400,"code":"InvalidBodyContent","message":"InvalidBodyContent","detail":null,"baseType":"error"}

 

注意:InvalidBodyContent

这个错误的字面意思很好理解,参数的内容中有错误,可具体是什么错误呢?

采用compare对比工具对比下正常的Curl请求和当前请求的区别,会看到这个地方dataVolumes多了个标记:3 items,这个是做什么用的?

从目前对比出来的差别来看,推测就是这个3 items多余导致了系统返回报错,删除3 items

Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy_第8张图片

修改后的内容如下图:

重新执行curl命令试试吧,Good Luck!

你可能感兴趣的:(Rancher调用API报错:secondaryLaunchConfigs need to be specified for inService strategy)