mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
522 fixed tests and added validation of mutated resources
This commit is contained in:
parent
888d2ae171
commit
044d55600a
3 changed files with 13 additions and 10 deletions
|
@ -216,23 +216,23 @@ func generateEmptyResource(kindSchema *openapi_v2.Schema) interface{} {
|
||||||
case "integer":
|
case "integer":
|
||||||
if kindSchema.GetDefault() != nil {
|
if kindSchema.GetDefault() != nil {
|
||||||
val, _ := strconv.Atoi(string(kindSchema.GetDefault().Value.Value))
|
val, _ := strconv.Atoi(string(kindSchema.GetDefault().Value.Value))
|
||||||
return val
|
return int64(val)
|
||||||
}
|
}
|
||||||
if kindSchema.GetExample() != nil {
|
if kindSchema.GetExample() != nil {
|
||||||
val, _ := strconv.Atoi(string(kindSchema.GetExample().GetValue().Value))
|
val, _ := strconv.Atoi(string(kindSchema.GetExample().GetValue().Value))
|
||||||
return val
|
return int64(val)
|
||||||
}
|
}
|
||||||
return 0
|
return int64(0)
|
||||||
case "number":
|
case "number":
|
||||||
if kindSchema.GetDefault() != nil {
|
if kindSchema.GetDefault() != nil {
|
||||||
val, _ := strconv.Atoi(string(kindSchema.GetDefault().Value.Value))
|
val, _ := strconv.Atoi(string(kindSchema.GetDefault().Value.Value))
|
||||||
return val
|
return int64(val)
|
||||||
}
|
}
|
||||||
if kindSchema.GetExample() != nil {
|
if kindSchema.GetExample() != nil {
|
||||||
val, _ := strconv.Atoi(string(kindSchema.GetExample().GetValue().Value))
|
val, _ := strconv.Atoi(string(kindSchema.GetExample().GetValue().Value))
|
||||||
return val
|
return int64(val)
|
||||||
}
|
}
|
||||||
return 0
|
return int64(0)
|
||||||
case "boolean":
|
case "boolean":
|
||||||
if kindSchema.GetDefault() != nil {
|
if kindSchema.GetDefault() != nil {
|
||||||
return string(kindSchema.GetDefault().Value.Value) == "true"
|
return string(kindSchema.GetDefault().Value.Value) == "true"
|
||||||
|
|
|
@ -8,10 +8,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_ValidateMutationPolicy(t *testing.T) {
|
func Test_ValidateMutationPolicy(t *testing.T) {
|
||||||
err := setValidationGlobalState()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Could not set global state")
|
|
||||||
}
|
|
||||||
|
|
||||||
tcs := []struct {
|
tcs := []struct {
|
||||||
description string
|
description string
|
||||||
|
|
|
@ -3,6 +3,8 @@ package webhooks
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/nirmata/kyverno/pkg/openapi"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
kyverno "github.com/nirmata/kyverno/pkg/api/kyverno/v1"
|
kyverno "github.com/nirmata/kyverno/pkg/api/kyverno/v1"
|
||||||
"github.com/nirmata/kyverno/pkg/engine"
|
"github.com/nirmata/kyverno/pkg/engine"
|
||||||
|
@ -101,6 +103,11 @@ func (ws *WebhookServer) HandleMutation(request *v1beta1.AdmissionRequest, resou
|
||||||
glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, resource.GetNamespace(), resource.GetName())
|
glog.V(4).Infof("Failed to apply policy %s on resource %s/%s\n", policy.Name, resource.GetNamespace(), resource.GetName())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
err := openapi.ValidateResource(engineResponse.PatchedResource.UnstructuredContent(), engineResponse.PatchedResource.GetKind())
|
||||||
|
if err != nil {
|
||||||
|
glog.V(4).Infoln(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
// gather patches
|
// gather patches
|
||||||
patches = append(patches, engineResponse.GetPatches()...)
|
patches = append(patches, engineResponse.GetPatches()...)
|
||||||
glog.V(4).Infof("Mutation from policy %s has applied successfully to %s %s/%s", policy.Name, request.Kind.Kind, resource.GetNamespace(), resource.GetName())
|
glog.V(4).Infof("Mutation from policy %s has applied successfully to %s %s/%s", policy.Name, request.Kind.Kind, resource.GetNamespace(), resource.GetName())
|
||||||
|
|
Loading…
Add table
Reference in a new issue