storage.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 utils
  14. // Source: https://github.com/kubernetes/kubernetes/blob/v1.21.1/pkg/apis/storage/v1/util/helpers.go
  15. import (
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. )
  18. // isDefaultStorageClassAnnotation represents a StorageClass annotation that
  19. // marks a class as the default StorageClass
  20. const isDefaultStorageClassAnnotation = "storageclass.kubernetes.io/is-default-class"
  21. // betaIsDefaultStorageClassAnnotation is the beta version of IsDefaultStorageClassAnnotation.
  22. // TODO: remove Beta when no longer used
  23. const betaIsDefaultStorageClassAnnotation = "storageclass.beta.kubernetes.io/is-default-class"
  24. // isDefaultAnnotation returns a boolean if
  25. // the annotation is set
  26. // TODO: remove Beta when no longer needed
  27. func isDefaultAnnotation(obj metav1.ObjectMeta) bool {
  28. if obj.Annotations[isDefaultStorageClassAnnotation] == "true" {
  29. return true
  30. }
  31. if obj.Annotations[betaIsDefaultStorageClassAnnotation] == "true" {
  32. return true
  33. }
  34. return false
  35. }