2017-09-10 19:53:17 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package e2e_node
|
|
|
|
|
|
|
|
import (
|
2018-03-21 20:56:51 +00:00
|
|
|
"os/exec"
|
2017-11-08 21:12:28 +00:00
|
|
|
"strconv"
|
2017-09-10 19:53:17 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"k8s.io/api/core/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-11-08 21:12:28 +00:00
|
|
|
kubeletmetrics "k8s.io/kubernetes/pkg/kubelet/metrics"
|
2017-09-10 19:53:17 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2017-11-08 21:12:28 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework/metrics"
|
2017-09-10 19:53:17 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2017-11-08 21:12:28 +00:00
|
|
|
"github.com/prometheus/common/model"
|
2017-09-10 19:53:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Serial because the test restarts Kubelet
|
2018-05-21 23:46:54 +00:00
|
|
|
var _ = framework.KubeDescribe("NVIDIA GPU Device Plugin [Feature:GPUDevicePlugin][NodeFeature:GPUDevicePlugin][Serial] [Disruptive]", func() {
|
2017-09-10 19:53:17 +00:00
|
|
|
f := framework.NewDefaultFramework("device-plugin-gpus-errors")
|
|
|
|
|
2017-09-18 23:10:04 +00:00
|
|
|
Context("DevicePlugin", func() {
|
2017-11-03 23:38:00 +00:00
|
|
|
var devicePluginPod *v1.Pod
|
2018-07-19 08:04:58 +00:00
|
|
|
var err error
|
2017-09-10 19:53:17 +00:00
|
|
|
BeforeEach(func() {
|
|
|
|
By("Ensuring that Nvidia GPUs exists on the node")
|
|
|
|
if !checkIfNvidiaGPUsExistOnNode() {
|
|
|
|
Skip("Nvidia GPUs do not exist on the node. Skipping test.")
|
|
|
|
}
|
|
|
|
|
|
|
|
By("Creating the Google Device Plugin pod for NVIDIA GPU in GKE")
|
2018-07-19 08:04:58 +00:00
|
|
|
devicePluginPod, err = f.ClientSet.CoreV1().Pods(metav1.NamespaceSystem).Create(framework.NVIDIADevicePlugin())
|
|
|
|
framework.ExpectNoError(err)
|
2017-09-10 19:53:17 +00:00
|
|
|
|
|
|
|
By("Waiting for GPUs to become available on the local node")
|
2017-09-18 23:10:04 +00:00
|
|
|
Eventually(func() bool {
|
|
|
|
return framework.NumberOfNVIDIAGPUs(getLocalNode(f)) > 0
|
2018-06-27 18:00:36 +00:00
|
|
|
}, 5*time.Minute, framework.Poll).Should(BeTrue())
|
2017-09-10 19:53:17 +00:00
|
|
|
|
|
|
|
if framework.NumberOfNVIDIAGPUs(getLocalNode(f)) < 2 {
|
|
|
|
Skip("Not enough GPUs to execute this test (at least two needed)")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
l, err := f.PodClient().List(metav1.ListOptions{})
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
|
|
|
|
for _, p := range l.Items {
|
|
|
|
if p.Namespace != f.Namespace.Name {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
f.PodClient().Delete(p.Name, &metav1.DeleteOptions{})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
It("checks that when Kubelet restarts exclusive GPU assignation to pods is kept.", func() {
|
|
|
|
By("Creating one GPU pod on a node with at least two GPUs")
|
2017-12-29 10:43:38 +00:00
|
|
|
podRECMD := "devs=$(ls /dev/ | egrep '^nvidia[0-9]+$') && echo gpu devices: $devs"
|
|
|
|
p1 := f.PodClient().CreateSync(makeBusyboxPod(framework.NVIDIAGPUResourceName, podRECMD))
|
|
|
|
|
|
|
|
deviceIDRE := "gpu devices: (nvidia[0-9]+)"
|
2018-04-25 07:44:27 +00:00
|
|
|
devId1 := parseLog(f, p1.Name, p1.Name, deviceIDRE)
|
2017-09-18 23:10:04 +00:00
|
|
|
p1, err := f.PodClient().Get(p1.Name, metav1.GetOptions{})
|
|
|
|
framework.ExpectNoError(err)
|
2017-09-10 19:53:17 +00:00
|
|
|
|
|
|
|
By("Restarting Kubelet and waiting for the current running pod to restart")
|
2017-12-29 10:43:38 +00:00
|
|
|
restartKubelet()
|
2017-09-10 19:53:17 +00:00
|
|
|
|
2019-02-15 10:11:29 +00:00
|
|
|
By("Confirming that after a kubelet and pod restart, GPU assignment is kept")
|
2018-04-25 07:44:27 +00:00
|
|
|
ensurePodContainerRestart(f, p1.Name, p1.Name)
|
|
|
|
devIdRestart1 := parseLog(f, p1.Name, p1.Name, deviceIDRE)
|
2017-11-03 23:38:00 +00:00
|
|
|
Expect(devIdRestart1).To(Equal(devId1))
|
2017-09-10 19:53:17 +00:00
|
|
|
|
|
|
|
By("Restarting Kubelet and creating another pod")
|
2017-12-29 10:43:38 +00:00
|
|
|
restartKubelet()
|
Fixes the races around devicemanager Allocate() and endpoint deletion.
There is a race in predicateAdmitHandler Admit() that getNodeAnyWayFunc()
could get Node with non-zero deviceplugin resource allocatable for a
non-existing endpoint. That race can happen when a device plugin fails,
but is more likely when kubelet restarts as with the current registration
model, there is a time gap between kubelet restart and device plugin
re-registration. During this time window, even though devicemanager could
have removed the resource initially during GetCapacity() call, Kubelet
may overwrite the device plugin resource capacity/allocatable with the
old value when node update from the API server comes in later. This
could cause a pod to be started without proper device runtime config set.
To solve this problem, introduce endpointStopGracePeriod. When a device
plugin fails, don't immediately remove the endpoint but set stopTime in
its endpoint. During kubelet restart, create endpoints with stopTime set
for any checkpointed registered resource. The endpoint is considered to be
in stopGracePeriod if its stoptime is set. This allows us to track what
resources should be handled by devicemanager during the time gap.
When an endpoint's stopGracePeriod expires, we remove the endpoint and
its resource. This allows the resource to be exported through other channels
(e.g., by directly updating node status through API server) if there is such
use case. Currently endpointStopGracePeriod is set as 5 minutes.
Given that an endpoint is no longer immediately removed upon disconnection,
mark all its devices unhealthy so that we can signal the resource allocatable
change to the scheduler to avoid scheduling more pods to the node.
When a device plugin endpoint is in stopGracePeriod, pods requesting the
corresponding resource will fail admission handler.
2018-03-05 21:54:43 +00:00
|
|
|
framework.WaitForAllNodesSchedulable(f.ClientSet, framework.TestContext.NodeSchedulableTimeout)
|
|
|
|
Eventually(func() bool {
|
|
|
|
return framework.NumberOfNVIDIAGPUs(getLocalNode(f)) > 0
|
2018-06-27 18:00:36 +00:00
|
|
|
}, 5*time.Minute, framework.Poll).Should(BeTrue())
|
2017-12-29 10:43:38 +00:00
|
|
|
p2 := f.PodClient().CreateSync(makeBusyboxPod(framework.NVIDIAGPUResourceName, podRECMD))
|
2017-09-10 19:53:17 +00:00
|
|
|
|
|
|
|
By("Checking that pods got a different GPU")
|
2018-04-25 07:44:27 +00:00
|
|
|
devId2 := parseLog(f, p2.Name, p2.Name, deviceIDRE)
|
2017-12-29 10:43:38 +00:00
|
|
|
|
2017-09-18 23:10:04 +00:00
|
|
|
Expect(devId1).To(Not(Equal(devId2)))
|
2017-09-10 19:53:17 +00:00
|
|
|
|
2017-11-03 23:38:00 +00:00
|
|
|
By("Deleting device plugin.")
|
2018-07-19 08:04:58 +00:00
|
|
|
f.ClientSet.CoreV1().Pods(metav1.NamespaceSystem).Delete(devicePluginPod.Name, &metav1.DeleteOptions{})
|
2017-11-03 23:38:00 +00:00
|
|
|
By("Waiting for GPUs to become unavailable on the local node")
|
|
|
|
Eventually(func() bool {
|
2017-11-28 23:18:17 +00:00
|
|
|
node, err := f.ClientSet.CoreV1().Nodes().Get(framework.TestContext.NodeName, metav1.GetOptions{})
|
|
|
|
framework.ExpectNoError(err)
|
|
|
|
return framework.NumberOfNVIDIAGPUs(node) <= 0
|
2017-11-03 23:38:00 +00:00
|
|
|
}, 10*time.Minute, framework.Poll).Should(BeTrue())
|
|
|
|
By("Checking that scheduled pods can continue to run even after we delete device plugin.")
|
2018-04-25 07:44:27 +00:00
|
|
|
ensurePodContainerRestart(f, p1.Name, p1.Name)
|
|
|
|
devIdRestart1 = parseLog(f, p1.Name, p1.Name, deviceIDRE)
|
2017-11-03 23:38:00 +00:00
|
|
|
Expect(devIdRestart1).To(Equal(devId1))
|
2018-04-25 07:44:27 +00:00
|
|
|
|
|
|
|
ensurePodContainerRestart(f, p2.Name, p2.Name)
|
|
|
|
devIdRestart2 := parseLog(f, p2.Name, p2.Name, deviceIDRE)
|
2017-11-03 23:38:00 +00:00
|
|
|
Expect(devIdRestart2).To(Equal(devId2))
|
|
|
|
By("Restarting Kubelet.")
|
2017-12-29 10:43:38 +00:00
|
|
|
restartKubelet()
|
2017-11-03 23:38:00 +00:00
|
|
|
By("Checking that scheduled pods can continue to run even after we delete device plugin and restart Kubelet.")
|
2018-04-25 07:44:27 +00:00
|
|
|
ensurePodContainerRestart(f, p1.Name, p1.Name)
|
|
|
|
devIdRestart1 = parseLog(f, p1.Name, p1.Name, deviceIDRE)
|
2017-11-03 23:38:00 +00:00
|
|
|
Expect(devIdRestart1).To(Equal(devId1))
|
2018-04-25 07:44:27 +00:00
|
|
|
ensurePodContainerRestart(f, p2.Name, p2.Name)
|
|
|
|
devIdRestart2 = parseLog(f, p2.Name, p2.Name, deviceIDRE)
|
2017-11-03 23:38:00 +00:00
|
|
|
Expect(devIdRestart2).To(Equal(devId2))
|
2017-11-08 21:12:28 +00:00
|
|
|
logDevicePluginMetrics()
|
2017-11-03 23:38:00 +00:00
|
|
|
|
2017-09-10 19:53:17 +00:00
|
|
|
// Cleanup
|
|
|
|
f.PodClient().DeleteSync(p1.Name, &metav1.DeleteOptions{}, framework.DefaultPodDeletionTimeout)
|
|
|
|
f.PodClient().DeleteSync(p2.Name, &metav1.DeleteOptions{}, framework.DefaultPodDeletionTimeout)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-03-21 20:56:51 +00:00
|
|
|
func checkIfNvidiaGPUsExistOnNode() bool {
|
|
|
|
// Cannot use `lspci` because it is not installed on all distros by default.
|
|
|
|
err := exec.Command("/bin/sh", "-c", "find /sys/devices/pci* -type f | grep vendor | xargs cat | grep 0x10de").Run()
|
|
|
|
if err != nil {
|
|
|
|
framework.Logf("check for nvidia GPUs failed. Got Error: %v", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-11-08 21:12:28 +00:00
|
|
|
func logDevicePluginMetrics() {
|
2019-03-07 23:39:37 +00:00
|
|
|
ms, err := metrics.GrabKubeletMetricsWithoutProxy(framework.TestContext.NodeName+":10255", "/metrics")
|
2017-11-08 21:12:28 +00:00
|
|
|
framework.ExpectNoError(err)
|
|
|
|
for msKey, samples := range ms {
|
|
|
|
switch msKey {
|
2019-02-18 09:40:04 +00:00
|
|
|
case kubeletmetrics.KubeletSubsystem + "_" + kubeletmetrics.DevicePluginAllocationDurationKey:
|
2017-11-08 21:12:28 +00:00
|
|
|
for _, sample := range samples {
|
|
|
|
latency := sample.Value
|
|
|
|
resource := string(sample.Metric["resource_name"])
|
|
|
|
var quantile float64
|
|
|
|
if val, ok := sample.Metric[model.QuantileLabel]; ok {
|
|
|
|
var err error
|
|
|
|
if quantile, err = strconv.ParseFloat(string(val), 64); err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
framework.Logf("Metric: %v ResourceName: %v Quantile: %v Latency: %v", msKey, resource, quantile, latency)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case kubeletmetrics.KubeletSubsystem + "_" + kubeletmetrics.DevicePluginRegistrationCountKey:
|
|
|
|
for _, sample := range samples {
|
|
|
|
resource := string(sample.Metric["resource_name"])
|
|
|
|
count := sample.Value
|
|
|
|
framework.Logf("Metric: %v ResourceName: %v Count: %v", msKey, resource, count)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|