admin管理员组文章数量:1202334
I want to test a validating webhook with curl
.
There is a port-forwarding to that service via kubectl
.
I created capi-cluster.yaml
.
But this fails:
curl --insecure -X POST -H "Content-Type: application/json" \
--data-binary @capi-cluster.yaml \
https://127.0.0.1:9443/validate-cluster-x-k8s-io-v1beta1-cluster
{"kind":"Cluster","apiVersion":"cluster.x-k8s.io/v1beta1","response":{"uid":"","allowed":false,"status":{"metadata":{},"message":"unknown operation \"\"","code":400}}}
What needs to be changed to get it working?
I want to test a validating webhook with curl
.
There is a port-forwarding to that service via kubectl
.
I created capi-cluster.yaml
.
But this fails:
curl --insecure -X POST -H "Content-Type: application/json" \
--data-binary @capi-cluster.yaml \
https://127.0.0.1:9443/validate-cluster-x-k8s-io-v1beta1-cluster
{"kind":"Cluster","apiVersion":"cluster.x-k8s.io/v1beta1","response":{"uid":"","allowed":false,"status":{"metadata":{},"message":"unknown operation \"\"","code":400}}}
What needs to be changed to get it working?
Share Improve this question edited Jan 21 at 15:51 jonrsharpe 122k30 gold badges266 silver badges473 bronze badges asked Jan 21 at 15:48 guettliguettli 27.8k105 gold badges409 silver badges751 bronze badges1 Answer
Reset to default 0I found the answer:
I need to create a json file like this:
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1",
"request": {
"uid": "test-uid",
"kind": {
"group": "",
"version": "v1",
"kind": "Pod"
},
"resource": {
"group": "",
"version": "v1",
"resource": "pods"
},
"namespace": "default",
"operation": "CREATE",
"object": <RESOURCE_JSON>,
"oldObject": null,
"dryRun": false,
"options": {
"apiVersion": "meta.k8s.io/v1",
"kind": "CreateOptions"
}
}
}
Then convert my yaml to json with yq -oj
, and insert it in above snippet.
Then it works:
curl --insecure -X POST -H "Content-Type: application/json" \
--data-binary @t.json
https://127.0.0.1:9443/validate-cluster-x-k8s-io-v1beta1-cluster
{"kind":"AdmissionReview","apiVersion":"admission.k8s.io/v1","response":{"uid":"test-uid","allowed":true,"status":{"metadata":{},"code":200}}}
本文标签: How to test Kubernetes validation webhook with curlStack Overflow
版权声明:本文标题:How to test Kubernetes validation webhook with curl? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738620425a2103157.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论