k8s.io/kubernetes@v1.29.3/test/e2e/storage/vsphere/bootstrap.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 "sync" 22 23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 "k8s.io/kubernetes/test/e2e/framework" 25 ) 26 27 var once sync.Once 28 var waiting = make(chan bool) 29 30 // Bootstrap takes care of initializing necessary test context for vSphere tests 31 func Bootstrap(fw *framework.Framework) { 32 done := make(chan bool) 33 go func() { 34 once.Do(func() { 35 bootstrapOnce(fw) 36 }) 37 <-waiting 38 done <- true 39 }() 40 <-done 41 } 42 43 func bootstrapOnce(f *framework.Framework) { 44 // 1. Read vSphere conf and get VSphere instances 45 vsphereInstances, err := GetVSphereInstances() 46 if err != nil { 47 framework.Failf("Failed to bootstrap vSphere with error: %v", err) 48 } 49 // 2. Get all nodes 50 nodeList, err := f.ClientSet.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) 51 if err != nil { 52 framework.Failf("Failed to get nodes: %v", err) 53 } 54 TestContext = Context{NodeMapper: NewNodeMapper(), VSphereInstances: vsphereInstances} 55 // 3. Get Node to VSphere mapping 56 err = TestContext.NodeMapper.GenerateNodeMap(vsphereInstances, *nodeList) 57 if err != nil { 58 framework.Failf("Failed to bootstrap vSphere with error: %v", err) 59 } 60 // 4. Generate Zone to Datastore mapping 61 err = TestContext.NodeMapper.GenerateZoneToDatastoreMap() 62 if err != nil { 63 framework.Failf("Failed to generate zone to datastore mapping with error: %v", err) 64 } 65 close(waiting) 66 }