k8s.io/kubernetes@v1.29.3/test/e2e/storage/vsphere/vsphere_volume_node_delete.go (about) 1 /* 2 Copyright 2017 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 22 "github.com/onsi/ginkgo/v2" 23 "github.com/onsi/gomega" 24 "github.com/vmware/govmomi/object" 25 26 clientset "k8s.io/client-go/kubernetes" 27 "k8s.io/kubernetes/test/e2e/feature" 28 "k8s.io/kubernetes/test/e2e/framework" 29 e2enode "k8s.io/kubernetes/test/e2e/framework/node" 30 e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" 31 "k8s.io/kubernetes/test/e2e/storage/utils" 32 admissionapi "k8s.io/pod-security-admission/api" 33 ) 34 35 var _ = utils.SIGDescribe("Node Unregister", feature.Vsphere, framework.WithSlow(), framework.WithDisruptive(), func() { 36 f := framework.NewDefaultFramework("node-unregister") 37 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 38 var ( 39 client clientset.Interface 40 namespace string 41 workingDir string 42 err error 43 ) 44 45 ginkgo.BeforeEach(func(ctx context.Context) { 46 e2eskipper.SkipUnlessProviderIs("vsphere") 47 Bootstrap(f) 48 client = f.ClientSet 49 namespace = f.Namespace.Name 50 framework.ExpectNoError(e2enode.WaitForAllNodesSchedulable(ctx, client, f.Timeouts.NodeSchedulable)) 51 framework.ExpectNoError(err) 52 workingDir = GetAndExpectStringEnvVar("VSPHERE_WORKING_DIR") 53 }) 54 55 ginkgo.It("node unregister", func(ctx context.Context) { 56 ginkgo.By("Get total Ready nodes") 57 nodeList, err := e2enode.GetReadySchedulableNodes(ctx, f.ClientSet) 58 framework.ExpectNoError(err) 59 if len(nodeList.Items) < 2 { 60 framework.Failf("At least 2 nodes are required for this test, got instead: %v", len(nodeList.Items)) 61 } 62 63 totalNodesCount := len(nodeList.Items) 64 nodeVM := nodeList.Items[0] 65 66 nodeInfo := TestContext.NodeMapper.GetNodeInfo(nodeVM.ObjectMeta.Name) 67 vmObject := object.NewVirtualMachine(nodeInfo.VSphere.Client.Client, nodeInfo.VirtualMachineRef) 68 69 // Find VM .vmx file path, host, resource pool. 70 // They are required to register a node VM to VC 71 vmxFilePath := getVMXFilePath(ctx, vmObject) 72 73 vmHost, err := vmObject.HostSystem(ctx) 74 framework.ExpectNoError(err) 75 76 vmPool, err := vmObject.ResourcePool(ctx) 77 framework.ExpectNoError(err) 78 79 // Unregister Node VM 80 ginkgo.By("Unregister a node VM") 81 unregisterNodeVM(ctx, nodeVM.ObjectMeta.Name, vmObject) 82 83 // Ready nodes should be 1 less 84 ginkgo.By("Verifying the ready node counts") 85 if !verifyReadyNodeCount(ctx, f.ClientSet, totalNodesCount-1) { 86 framework.Failf("Unable to verify expected ready node count. Total Nodes: %d, Expected Ready Nodes: %d", totalNodesCount, totalNodesCount-1) 87 } 88 89 nodeList, err = e2enode.GetReadySchedulableNodes(ctx, client) 90 framework.ExpectNoError(err) 91 92 var nodeNameList []string 93 for _, node := range nodeList.Items { 94 nodeNameList = append(nodeNameList, node.ObjectMeta.Name) 95 } 96 gomega.Expect(nodeNameList).NotTo(gomega.ContainElement(nodeVM.ObjectMeta.Name)) 97 98 // Register Node VM 99 ginkgo.By("Register back the node VM") 100 registerNodeVM(ctx, nodeVM.ObjectMeta.Name, workingDir, vmxFilePath, vmPool, vmHost) 101 102 // Ready nodes should be equal to earlier count 103 ginkgo.By("Verifying the ready node counts") 104 if !verifyReadyNodeCount(ctx, f.ClientSet, totalNodesCount) { 105 framework.Failf("Unable to verify expected ready node count. Total Nodes: %d, Expected Ready Nodes: %d", totalNodesCount, totalNodesCount) 106 } 107 108 nodeList, err = e2enode.GetReadySchedulableNodes(ctx, client) 109 framework.ExpectNoError(err) 110 111 nodeNameList = nodeNameList[:0] 112 for _, node := range nodeList.Items { 113 nodeNameList = append(nodeNameList, node.ObjectMeta.Name) 114 } 115 gomega.Expect(nodeNameList).To(gomega.ContainElement(nodeVM.ObjectMeta.Name)) 116 117 // Sanity test that pod provisioning works 118 ginkgo.By("Sanity check for volume lifecycle") 119 scParameters := make(map[string]string) 120 storagePolicy := GetAndExpectStringEnvVar("VSPHERE_SPBM_GOLD_POLICY") 121 scParameters[SpbmStoragePolicy] = storagePolicy 122 invokeValidPolicyTest(ctx, f, client, namespace, scParameters) 123 }) 124 })