1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

Panic fix in generation.go (#1563)

* added if condition

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

* fixed test condition

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
This commit is contained in:
Pooja Singh 2021-02-10 00:04:57 +05:30 committed by GitHub
parent db1bfba3f8
commit 4788085c4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View file

@ -191,19 +191,28 @@ func stripNonPolicyFields(obj, newRes map[string]interface{}, logger logr.Logger
delete(obj["metadata"].(map[string]interface{})["annotations"].(map[string]interface{}), "kubectl.kubernetes.io/last-applied-configuration")
delete(obj["metadata"].(map[string]interface{})["labels"].(map[string]interface{}), "generate.kyverno.io/clone-policy-name")
requiredMetadataInObj := make(map[string]interface{})
requiredMetadataInObj["annotations"] = obj["metadata"].(map[string]interface{})["annotations"]
requiredMetadataInObj["labels"] = obj["metadata"].(map[string]interface{})["labels"]
obj["metadata"] = requiredMetadataInObj
if _, found := obj["metadata"]; found {
requiredMetadataInObj := make(map[string]interface{})
if _, found := obj["metadata"].(map[string]interface{})["annotations"]; found {
requiredMetadataInObj["annotations"] = obj["metadata"].(map[string]interface{})["annotations"]
}
requiredMetadataInNewRes := make(map[string]interface{})
if _, found := newRes["metadata"].(map[string]interface{})["annotations"]; found {
requiredMetadataInNewRes["annotations"] = newRes["metadata"].(map[string]interface{})["annotations"]
if _, found := newRes["metadata"].(map[string]interface{})["labels"]; found {
requiredMetadataInObj["labels"] = obj["metadata"].(map[string]interface{})["labels"]
}
obj["metadata"] = requiredMetadataInObj
}
if _, found := newRes["metadata"].(map[string]interface{})["labels"]; found {
requiredMetadataInNewRes["labels"] = newRes["metadata"].(map[string]interface{})["labels"]
if _, found := newRes["metadata"]; found {
requiredMetadataInNewRes := make(map[string]interface{})
if _, found := newRes["metadata"].(map[string]interface{})["annotations"]; found {
requiredMetadataInNewRes["annotations"] = newRes["metadata"].(map[string]interface{})["annotations"]
}
if _, found := newRes["metadata"].(map[string]interface{})["labels"]; found {
requiredMetadataInNewRes["labels"] = newRes["metadata"].(map[string]interface{})["labels"]
}
newRes["metadata"] = requiredMetadataInNewRes
}
newRes["metadata"] = requiredMetadataInNewRes
if _, found := obj["status"]; found {
delete(obj, "status")

View file

@ -62,7 +62,6 @@ func Test_updateFeildsInSourceAndUpdatedResource(t *testing.T) {
"annotations": map[string]interface{}{
"imageregistry": "https://hub.docker.com/",
},
"labels": map[string]interface{}{},
},
},