diff --git a/types/conf.go b/types/conf.go index 88c95a4a3..6180956b7 100644 --- a/types/conf.go +++ b/types/conf.go @@ -330,3 +330,42 @@ func CheckSystemNamespaces(namespace string, systemNamespaces []string) bool { } 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 +}