size.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright 2015 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 framework
  14. import (
  15. "fmt"
  16. "time"
  17. )
  18. // ResizeGroup resizes an instance group
  19. func ResizeGroup(group string, size int32) error {
  20. if TestContext.ReportDir != "" {
  21. CoreDump(TestContext.ReportDir)
  22. defer CoreDump(TestContext.ReportDir)
  23. }
  24. return TestContext.CloudConfig.Provider.ResizeGroup(group, size)
  25. }
  26. // GetGroupNodes returns a node name for the specified node group
  27. func GetGroupNodes(group string) ([]string, error) {
  28. return TestContext.CloudConfig.Provider.GetGroupNodes(group)
  29. }
  30. // GroupSize returns the size of an instance group
  31. func GroupSize(group string) (int, error) {
  32. return TestContext.CloudConfig.Provider.GroupSize(group)
  33. }
  34. // WaitForGroupSize waits for node instance group reached the desired size
  35. func WaitForGroupSize(group string, size int32) error {
  36. timeout := 30 * time.Minute
  37. for start := time.Now(); time.Since(start) < timeout; time.Sleep(20 * time.Second) {
  38. currentSize, err := GroupSize(group)
  39. if err != nil {
  40. Logf("Failed to get node instance group size: %v", err)
  41. continue
  42. }
  43. if currentSize != int(size) {
  44. Logf("Waiting for node instance group size %d, current size %d", size, currentSize)
  45. continue
  46. }
  47. Logf("Node instance group has reached the desired size %d", size)
  48. return nil
  49. }
  50. return fmt.Errorf("timeout waiting %v for node instance group size to be %d", timeout, size)
  51. }