mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-08-31 16:38:43 +00:00
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:
committed by
Tomofumi Hayashi
parent
b117d61ce6
commit
3568756adb
@@ -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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user