1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

Merge pull request #781 from shravanshetty1/778_cli_fix

#778 - CLI fixes
This commit is contained in:
shuting 2020-04-01 11:04:24 -07:00 committed by GitHub
commit 19ea604891
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View file

@ -70,7 +70,7 @@ func (o *Controller) ValidatePolicyFields(policyRaw []byte) error {
return err
}
return o.validatePolicyMutation(policy)
return o.ValidatePolicyMutation(policy)
}
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]
}
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)
for _, rule := range policy.Spec.Rules {
if rule.HasMutate() {

View file

@ -54,7 +54,7 @@ func Test_ValidateMutationPolicy(t *testing.T) {
_ = json.Unmarshal(tc.policy, &policy)
var errMessage string
err := o.validatePolicyMutation(policy)
err := o.ValidatePolicyMutation(policy)
if err != nil {
errMessage = err.Error()
}

View file

@ -75,8 +75,14 @@ func Validate(policyRaw []byte, client *dclient.Client, mock bool, openAPIContro
}
}
if err := openAPIController.ValidatePolicyFields(policyRaw); err != nil {
return err
if !mock {
if err := openAPIController.ValidatePolicyFields(policyRaw); err != nil {
return err
}
} else {
if err := openAPIController.ValidatePolicyMutation(p); err != nil {
return err
}
}
return nil