Implement custom NetworkSelectionElement Unmarshaler

This Unmarshaler bring back support for pre v3.2 "interfaceRequest"
property.

Signed-off-by: giovanism <giovanism@outlook.co.id>
This commit is contained in:
giovanism
2019-07-26 22:10:23 +07:00
committed by Tomofumi Hayashi
parent b117d61ce6
commit 3568756adb

View File

@@ -330,3 +330,42 @@ func CheckSystemNamespaces(namespace string, systemNamespaces []string) bool {
} }
return false return false
} }
// UnmarshalJSON unmarshal Network Selection Annotation. This also supports
// the deprecated "interfaceRequest" property.
func (net *NetworkSelectionElement) UnmarshalJSON(bytes []byte) error {
var networkSelectionMap map[string]string
if err := json.Unmarshal(bytes, &networkSelectionMap); err != nil {
return err
}
if name, ok := networkSelectionMap["name"]; ok {
net.Name = name
} else {
return logging.Errorf(`UnmarshalJSON(): "name" was not provided`)
}
if namespace, ok := networkSelectionMap["namespace"]; ok {
net.Namespace = namespace
}
if ips, ok := networkSelectionMap["ips"]; ok {
net.IPRequest = ips
}
if mac, ok := networkSelectionMap["mac"]; ok {
net.MacRequest = mac
}
// compatibility pre v3.2
if ifName, ok := networkSelectionMap["interfaceRequest"]; ok {
net.InterfaceRequest = ifName
}
if ifName, ok := networkSelectionMap["interface"]; ok {
net.InterfaceRequest = ifName
}
return nil
}