-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1446 :Failed to mutate policy #1767
Fix #1446 :Failed to mutate policy #1767
Conversation
Signed-off-by: vyankatesh <vyankatesh@neualto.com>
d55803c
to
bf2d4a9
Compare
Signed-off-by: vyankatesh <vyankatesh@neualto.com>
68eb4f9
to
9e2fa71
Compare
4852da4
to
e534a2c
Compare
3c9240a
to
27ff1b5
Compare
…kyGH/kyverno into bug/failed_to_mutate_policy Signed-off-by: vyankatesh <vyankatesh@neualto.com>
27ff1b5
to
f58bb3a
Compare
pkg/policy/validate_controller.go
Outdated
@@ -251,6 +274,14 @@ func (pc *PolicyController) addNsPolicy(obj interface{}) { | |||
logger.Info("policy created", "uid", p.UID, "kind", "Policy", "name", p.Name, "namespaces", p.Namespace) | |||
|
|||
pol := ConvertPolicyToClusterPolicy(p) | |||
if pol.Spec.Background == nil || pol.Spec.ValidationFailureAction == "" || checkAutoGenRules(pol) { | |||
pol.ObjectMeta.SetAnnotations(map[string]string{"kyverno.io/mutate-policy": strconv.Itoa(random.Intn(100))}) | |||
pol.SetGroupVersionKind(schema.GroupVersionKind{Group: "kyverno.io", Version: "v1", Kind: "ClusterPolicy"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind
should be Policy
.
pkg/policy/validate_controller.go
Outdated
if pol.Spec.Background == nil || pol.Spec.ValidationFailureAction == "" || checkAutoGenRules(pol) { | ||
pol.ObjectMeta.SetAnnotations(map[string]string{"kyverno.io/mutate-policy": strconv.Itoa(random.Intn(100))}) | ||
pol.SetGroupVersionKind(schema.GroupVersionKind{Group: "kyverno.io", Version: "v1", Kind: "ClusterPolicy"}) | ||
_, err := pc.client.UpdateResource("kyverno.io/v1", "ClusterPolicy", p.Namespace, pol, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind
-> Policy
.
pkg/policy/validate_controller.go
Outdated
|
||
if ncurP.Spec.Background == nil || ncurP.Spec.ValidationFailureAction == "" || checkAutoGenRules(ncurP) { | ||
ncurP.ObjectMeta.SetAnnotations(map[string]string{"kyverno.io/mutate-policy": strconv.Itoa(random.Intn(100))}) | ||
ncurP.SetGroupVersionKind(schema.GroupVersionKind{Group: "kyverno.io", Version: "v1", Kind: "ClusterPolicy"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind
-> Policy
.
pkg/policy/validate_controller.go
Outdated
if ncurP.Spec.Background == nil || ncurP.Spec.ValidationFailureAction == "" || checkAutoGenRules(ncurP) { | ||
ncurP.ObjectMeta.SetAnnotations(map[string]string{"kyverno.io/mutate-policy": strconv.Itoa(random.Intn(100))}) | ||
ncurP.SetGroupVersionKind(schema.GroupVersionKind{Group: "kyverno.io", Version: "v1", Kind: "ClusterPolicy"}) | ||
_, err := pc.client.UpdateResource("kyverno.io/v1", "ClusterPolicy", ncurP.GetNamespace(), ncurP, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kind
-> Policy
.
pkg/policy/validate_controller.go
Outdated
@@ -192,6 +197,15 @@ func (pc *PolicyController) addPolicy(obj interface{}) { | |||
|
|||
logger.Info("policy created", "uid", p.UID, "kind", "ClusterPolicy", "name", p.Name) | |||
|
|||
if p.Spec.Background == nil || p.Spec.ValidationFailureAction == "" || checkAutoGenRules(p) { | |||
p.ObjectMeta.SetAnnotations(map[string]string{"kyverno.io/mutate-policy": strconv.Itoa(random.Intn(100))}) | |||
p.SetGroupVersionKind(schema.GroupVersionKind{Group: "kyverno.io", Version: "v1", Kind: "Policy"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be ClusterPolicy
.
pkg/policy/validate_controller.go
Outdated
@@ -205,6 +219,15 @@ func (pc *PolicyController) updatePolicy(old, cur interface{}) { | |||
oldP := old.(*kyverno.ClusterPolicy) | |||
curP := cur.(*kyverno.ClusterPolicy) | |||
|
|||
if curP.Spec.Background == nil || curP.Spec.ValidationFailureAction == "" || checkAutoGenRules(curP) { | |||
curP.ObjectMeta.SetAnnotations(map[string]string{"kyverno.io/mutate-policy": strconv.Itoa(random.Intn(100))}) | |||
curP.SetGroupVersionKind(schema.GroupVersionKind{Group: "kyverno.io", Version: "v1", Kind: "Policy"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClusterPolicy
.
Signed-off-by: vyankatesh <vyankatesh@neualto.com>
3785fe4
to
38f9f53
Compare
Signed-off-by: Vyankatesh vyankateshkd@gmail.com
Related issue
closes #1446
What type of PR is this
/kind bug
Proposed changes
Checklist