helpers.go 1.8 KB

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