mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +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:
parent
db1bfba3f8
commit
4788085c4f
2 changed files with 19 additions and 11 deletions
|
@ -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{})["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")
|
delete(obj["metadata"].(map[string]interface{})["labels"].(map[string]interface{}), "generate.kyverno.io/clone-policy-name")
|
||||||
|
|
||||||
requiredMetadataInObj := make(map[string]interface{})
|
if _, found := obj["metadata"]; found {
|
||||||
requiredMetadataInObj["annotations"] = obj["metadata"].(map[string]interface{})["annotations"]
|
requiredMetadataInObj := make(map[string]interface{})
|
||||||
requiredMetadataInObj["labels"] = obj["metadata"].(map[string]interface{})["labels"]
|
if _, found := obj["metadata"].(map[string]interface{})["annotations"]; found {
|
||||||
obj["metadata"] = requiredMetadataInObj
|
requiredMetadataInObj["annotations"] = obj["metadata"].(map[string]interface{})["annotations"]
|
||||||
|
}
|
||||||
|
|
||||||
requiredMetadataInNewRes := make(map[string]interface{})
|
if _, found := newRes["metadata"].(map[string]interface{})["labels"]; found {
|
||||||
if _, found := newRes["metadata"].(map[string]interface{})["annotations"]; found {
|
requiredMetadataInObj["labels"] = obj["metadata"].(map[string]interface{})["labels"]
|
||||||
requiredMetadataInNewRes["annotations"] = newRes["metadata"].(map[string]interface{})["annotations"]
|
}
|
||||||
|
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 {
|
if _, found := obj["status"]; found {
|
||||||
delete(obj, "status")
|
delete(obj, "status")
|
||||||
|
|
|
@ -62,7 +62,6 @@ func Test_updateFeildsInSourceAndUpdatedResource(t *testing.T) {
|
||||||
"annotations": map[string]interface{}{
|
"annotations": map[string]interface{}{
|
||||||
"imageregistry": "https://hub.docker.com/",
|
"imageregistry": "https://hub.docker.com/",
|
||||||
},
|
},
|
||||||
"labels": map[string]interface{}{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue