bootstrap.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. Copyright 2018 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package vsphere
  14. import (
  15. "context"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. "k8s.io/kubernetes/test/e2e/framework"
  18. "sync"
  19. )
  20. var once sync.Once
  21. var waiting = make(chan bool)
  22. var f *framework.Framework
  23. // Bootstrap takes care of initializing necessary test context for vSphere tests
  24. func Bootstrap(fw *framework.Framework) {
  25. done := make(chan bool)
  26. f = fw
  27. go func() {
  28. once.Do(bootstrapOnce)
  29. <-waiting
  30. done <- true
  31. }()
  32. <-done
  33. }
  34. func bootstrapOnce() {
  35. // 1. Read vSphere conf and get VSphere instances
  36. vsphereInstances, err := GetVSphereInstances()
  37. if err != nil {
  38. framework.Failf("Failed to bootstrap vSphere with error: %v", err)
  39. }
  40. // 2. Get all nodes
  41. nodeList, err := f.ClientSet.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
  42. if err != nil {
  43. framework.Failf("Failed to get nodes: %v", err)
  44. }
  45. TestContext = Context{NodeMapper: &NodeMapper{}, VSphereInstances: vsphereInstances}
  46. // 3. Get Node to VSphere mapping
  47. err = TestContext.NodeMapper.GenerateNodeMap(vsphereInstances, *nodeList)
  48. if err != nil {
  49. framework.Failf("Failed to bootstrap vSphere with error: %v", err)
  50. }
  51. // 4. Generate Zone to Datastore mapping
  52. err = TestContext.NodeMapper.GenerateZoneToDatastoreMap()
  53. if err != nil {
  54. framework.Failf("Failed to generate zone to datastore mapping with error: %v", err)
  55. }
  56. close(waiting)
  57. }