diff --git a/k8sclient/k8sclient.go b/k8sclient/k8sclient.go index 400dfb361..4d219498d 100644 --- a/k8sclient/k8sclient.go +++ b/k8sclient/k8sclient.go @@ -232,6 +232,10 @@ func parsePodNetworkAnnotation(podNetworks, defaultNamespace string) ([]*types.N if net.Namespace == "" { net.Namespace = defaultNamespace } + // compatibility pre v3.2, will be removed in v4.0 + if net.ObsolatedInterfaceRequest != "" && net.InterfaceRequest == "" { + net.InterfaceRequest = net.ObsolatedInterfaceRequest + } } return networks, nil diff --git a/types/conf.go b/types/conf.go index 6180956b7..88c95a4a3 100644 --- a/types/conf.go +++ b/types/conf.go @@ -330,42 +330,3 @@ 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 -} diff --git a/types/conf_test.go b/types/conf_test.go index 0a6e67db9..07885b3af 100644 --- a/types/conf_test.go +++ b/types/conf_test.go @@ -467,49 +467,4 @@ var _ = Describe("config operations", func() { Expect(err).To(HaveOccurred()) }) - - Context("using UnmarshalJSON", func() { - It("succeeds with valid json", func() { - networkselectionelement := &NetworkSelectionElement{ - Name: "kube-system", - Namespace: "net1", - InterfaceRequest: "", - } - conf := `{ - "name": "kube-system", - "namespace": "net1", - "interfaceRequest": "", - "ips": "10.18.89.129", - "mac": "CB-32-97-FF-D6-79", - "interface": "" -}` - err := networkselectionelement.UnmarshalJSON([]byte(conf)) - Expect(err).NotTo(HaveOccurred()) - }) - - It("fails to parse invalid json", func() { - networkselectionelement := &NetworkSelectionElement{ - Name: "kube-system", - Namespace: "net1", - InterfaceRequest: "", - } - err := networkselectionelement.UnmarshalJSON([]byte("invalidjson~")) - Expect(err).To(HaveOccurred()) - }) - - It("fails with missing name parameter", func() { - networkselectionelement := &NetworkSelectionElement{ - Name: "kube-system", - Namespace: "net1", - InterfaceRequest: "", - } - // conf json does not include "name" - conf := `{ - "namespace": "net1", - "interfaceRequest": "" -}` - err := networkselectionelement.UnmarshalJSON([]byte(conf)) - Expect(err).To(HaveOccurred()) - }) - }) }) diff --git a/types/types.go b/types/types.go index 91d716e7a..02321d82e 100644 --- a/types/types.go +++ b/types/types.go @@ -140,6 +140,9 @@ type NetworkSelectionElement struct { // InterfaceRequest contains an optional requested name for the // network interface this attachment will create in the container InterfaceRequest string `json:"interface,omitempty"` + // ObsoateInterfaceRequest is obsolated parameter at pre 3.2. + // This will be removed in 4.0 release. + ObsolatedInterfaceRequest string `json:"interfaceRequest,omitempty"` } // K8sArgs is the valid CNI_ARGS used for Kubernetes