From 3568756adb40e5c8e9bb668dc3b6e77a2b60705f Mon Sep 17 00:00:00 2001 From: giovanism Date: Fri, 26 Jul 2019 22:10:23 +0700 Subject: [PATCH] Implement custom NetworkSelectionElement Unmarshaler This Unmarshaler bring back support for pre v3.2 "interfaceRequest" property. Signed-off-by: giovanism --- types/conf.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) 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 +}