k8s admission webhook报错

何玺
2023-12-01

W0201 05:48:35.514089       1 dispatcher.go:129] Failed calling webhook, failing open casbin.default.svc: failed calling webhook "test.default.svc": expected webhook response of admission.k8s.io/v1, Kind=AdmissionReview, got /, Kind=
E0201 05:48:35.514112       1 dispatcher.go:130] failed calling webhook "test.default.svc": expected webhook response of admission.k8s.io/v1, Kind=AdmissionReview, got /, Kind=

原因是返回的数据格式不对,缺少 apiversion和kind,需要根据标准进行设置:

格式如下:

{
  "apiVersion": "admission.k8s.io/v1",
  "kind": "AdmissionReview",
  "response": {
    "uid": "<value from request.uid>",
    "allowed": true
  }
}

代码中加上类似两条语句:

	arReview.Kind = admissionReview.Kind
	arReview.APIVersion = admissionReview.APIVersion

 类似资料: