volume_limits.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 storage
  14. import (
  15. "github.com/onsi/ginkgo"
  16. "k8s.io/api/core/v1"
  17. clientset "k8s.io/client-go/kubernetes"
  18. v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
  19. "k8s.io/kubernetes/test/e2e/framework"
  20. e2enode "k8s.io/kubernetes/test/e2e/framework/node"
  21. e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
  22. "k8s.io/kubernetes/test/e2e/storage/utils"
  23. )
  24. var _ = utils.SIGDescribe("Volume limits", func() {
  25. var (
  26. c clientset.Interface
  27. )
  28. f := framework.NewDefaultFramework("volume-limits-on-node")
  29. ginkgo.BeforeEach(func() {
  30. e2eskipper.SkipUnlessProviderIs("aws", "gce", "gke")
  31. c = f.ClientSet
  32. framework.ExpectNoError(framework.WaitForAllNodesSchedulable(c, framework.TestContext.NodeSchedulableTimeout))
  33. })
  34. ginkgo.It("should verify that all nodes have volume limits", func() {
  35. nodeList, err := e2enode.GetReadySchedulableNodes(f.ClientSet)
  36. framework.ExpectNoError(err)
  37. for _, node := range nodeList.Items {
  38. volumeLimits := getVolumeLimit(&node)
  39. if len(volumeLimits) == 0 {
  40. framework.Failf("Expected volume limits to be set")
  41. }
  42. }
  43. })
  44. })
  45. func getVolumeLimit(node *v1.Node) map[v1.ResourceName]int64 {
  46. volumeLimits := map[v1.ResourceName]int64{}
  47. nodeAllocatables := node.Status.Allocatable
  48. for k, v := range nodeAllocatables {
  49. if v1helper.IsAttachableVolumeResourceName(k) {
  50. volumeLimits[k] = v.Value()
  51. }
  52. }
  53. return volumeLimits
  54. }