helpers.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 scheduling
  14. import (
  15. "fmt"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. )
  18. // SystemPriorityClasses define system priority classes that are auto-created at cluster bootstrapping.
  19. // Our API validation logic ensures that any priority class that has a system prefix or its value
  20. // is higher than HighestUserDefinablePriority is equal to one of these SystemPriorityClasses.
  21. var systemPriorityClasses = []*PriorityClass{
  22. {
  23. ObjectMeta: metav1.ObjectMeta{
  24. Name: SystemNodeCritical,
  25. },
  26. Value: SystemCriticalPriority + 1000,
  27. Description: "Used for system critical pods that must not be moved from their current node.",
  28. },
  29. {
  30. ObjectMeta: metav1.ObjectMeta{
  31. Name: SystemClusterCritical,
  32. },
  33. Value: SystemCriticalPriority,
  34. Description: "Used for system critical pods that must run in the cluster, but can be moved to another node if necessary.",
  35. },
  36. }
  37. // SystemPriorityClasses returns the list of system priority classes.
  38. // NOTE: be careful not to modify any of elements of the returned array directly.
  39. func SystemPriorityClasses() []*PriorityClass {
  40. return systemPriorityClasses
  41. }
  42. // IsKnownSystemPriorityClass checks that "pc" is equal to one of the system PriorityClasses.
  43. // It ignores "description", labels, annotations, etc. of the PriorityClass.
  44. func IsKnownSystemPriorityClass(pc *PriorityClass) (bool, error) {
  45. for _, spc := range systemPriorityClasses {
  46. if spc.Name == pc.Name {
  47. if spc.Value != pc.Value {
  48. return false, fmt.Errorf("value of %v PriorityClass must be %v", spc.Name, spc.Value)
  49. }
  50. if spc.GlobalDefault != pc.GlobalDefault {
  51. return false, fmt.Errorf("globalDefault of %v PriorityClass must be %v", spc.Name, spc.GlobalDefault)
  52. }
  53. return true, nil
  54. }
  55. }
  56. return false, fmt.Errorf("%v is not a known system priority class", pc.Name)
  57. }