mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
9d5f77a941
Functions for parsing metadata moved to utils. Changed login of mutation webhook according to last changes.
33 lines
731 B
Go
33 lines
731 B
Go
package webhooks
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
)
|
|
|
|
func parseMetadataFromObject(bytes []byte) map[string]interface{} {
|
|
var objectJSON map[string]interface{}
|
|
json.Unmarshal(bytes, &objectJSON)
|
|
|
|
return objectJSON["metadata"].(map[string]interface{})
|
|
}
|
|
|
|
func parseLabelsFromMetadata(meta map[string]interface{}) labels.Set {
|
|
if interfaceMap, ok := meta["labels"].(map[string]interface{}); ok {
|
|
labelMap := make(labels.Set, len(interfaceMap))
|
|
|
|
for key, value := range interfaceMap {
|
|
labelMap[key] = value.(string)
|
|
}
|
|
return labelMap
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func parseNameFromMetadata(meta map[string]interface{}) string {
|
|
if name, ok := meta["name"].(string); ok {
|
|
return name
|
|
}
|
|
return ""
|
|
}
|