mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-29 10:55:05 +00:00
fix: kind wash in mutate policy helper (#3698)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
parent
8b36441cd1
commit
b689f1f15c
3 changed files with 17 additions and 9 deletions
|
@ -34,8 +34,8 @@ func Test_Policy_IsNamespaced(t *testing.T) {
|
|||
Name: "this-is-a-way-too-long-policy-name-that-should-trigger-an-error-when-calling-the-policy-validation-method",
|
||||
},
|
||||
}
|
||||
assert.Equal(t, namespaced.IsNamespaced(), false)
|
||||
assert.Equal(t, notNamespaced.IsNamespaced(), false)
|
||||
assert.Equal(t, namespaced.IsNamespaced(), true)
|
||||
assert.Equal(t, notNamespaced.IsNamespaced(), true)
|
||||
}
|
||||
|
||||
func Test_Policy_Autogen_All(t *testing.T) {
|
||||
|
|
|
@ -84,7 +84,7 @@ func (p *Policy) GetSpec() *Spec {
|
|||
|
||||
// IsNamespaced indicates if the policy is namespace scoped
|
||||
func (p *Policy) IsNamespaced() bool {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
// IsReady indicates if the policy is ready to serve the admission request
|
||||
|
|
|
@ -189,13 +189,21 @@ func MutatePolicy(policy v1.PolicyInterface, logger logr.Logger) (v1.PolicyInter
|
|||
if err != nil {
|
||||
return nil, sanitizederror.NewWithError(fmt.Sprintf("failed to apply %s policy", policy.GetName()), err)
|
||||
}
|
||||
var p v1.ClusterPolicy
|
||||
err = json.Unmarshal(modifiedPolicy, &p)
|
||||
if err != nil {
|
||||
return nil, sanitizederror.NewWithError(fmt.Sprintf("failed to unmarshal %s policy", policy.GetName()), err)
|
||||
if policy.IsNamespaced() {
|
||||
var p v1.Policy
|
||||
err = json.Unmarshal(modifiedPolicy, &p)
|
||||
if err != nil {
|
||||
return nil, sanitizederror.NewWithError(fmt.Sprintf("failed to unmarshal %s policy", policy.GetName()), err)
|
||||
}
|
||||
return &p, nil
|
||||
} else {
|
||||
var p v1.ClusterPolicy
|
||||
err = json.Unmarshal(modifiedPolicy, &p)
|
||||
if err != nil {
|
||||
return nil, sanitizederror.NewWithError(fmt.Sprintf("failed to unmarshal %s policy", policy.GetName()), err)
|
||||
}
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
// IsInputFromPipe - check if input is passed using pipe
|
||||
|
|
Loading…
Add table
Reference in a new issue