helpers.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright 2016 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 util
  14. import (
  15. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  16. )
  17. // IsDefaultStorageClassAnnotation represents a StorageClass annotation that
  18. // marks a class as the default StorageClass
  19. const IsDefaultStorageClassAnnotation = "storageclass.kubernetes.io/is-default-class"
  20. // BetaIsDefaultStorageClassAnnotation is the beta version of IsDefaultStorageClassAnnotation.
  21. // TODO: remove Beta when no longer used
  22. const BetaIsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class"
  23. // IsDefaultAnnotationText returns a pretty Yes/No String if
  24. // the annotation is set
  25. // TODO: remove Beta when no longer needed
  26. func IsDefaultAnnotationText(obj metav1.ObjectMeta) string {
  27. if obj.Annotations[IsDefaultStorageClassAnnotation] == "true" {
  28. return "Yes"
  29. }
  30. if obj.Annotations[BetaIsDefaultStorageClassAnnotation] == "true" {
  31. return "Yes"
  32. }
  33. return "No"
  34. }
  35. // IsDefaultAnnotation returns a boolean if
  36. // the annotation is set
  37. // TODO: remove Beta when no longer needed
  38. func IsDefaultAnnotation(obj metav1.ObjectMeta) bool {
  39. if obj.Annotations[IsDefaultStorageClassAnnotation] == "true" {
  40. return true
  41. }
  42. if obj.Annotations[BetaIsDefaultStorageClassAnnotation] == "true" {
  43. return true
  44. }
  45. return false
  46. }