bootstrap.go 1.9 KB

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