mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +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
|
||||
}
|
||||
|
||||
// CompareKubernetesVersion compare kuberneates client version to user given version
|
||||
func CompareKubernetesVersion(client *client.Client, log logr.Logger, k8smajor, k8sminor, k8ssub int) bool {
|
||||
// HigherThanKubernetesVersion compare kuberneates client version to user given version
|
||||
func HigherThanKubernetesVersion(client *client.Client, log logr.Logger, k8smajor, k8sminor, k8ssub int) bool {
|
||||
logger := log.WithName("CompareKubernetesVersion")
|
||||
serverVersion, err := client.DiscoveryClient.GetServerVersion()
|
||||
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)
|
||||
defer func() {
|
||||
logger.V(4).Info("request processed", "processingTime", time.Since(startTime))
|
||||
}()
|
||||
|
||||
admissionReview.Response = &v1beta1.AdmissionResponse{
|
||||
Allowed: true,
|
||||
|
@ -182,6 +179,8 @@ func (ws *WebhookServer) handlerFunc(handler func(request *v1beta1.AdmissionRequ
|
|||
|
||||
admissionReview.Response = handler(request)
|
||||
writeResponse(rw, admissionReview)
|
||||
logger.V(4).Info("request processed", "processingTime", time.Since(startTime).Milliseconds())
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -265,8 +264,8 @@ func (ws *WebhookServer) resourceMutation(request *v1beta1.AdmissionRequest) *v1
|
|||
var patches []byte
|
||||
patchedResource := request.Object.Raw
|
||||
|
||||
versionCheck := utils.CompareKubernetesVersion(ws.client, ws.log, 1, 14, 0)
|
||||
if versionCheck {
|
||||
higherVersion := utils.HigherThanKubernetesVersion(ws.client, ws.log, 1, 14, 0)
|
||||
if higherVersion {
|
||||
// MUTATION
|
||||
// mutation failure should not block the resource creation
|
||||
// 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)
|
||||
if !versionCheck {
|
||||
higherVersion := utils.HigherThanKubernetesVersion(ws.client, ws.log, 1, 14, 0)
|
||||
if higherVersion {
|
||||
ok, msg := ws.HandleValidation(request, policies, nil, ctx, userRequestInfo)
|
||||
if !ok {
|
||||
logger.Info("admission request denied")
|
||||
|
|
Loading…
Reference in a new issue