size.go 2.0 KB

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