mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
778 tested prototype
This commit is contained in:
parent
67d2bc224b
commit
bbeefb955b
3 changed files with 14 additions and 5 deletions
|
@ -70,7 +70,7 @@ func (o *Controller) ValidatePolicyFields(policyRaw []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return o.validatePolicyMutation(policy)
|
return o.ValidatePolicyMutation(policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Controller) ValidateResource(patchedResource unstructured.Unstructured, kind string) error {
|
func (o *Controller) ValidateResource(patchedResource unstructured.Unstructured, kind string) error {
|
||||||
|
@ -107,7 +107,10 @@ func (o *Controller) GetDefinitionNameFromKind(kind string) string {
|
||||||
return o.kindToDefinitionName[kind]
|
return o.kindToDefinitionName[kind]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Controller) validatePolicyMutation(policy v1.ClusterPolicy) error {
|
func (o *Controller) ValidatePolicyMutation(policy v1.ClusterPolicy) error {
|
||||||
|
o.mutex.RLock()
|
||||||
|
defer o.mutex.RUnlock()
|
||||||
|
|
||||||
var kindToRules = make(map[string][]v1.Rule)
|
var kindToRules = make(map[string][]v1.Rule)
|
||||||
for _, rule := range policy.Spec.Rules {
|
for _, rule := range policy.Spec.Rules {
|
||||||
if rule.HasMutate() {
|
if rule.HasMutate() {
|
||||||
|
|
|
@ -54,7 +54,7 @@ func Test_ValidateMutationPolicy(t *testing.T) {
|
||||||
_ = json.Unmarshal(tc.policy, &policy)
|
_ = json.Unmarshal(tc.policy, &policy)
|
||||||
|
|
||||||
var errMessage string
|
var errMessage string
|
||||||
err := o.validatePolicyMutation(policy)
|
err := o.ValidatePolicyMutation(policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMessage = err.Error()
|
errMessage = err.Error()
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,14 @@ func Validate(policyRaw []byte, client *dclient.Client, mock bool, openAPIContro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := openAPIController.ValidatePolicyFields(policyRaw); err != nil {
|
if !mock {
|
||||||
return err
|
if err := openAPIController.ValidatePolicyFields(policyRaw); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := openAPIController.ValidatePolicyMutation(p); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue