Skip to content
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

Merged
merged 10 commits into from
Apr 7, 2021

Conversation

vyankyGH
Copy link
Contributor

@vyankyGH vyankyGH commented Apr 6, 2021

Signed-off-by: Vyankatesh vyankateshkd@gmail.com

Related issue

closes #1446

What type of PR is this

/kind bug

Proposed changes

  • Fix Failed to mutate policy defaults

Checklist

Signed-off-by: vyankatesh <vyankatesh@neualto.com>
@vyankyGH vyankyGH force-pushed the bug/failed_to_mutate_policy branch from d55803c to bf2d4a9 Compare April 6, 2021 10:04
@vyankyGH vyankyGH changed the title Fix failed to mutate policy Fix #1446 :Failed to mutate policy Apr 6, 2021
Signed-off-by: vyankatesh <vyankatesh@neualto.com>
Signed-off-by: vyankatesh <vyankatesh@neualto.com>
@vyankyGH vyankyGH force-pushed the bug/failed_to_mutate_policy branch from 4852da4 to e534a2c Compare April 7, 2021 22:18
Signed-off-by: vyankatesh <vyankatesh@neualto.com>
@vyankyGH vyankyGH force-pushed the bug/failed_to_mutate_policy branch from 3c9240a to 27ff1b5 Compare April 7, 2021 22:34
…kyGH/kyverno into bug/failed_to_mutate_policy

Signed-off-by: vyankatesh <vyankatesh@neualto.com>
@vyankyGH vyankyGH force-pushed the bug/failed_to_mutate_policy branch from 27ff1b5 to f58bb3a Compare April 7, 2021 22:35
@@ -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"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind should be Policy.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind -> Policy.


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"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind -> Policy.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind -> Policy.

@@ -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"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ClusterPolicy.

@@ -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"})
Copy link
Member

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>
@vyankyGH vyankyGH force-pushed the bug/failed_to_mutate_policy branch from 3785fe4 to 38f9f53 Compare April 7, 2021 22:45
@realshuting realshuting self-assigned this Apr 7, 2021
@realshuting realshuting merged commit e2cd04c into kyverno:main Apr 7, 2021
@vyankyGH vyankyGH deleted the bug/failed_to_mutate_policy branch May 10, 2021 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] failed to mutate policy defaults
3 participants