From f62529d4ff1defa4fb5ea422c628dd5735b812d5 Mon Sep 17 00:00:00 2001 From: Billy McFall <22157057+Billy99@users.noreply.github.com> Date: Fri, 23 Oct 2020 10:54:20 -0400 Subject: [PATCH] Update source for k8s bump to v0.18.3 Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com> --- Dockerfile.openshift | 2 +- k8sclient/k8sclient.go | 11 ++++++----- multus/multus_test.go | 22 ++++++++++++++-------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Dockerfile.openshift b/Dockerfile.openshift index cf6ebd08a..c0431eada 100644 --- a/Dockerfile.openshift +++ b/Dockerfile.openshift @@ -1,5 +1,5 @@ # This dockerfile is specific to building Multus for OpenShift -FROM openshift/origin-release:golang-1.10 as builder +FROM openshift/origin-release:golang-1.15 as builder ADD . /usr/src/multus-cni diff --git a/k8sclient/k8sclient.go b/k8sclient/k8sclient.go index 27398928e..858085c28 100644 --- a/k8sclient/k8sclient.go +++ b/k8sclient/k8sclient.go @@ -15,6 +15,7 @@ package k8sclient import ( + "context" "encoding/json" "fmt" "net" @@ -66,22 +67,22 @@ type ClientInfo struct { // AddPod adds pod into kubernetes func (c *ClientInfo) AddPod(pod *v1.Pod) (*v1.Pod, error) { - return c.Client.Core().Pods(pod.ObjectMeta.Namespace).Create(pod) + return c.Client.CoreV1().Pods(pod.ObjectMeta.Namespace).Create(context.TODO(), pod, metav1.CreateOptions{}) } // GetPod gets pod from kubernetes func (c *ClientInfo) GetPod(namespace, name string) (*v1.Pod, error) { - return c.Client.Core().Pods(namespace).Get(name, metav1.GetOptions{}) + return c.Client.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{}) } // DeletePod deletes a pod from kubernetes func (c *ClientInfo) DeletePod(namespace, name string) error { - return c.Client.Core().Pods(namespace).Delete(name, &metav1.DeleteOptions{}) + return c.Client.CoreV1().Pods(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{}) } // AddNetAttachDef adds net-attach-def into kubernetes func (c *ClientInfo) AddNetAttachDef(netattach *nettypes.NetworkAttachmentDefinition) (*nettypes.NetworkAttachmentDefinition, error) { - return c.NetClient.NetworkAttachmentDefinitions(netattach.ObjectMeta.Namespace).Create(netattach) + return c.NetClient.NetworkAttachmentDefinitions(netattach.ObjectMeta.Namespace).Create(context.TODO(), netattach, metav1.CreateOptions{}) } // Eventf puts event into kubernetes events @@ -241,7 +242,7 @@ func parsePodNetworkAnnotation(podNetworks, defaultNamespace string) ([]*types.N func getKubernetesDelegate(client *ClientInfo, net *types.NetworkSelectionElement, confdir string, pod *v1.Pod, resourceMap map[string]*types.ResourceInfo) (*types.DelegateNetConf, map[string]*types.ResourceInfo, error) { logging.Debugf("getKubernetesDelegate: %v, %v, %s, %v, %v", client, net, confdir, pod, resourceMap) - customResource, err := client.NetClient.NetworkAttachmentDefinitions(net.Namespace).Get(net.Name, metav1.GetOptions{}) + customResource, err := client.NetClient.NetworkAttachmentDefinitions(net.Namespace).Get(context.TODO(), net.Name, metav1.GetOptions{}) if err != nil { errMsg := fmt.Sprintf("cannot find a network-attachment-definition (%s) in namespace (%s): %v", net.Name, net.Namespace, err) if client != nil { diff --git a/multus/multus_test.go b/multus/multus_test.go index 5b1ae66d9..2934415fa 100644 --- a/multus/multus_test.go +++ b/multus/multus_test.go @@ -1395,7 +1395,8 @@ var _ = Describe("multus operations cniVersion 0.2.0 config", func() { }, nil) clientInfo := NewFakeClientInfo() - _, err := clientInfo.Client.Core().Pods(fakePod.ObjectMeta.Namespace).Create(fakePod) + _, err := clientInfo.Client.CoreV1().Pods(fakePod.ObjectMeta.Namespace).Create( + context.TODO(), fakePod, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) _, err = clientInfo.AddNetAttachDef( @@ -1473,7 +1474,8 @@ var _ = Describe("multus operations cniVersion 0.2.0 config", func() { }, nil) clientInfo := NewFakeClientInfo() - _, err := clientInfo.Client.Core().Pods(fakePod.ObjectMeta.Namespace).Create(fakePod) + _, err := clientInfo.Client.CoreV1().Pods(fakePod.ObjectMeta.Namespace).Create( + context.TODO(), fakePod, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) _, err = clientInfo.AddNetAttachDef( @@ -1549,7 +1551,8 @@ var _ = Describe("multus operations cniVersion 0.2.0 config", func() { }, nil) clientInfo := NewFakeClientInfo() - _, err := clientInfo.Client.Core().Pods(fakePod.ObjectMeta.Namespace).Create(fakePod) + _, err := clientInfo.Client.CoreV1().Pods(fakePod.ObjectMeta.Namespace).Create( + context.TODO(), fakePod, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) _, err = clientInfo.AddNetAttachDef( @@ -1570,8 +1573,8 @@ var _ = Describe("multus operations cniVersion 0.2.0 config", func() { // delete pod to emulate no pod info clientInfo.DeletePod(fakePod.ObjectMeta.Namespace, fakePod.ObjectMeta.Name) - nilPod, err := clientInfo.Client.Core().Pods(fakePod.ObjectMeta.Namespace).Get( - fakePod.ObjectMeta.Name, metav1.GetOptions{}) + nilPod, err := clientInfo.Client.CoreV1().Pods(fakePod.ObjectMeta.Namespace).Get( + context.TODO(), fakePod.ObjectMeta.Name, metav1.GetOptions{}) Expect(nilPod).To(BeNil()) Expect(errors.IsNotFound(err)).To(BeTrue()) @@ -2641,7 +2644,8 @@ var _ = Describe("multus operations cniVersion 0.4.0 config", func() { }, nil) clientInfo := NewFakeClientInfo() - _, err := clientInfo.Client.Core().Pods(fakePod.ObjectMeta.Namespace).Create(fakePod) + _, err := clientInfo.Client.CoreV1().Pods(fakePod.ObjectMeta.Namespace).Create( + context.TODO(), fakePod, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) _, err = clientInfo.AddNetAttachDef( @@ -2723,7 +2727,8 @@ var _ = Describe("multus operations cniVersion 0.4.0 config", func() { }, nil) clientInfo := NewFakeClientInfo() - _, err := clientInfo.Client.Core().Pods(fakePod.ObjectMeta.Namespace).Create(fakePod) + _, err := clientInfo.Client.CoreV1().Pods(fakePod.ObjectMeta.Namespace).Create( + context.TODO(), fakePod, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) _, err = clientInfo.AddNetAttachDef( @@ -2793,7 +2798,8 @@ var _ = Describe("multus operations cniVersion 0.4.0 config", func() { }, nil) clientInfo := NewFakeClientInfo() - _, err := clientInfo.Client.Core().Pods(fakePod.ObjectMeta.Namespace).Create(fakePod) + _, err := clientInfo.Client.CoreV1().Pods(fakePod.ObjectMeta.Namespace).Create( + context.TODO(), fakePod, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) _, err = clientInfo.AddNetAttachDef(