k8s.io/kubernetes@v1.29.3/test/e2e/storage/vsphere/vsphere_volume_vpxd_restart.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package vsphere 18 19 import ( 20 "context" 21 "fmt" 22 "strconv" 23 "time" 24 25 "github.com/onsi/ginkgo/v2" 26 "github.com/onsi/gomega" 27 28 v1 "k8s.io/api/core/v1" 29 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 30 "k8s.io/apimachinery/pkg/util/uuid" 31 clientset "k8s.io/client-go/kubernetes" 32 "k8s.io/kubernetes/test/e2e/feature" 33 "k8s.io/kubernetes/test/e2e/framework" 34 e2enode "k8s.io/kubernetes/test/e2e/framework/node" 35 e2epod "k8s.io/kubernetes/test/e2e/framework/pod" 36 e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" 37 "k8s.io/kubernetes/test/e2e/storage/utils" 38 admissionapi "k8s.io/pod-security-admission/api" 39 ) 40 41 /* 42 Test to verify that a volume remains attached through vpxd restart. 43 44 For the number of schedulable nodes: 45 1. Create a Volume with default options. 46 2. Create a Pod with the created Volume. 47 3. Verify that the Volume is attached. 48 4. Create a file with random contents under the Volume's mount point on the Pod. 49 5. Stop the vpxd service on the vCenter host. 50 6. Verify that the file is accessible on the Pod and that it's contents match. 51 7. Start the vpxd service on the vCenter host. 52 8. Verify that the Volume remains attached, the file is accessible on the Pod, and that it's contents match. 53 9. Delete the Pod and wait for the Volume to be detached. 54 10. Delete the Volume. 55 */ 56 var _ = utils.SIGDescribe("Verify Volume Attach Through vpxd Restart", feature.Vsphere, framework.WithSerial(), framework.WithDisruptive(), func() { 57 f := framework.NewDefaultFramework("restart-vpxd") 58 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 59 60 type node struct { 61 name string 62 kvLabels map[string]string 63 nodeInfo *NodeInfo 64 } 65 66 const ( 67 labelKey = "vsphere_e2e_label_vpxd_restart" 68 vpxdServiceName = "vmware-vpxd" 69 ) 70 71 var ( 72 client clientset.Interface 73 namespace string 74 vcNodesMap map[string][]node 75 ) 76 77 ginkgo.BeforeEach(func(ctx context.Context) { 78 // Requires SSH access to vCenter. 79 e2eskipper.SkipUnlessProviderIs("vsphere") 80 81 Bootstrap(f) 82 client = f.ClientSet 83 namespace = f.Namespace.Name 84 framework.ExpectNoError(e2enode.WaitForAllNodesSchedulable(ctx, client, f.Timeouts.NodeSchedulable)) 85 86 nodes, err := e2enode.GetReadySchedulableNodes(ctx, client) 87 framework.ExpectNoError(err) 88 numNodes := len(nodes.Items) 89 90 vcNodesMap = make(map[string][]node) 91 for i := 0; i < numNodes; i++ { 92 nodeInfo := TestContext.NodeMapper.GetNodeInfo(nodes.Items[i].Name) 93 nodeName := nodes.Items[i].Name 94 nodeLabel := "vsphere_e2e_" + string(uuid.NewUUID()) 95 e2enode.AddOrUpdateLabelOnNode(client, nodeName, labelKey, nodeLabel) 96 97 vcHost := nodeInfo.VSphere.Config.Hostname 98 vcNodesMap[vcHost] = append(vcNodesMap[vcHost], node{ 99 name: nodeName, 100 kvLabels: map[string]string{labelKey: nodeLabel}, 101 nodeInfo: nodeInfo, 102 }) 103 } 104 }) 105 106 ginkgo.It("verify volume remains attached through vpxd restart", func(ctx context.Context) { 107 e2eskipper.SkipUnlessSSHKeyPresent() 108 109 for vcHost, nodes := range vcNodesMap { 110 var ( 111 volumePaths []string 112 filePaths []string 113 fileContents []string 114 pods []*v1.Pod 115 ) 116 117 framework.Logf("Testing for nodes on vCenter host: %s", vcHost) 118 119 for i, node := range nodes { 120 ginkgo.By(fmt.Sprintf("Creating test vsphere volume %d", i)) 121 volumePath, err := node.nodeInfo.VSphere.CreateVolume(&VolumeOptions{}, node.nodeInfo.DataCenterRef) 122 framework.ExpectNoError(err) 123 volumePaths = append(volumePaths, volumePath) 124 125 ginkgo.By(fmt.Sprintf("Creating pod %d on node %v", i, node.name)) 126 podspec := getVSpherePodSpecWithVolumePaths([]string{volumePath}, node.kvLabels, nil) 127 pod, err := client.CoreV1().Pods(namespace).Create(ctx, podspec, metav1.CreateOptions{}) 128 framework.ExpectNoError(err) 129 130 ginkgo.By(fmt.Sprintf("Waiting for pod %d to be ready", i)) 131 gomega.Expect(e2epod.WaitForPodNameRunningInNamespace(ctx, client, pod.Name, namespace)).To(gomega.Succeed()) 132 133 pod, err = client.CoreV1().Pods(namespace).Get(ctx, pod.Name, metav1.GetOptions{}) 134 framework.ExpectNoError(err) 135 pods = append(pods, pod) 136 137 nodeName := pod.Spec.NodeName 138 ginkgo.By(fmt.Sprintf("Verifying that volume %v is attached to node %v", volumePath, nodeName)) 139 expectVolumeToBeAttached(ctx, nodeName, volumePath) 140 141 ginkgo.By(fmt.Sprintf("Creating a file with random content on the volume mounted on pod %d", i)) 142 filePath := fmt.Sprintf("/mnt/volume1/%v_vpxd_restart_test_%v.txt", namespace, strconv.FormatInt(time.Now().UnixNano(), 10)) 143 randomContent := fmt.Sprintf("Random Content -- %v", strconv.FormatInt(time.Now().UnixNano(), 10)) 144 err = writeContentToPodFile(namespace, pod.Name, filePath, randomContent) 145 framework.ExpectNoError(err) 146 filePaths = append(filePaths, filePath) 147 fileContents = append(fileContents, randomContent) 148 } 149 150 ginkgo.By("Stopping vpxd on the vCenter host") 151 vcAddress := vcHost + ":22" 152 err := invokeVCenterServiceControl(ctx, "stop", vpxdServiceName, vcAddress) 153 framework.ExpectNoError(err, "Unable to stop vpxd on the vCenter host") 154 155 expectFilesToBeAccessible(namespace, pods, filePaths) 156 expectFileContentsToMatch(namespace, pods, filePaths, fileContents) 157 158 ginkgo.By("Starting vpxd on the vCenter host") 159 err = invokeVCenterServiceControl(ctx, "start", vpxdServiceName, vcAddress) 160 framework.ExpectNoError(err, "Unable to start vpxd on the vCenter host") 161 162 expectVolumesToBeAttached(ctx, pods, volumePaths) 163 expectFilesToBeAccessible(namespace, pods, filePaths) 164 expectFileContentsToMatch(namespace, pods, filePaths, fileContents) 165 166 for i, node := range nodes { 167 pod := pods[i] 168 nodeName := pod.Spec.NodeName 169 volumePath := volumePaths[i] 170 171 ginkgo.By(fmt.Sprintf("Deleting pod on node %s", nodeName)) 172 err = e2epod.DeletePodWithWait(ctx, client, pod) 173 framework.ExpectNoError(err) 174 175 ginkgo.By(fmt.Sprintf("Waiting for volume %s to be detached from node %s", volumePath, nodeName)) 176 err = waitForVSphereDiskToDetach(ctx, volumePath, nodeName) 177 framework.ExpectNoError(err) 178 179 ginkgo.By(fmt.Sprintf("Deleting volume %s", volumePath)) 180 err = node.nodeInfo.VSphere.DeleteVolume(volumePath, node.nodeInfo.DataCenterRef) 181 framework.ExpectNoError(err) 182 } 183 } 184 }) 185 })