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

Panic fix in generation.go #1563

Merged
merged 2 commits into from
Feb 9, 2021

Conversation

NoSkillGirl
Copy link
Contributor

@NoSkillGirl NoSkillGirl commented Feb 9, 2021

Signed-off-by: NoSkillGirl singhpooja240393@gmail.com

Related issue

Fixed generation.go interface conversion panic:

panic: interface conversion: interface {} is nil, not map[string]interface {}
goroutine 17228 [running]:
github.com/kyverno/kyverno/pkg/webhooks.stripNonPolicyFields(0xc0056462d0, 0xc0011c6b40, 0x211b700, 0xc0011c6960, 0x4, 0xc00597ab57)
	/Users/shutingzhao/go/src/github.com/realshuting/kyverno/pkg/webhooks/generation.go:191 +0xfd9
github.com/kyverno/kyverno/pkg/webhooks.(*WebhookServer).handleUpdateTargetResource(0xc000b13c80, 0xc00010f520, 0xc0038f64a8, 0x1, 0x1, 0xc0011c6ab0, 0x211b700, 0xc0011c6960)
	/Users/shutingzhao/go/src/github.com/realshuting/kyverno/pkg/webhooks/generation.go:165 +0x6af
github.com/kyverno/kyverno/pkg/webhooks.(*WebhookServer).handleUpdate(0xc000b13c80, 0xc00010f520, 0xc0038f64a8, 0x1, 0x1)
	/Users/shutingzhao/go/src/github.com/realshuting/kyverno/pkg/webhooks/generation.go:110 +0x4c5
github.com/kyverno/kyverno/pkg/webhooks.(*WebhookServer).HandleGenerate(0xc000b13c80, 0xc00010f520, 0xc0038f64a8, 0x1, 0x1, 0xc0000d9500, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/shutingzhao/go/src/github.com/realshuting/kyverno/pkg/webhooks/generation.go:92 +0xd86
created by github.com/kyverno/kyverno/pkg/webhooks.(*WebhookServer).ResourceMutation
	/Users/shutingzhao/go/src/github.com/realshuting/kyverno/pkg/webhooks/server.go:379 +0xdb3
rpc error: code = Unknown desc = Error: No such container: e7aa7f0473911a3cb684d1037bb228df90908449c44d13172cecb8b190d0ade5%

What type of PR is this?

/kind bug

Proposed changes

Added if condition before conversion.

Checklist

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
@NoSkillGirl NoSkillGirl changed the title added if condition Panic fix in generation.go Feb 9, 2021
Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
@NoSkillGirl NoSkillGirl added this to the Kyverno Release 1.3.2 milestone Feb 9, 2021
requiredMetadataInObj := make(map[string]interface{})
if _, found := obj["metadata"].(map[string]interface{})["annotations"]; found {
requiredMetadataInObj["annotations"] = obj["metadata"].(map[string]interface{})["annotations"]
}
Copy link
Member

Choose a reason for hiding this comment

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

This can be improved to:

if _, found := obj["metadata"]; found {
	requiredMetadataInObj := make(map[string]interface{})
	if annotations, found := obj["metadata"].(map[string]interface{})["annotations"]; found {
		requiredMetadataInObj["annotations"] = annotations
        }
}

@realshuting realshuting merged commit 4788085 into kyverno:main Feb 9, 2021
@NoSkillGirl NoSkillGirl mentioned this pull request Feb 9, 2021
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.

None yet

2 participants