2016-11-14 17:44:28 -05:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-11-06 22:59:05 -05:00
|
|
|
package e2enode
|
2016-11-14 17:44:28 -05:00
|
|
|
|
|
|
|
|
import (
|
2020-02-07 21:16:47 -05:00
|
|
|
"context"
|
2016-11-14 17:44:28 -05:00
|
|
|
"time"
|
|
|
|
|
|
2017-06-22 14:24:23 -04:00
|
|
|
"k8s.io/api/core/v1"
|
2017-01-16 22:38:19 -05:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-01-24 09:35:22 -05:00
|
|
|
"k8s.io/apimachinery/pkg/util/uuid"
|
2016-11-14 17:44:28 -05:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2019-05-07 20:09:50 -04:00
|
|
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
2016-11-14 17:44:28 -05:00
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2019-07-28 00:49:36 -04:00
|
|
|
"github.com/onsi/ginkgo"
|
2016-11-14 17:44:28 -05:00
|
|
|
)
|
|
|
|
|
|
2021-02-22 13:53:33 -05:00
|
|
|
var _ = SIGDescribe("Kubelet Volume Manager", func() {
|
2016-11-14 17:44:28 -05:00
|
|
|
f := framework.NewDefaultFramework("kubelet-volume-manager")
|
2019-07-28 00:49:36 -04:00
|
|
|
ginkgo.Describe("Volume Manager", func() {
|
2021-02-25 04:44:15 -05:00
|
|
|
ginkgo.Context("On termination of pod with memory backed volume", func() {
|
2019-07-28 00:49:36 -04:00
|
|
|
ginkgo.It("should remove the volume from the node [NodeConformance]", func() {
|
2016-11-14 17:44:28 -05:00
|
|
|
var (
|
2016-11-18 15:55:46 -05:00
|
|
|
memoryBackedPod *v1.Pod
|
2016-11-14 17:44:28 -05:00
|
|
|
volumeName string
|
|
|
|
|
)
|
2019-07-28 00:49:36 -04:00
|
|
|
ginkgo.By("Creating a pod with a memory backed volume that exits success without restart", func() {
|
2016-11-14 17:44:28 -05:00
|
|
|
volumeName = "memory-volume"
|
2016-11-18 15:55:46 -05:00
|
|
|
memoryBackedPod = f.PodClient().Create(&v1.Pod{
|
2017-01-16 22:38:19 -05:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-11-14 17:44:28 -05:00
|
|
|
Name: "pod" + string(uuid.NewUUID()),
|
|
|
|
|
Namespace: f.Namespace.Name,
|
|
|
|
|
},
|
2016-11-18 15:55:46 -05:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
|
RestartPolicy: v1.RestartPolicyNever,
|
|
|
|
|
Containers: []v1.Container{
|
2016-11-14 17:44:28 -05:00
|
|
|
{
|
2017-08-29 04:32:08 -04:00
|
|
|
Image: busyboxImage,
|
2016-11-14 17:44:28 -05:00
|
|
|
Name: "container" + string(uuid.NewUUID()),
|
|
|
|
|
Command: []string{"sh", "-c", "echo"},
|
2016-11-18 15:55:46 -05:00
|
|
|
VolumeMounts: []v1.VolumeMount{
|
2016-11-14 17:44:28 -05:00
|
|
|
{
|
|
|
|
|
Name: volumeName,
|
|
|
|
|
MountPath: "/tmp",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2016-11-18 15:55:46 -05:00
|
|
|
Volumes: []v1.Volume{
|
2016-11-14 17:44:28 -05:00
|
|
|
{
|
|
|
|
|
Name: volumeName,
|
2016-11-18 15:55:46 -05:00
|
|
|
VolumeSource: v1.VolumeSource{
|
|
|
|
|
EmptyDir: &v1.EmptyDirVolumeSource{Medium: v1.StorageMediumMemory},
|
2016-11-14 17:44:28 -05:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
2019-05-07 20:09:50 -04:00
|
|
|
err := e2epod.WaitForPodSuccessInNamespace(f.ClientSet, memoryBackedPod.Name, f.Namespace.Name)
|
2019-06-08 13:44:08 -04:00
|
|
|
framework.ExpectNoError(err)
|
2016-11-14 17:44:28 -05:00
|
|
|
})
|
2019-07-28 00:49:36 -04:00
|
|
|
ginkgo.By("Verifying the memory backed volume was removed from node", func() {
|
2016-11-14 17:44:28 -05:00
|
|
|
volumePath := fmt.Sprintf("/tmp/%s/volumes/kubernetes.io~empty-dir/%s", string(memoryBackedPod.UID), volumeName)
|
|
|
|
|
var err error
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
// need to create a new verification pod on each pass since updates
|
|
|
|
|
//to the HostPath volume aren't propogated to the pod
|
2016-11-18 15:55:46 -05:00
|
|
|
pod := f.PodClient().Create(&v1.Pod{
|
2017-01-16 22:38:19 -05:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-11-14 17:44:28 -05:00
|
|
|
Name: "pod" + string(uuid.NewUUID()),
|
|
|
|
|
Namespace: f.Namespace.Name,
|
|
|
|
|
},
|
2016-11-18 15:55:46 -05:00
|
|
|
Spec: v1.PodSpec{
|
|
|
|
|
RestartPolicy: v1.RestartPolicyNever,
|
|
|
|
|
Containers: []v1.Container{
|
2016-11-14 17:44:28 -05:00
|
|
|
{
|
2017-08-29 04:32:08 -04:00
|
|
|
Image: busyboxImage,
|
2016-11-14 17:44:28 -05:00
|
|
|
Name: "container" + string(uuid.NewUUID()),
|
|
|
|
|
Command: []string{"sh", "-c", "if [ -d " + volumePath + " ]; then exit 1; fi;"},
|
2016-11-18 15:55:46 -05:00
|
|
|
VolumeMounts: []v1.VolumeMount{
|
2016-11-14 17:44:28 -05:00
|
|
|
{
|
|
|
|
|
Name: "kubelet-pods",
|
|
|
|
|
MountPath: "/tmp",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2016-11-18 15:55:46 -05:00
|
|
|
Volumes: []v1.Volume{
|
2016-11-14 17:44:28 -05:00
|
|
|
{
|
|
|
|
|
Name: "kubelet-pods",
|
2016-11-18 15:55:46 -05:00
|
|
|
VolumeSource: v1.VolumeSource{
|
2016-11-14 17:44:28 -05:00
|
|
|
// TODO: remove hardcoded kubelet volume directory path
|
|
|
|
|
// framework.TestContext.KubeVolumeDir is currently not populated for node e2e
|
2016-11-18 15:55:46 -05:00
|
|
|
HostPath: &v1.HostPathVolumeSource{Path: "/var/lib/kubelet/pods"},
|
2016-11-14 17:44:28 -05:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
2019-05-07 20:09:50 -04:00
|
|
|
err = e2epod.WaitForPodSuccessInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
|
2016-11-14 17:44:28 -05:00
|
|
|
gp := int64(1)
|
2020-03-01 12:24:42 -05:00
|
|
|
f.PodClient().Delete(context.TODO(), pod.Name, metav1.DeleteOptions{GracePeriodSeconds: &gp})
|
2016-11-14 17:44:28 -05:00
|
|
|
if err == nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
<-time.After(10 * time.Second)
|
|
|
|
|
}
|
2019-06-08 13:44:08 -04:00
|
|
|
framework.ExpectNoError(err)
|
2016-11-14 17:44:28 -05:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|