From db0f616974503e8831dbe8502beefc79beefcd00 Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Sat, 9 Nov 2019 16:25:15 -0800 Subject: [PATCH] Handle error return from allocatePodResources --- pkg/kubelet/cm/devicemanager/manager.go | 12 +++++++++--- pkg/kubelet/cm/devicemanager/manager_test.go | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/cm/devicemanager/manager.go b/pkg/kubelet/cm/devicemanager/manager.go index f3089042ece..f5b0f5700e2 100644 --- a/pkg/kubelet/cm/devicemanager/manager.go +++ b/pkg/kubelet/cm/devicemanager/manager.go @@ -231,7 +231,9 @@ func (m *ManagerImpl) Start(activePods ActivePodsFunc, sourcesReady config.Sourc } socketPath := filepath.Join(m.socketdir, m.socketname) - os.MkdirAll(m.socketdir, 0750) + if err = os.MkdirAll(m.socketdir, 0750); err != nil { + return err + } if selinux.SELinuxEnabled() { if err := selinux.SetFileLabel(m.socketdir, config.KubeletPluginsDirSELinuxLabel); err != nil { klog.Warningf("Unprivileged containerized plugins might not work. Could not set selinux context on %s: %v", m.socketdir, err) @@ -552,7 +554,9 @@ func (m *ManagerImpl) writeCheckpoint() error { m.mutex.Unlock() err := m.checkpointManager.CreateCheckpoint(kubeletDeviceManagerCheckpoint, data) if err != nil { - return fmt.Errorf("failed to write checkpoint file %q: %v", kubeletDeviceManagerCheckpoint, err) + err2 := fmt.Errorf("failed to write checkpoint file %q: %v", kubeletDeviceManagerCheckpoint, err) + klog.Warning(err2) + return err2 } return nil } @@ -853,7 +857,9 @@ func (m *ManagerImpl) GetDeviceRunContainerOptions(pod *v1.Pod, container *v1.Co } if needsReAllocate { klog.V(2).Infof("needs re-allocate device plugin resources for pod %s", podUID) - m.allocatePodResources(pod) + if err := m.allocatePodResources(pod); err != nil { + return nil, err + } } m.mutex.Lock() defer m.mutex.Unlock() diff --git a/pkg/kubelet/cm/devicemanager/manager_test.go b/pkg/kubelet/cm/devicemanager/manager_test.go index f810c33511e..b008d6a95bd 100644 --- a/pkg/kubelet/cm/devicemanager/manager_test.go +++ b/pkg/kubelet/cm/devicemanager/manager_test.go @@ -745,7 +745,9 @@ func TestPodContainerDeviceAllocation(t *testing.T) { testCase.description, testCase.expErr, err) } runContainerOpts, err := testManager.GetDeviceRunContainerOptions(pod, &pod.Spec.Containers[0]) - as.Nil(err) + if testCase.expErr == nil { + as.Nil(err) + } if testCase.expectedContainerOptsLen == nil { as.Nil(runContainerOpts) } else {