mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-14 19:58:45 +00:00
Fix bug
This commit is contained in:
parent
416f5ecc00
commit
962b8f9865
2 changed files with 8 additions and 9 deletions
|
@ -137,8 +137,8 @@ func ConvertResource(raw []byte, group, version, kind, namespace string) (unstru
|
||||||
return *obj, nil
|
return *obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompareKubernetesVersion compare kuberneates client version to user given version
|
// HigherThanKubernetesVersion compare kuberneates client version to user given version
|
||||||
func CompareKubernetesVersion(client *client.Client, log logr.Logger, k8smajor, k8sminor, k8ssub int) bool {
|
func HigherThanKubernetesVersion(client *client.Client, log logr.Logger, k8smajor, k8sminor, k8ssub int) bool {
|
||||||
logger := log.WithName("CompareKubernetesVersion")
|
logger := log.WithName("CompareKubernetesVersion")
|
||||||
serverVersion, err := client.DiscoveryClient.GetServerVersion()
|
serverVersion, err := client.DiscoveryClient.GetServerVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -164,9 +164,6 @@ func (ws *WebhookServer) handlerFunc(handler func(request *v1beta1.AdmissionRequ
|
||||||
}
|
}
|
||||||
|
|
||||||
logger := ws.log.WithValues("kind", admissionReview.Request.Kind, "namespace", admissionReview.Request.Namespace, "name", admissionReview.Request.Name)
|
logger := ws.log.WithValues("kind", admissionReview.Request.Kind, "namespace", admissionReview.Request.Namespace, "name", admissionReview.Request.Name)
|
||||||
defer func() {
|
|
||||||
logger.V(4).Info("request processed", "processingTime", time.Since(startTime))
|
|
||||||
}()
|
|
||||||
|
|
||||||
admissionReview.Response = &v1beta1.AdmissionResponse{
|
admissionReview.Response = &v1beta1.AdmissionResponse{
|
||||||
Allowed: true,
|
Allowed: true,
|
||||||
|
@ -182,6 +179,8 @@ func (ws *WebhookServer) handlerFunc(handler func(request *v1beta1.AdmissionRequ
|
||||||
|
|
||||||
admissionReview.Response = handler(request)
|
admissionReview.Response = handler(request)
|
||||||
writeResponse(rw, admissionReview)
|
writeResponse(rw, admissionReview)
|
||||||
|
logger.V(4).Info("request processed", "processingTime", time.Since(startTime).Milliseconds())
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,8 +264,8 @@ func (ws *WebhookServer) resourceMutation(request *v1beta1.AdmissionRequest) *v1
|
||||||
var patches []byte
|
var patches []byte
|
||||||
patchedResource := request.Object.Raw
|
patchedResource := request.Object.Raw
|
||||||
|
|
||||||
versionCheck := utils.CompareKubernetesVersion(ws.client, ws.log, 1, 14, 0)
|
higherVersion := utils.HigherThanKubernetesVersion(ws.client, ws.log, 1, 14, 0)
|
||||||
if versionCheck {
|
if higherVersion {
|
||||||
// MUTATION
|
// MUTATION
|
||||||
// mutation failure should not block the resource creation
|
// mutation failure should not block the resource creation
|
||||||
// any mutation failure is reported as the violation
|
// any mutation failure is reported as the violation
|
||||||
|
@ -390,8 +389,8 @@ func (ws *WebhookServer) resourceValidation(request *v1beta1.AdmissionRequest) *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
versionCheck := utils.CompareKubernetesVersion(ws.client, ws.log, 1, 14, 0)
|
higherVersion := utils.HigherThanKubernetesVersion(ws.client, ws.log, 1, 14, 0)
|
||||||
if !versionCheck {
|
if higherVersion {
|
||||||
ok, msg := ws.HandleValidation(request, policies, nil, ctx, userRequestInfo)
|
ok, msg := ws.HandleValidation(request, policies, nil, ctx, userRequestInfo)
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Info("admission request denied")
|
logger.Info("admission request denied")
|
||||||
|
|
Loading…
Add table
Reference in a new issue