...

Source file src/k8s.io/kubernetes/pkg/apis/scheduling/v1/helpers.go

Documentation: k8s.io/kubernetes/pkg/apis/scheduling/v1

     1  /*
     2  Copyright 2019 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1
    18  
    19  import (
    20  	"fmt"
    21  	"k8s.io/api/scheduling/v1"
    22  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    23  	"k8s.io/kubernetes/pkg/apis/scheduling"
    24  )
    25  
    26  // SystemPriorityClasses define system priority classes that are auto-created at cluster bootstrapping.
    27  // Our API validation logic ensures that any priority class that has a system prefix or its value
    28  // is higher than HighestUserDefinablePriority is equal to one of these SystemPriorityClasses.
    29  var systemPriorityClasses = []*v1.PriorityClass{
    30  	{
    31  		ObjectMeta: metav1.ObjectMeta{
    32  			Name: scheduling.SystemNodeCritical,
    33  		},
    34  		Value:       scheduling.SystemCriticalPriority + 1000,
    35  		Description: "Used for system critical pods that must not be moved from their current node.",
    36  	},
    37  	{
    38  		ObjectMeta: metav1.ObjectMeta{
    39  			Name: scheduling.SystemClusterCritical,
    40  		},
    41  		Value:       scheduling.SystemCriticalPriority,
    42  		Description: "Used for system critical pods that must run in the cluster, but can be moved to another node if necessary.",
    43  	},
    44  }
    45  
    46  // SystemPriorityClasses returns the list of system priority classes.
    47  // NOTE: be careful not to modify any of elements of the returned array directly.
    48  func SystemPriorityClasses() []*v1.PriorityClass {
    49  	return systemPriorityClasses
    50  }
    51  
    52  // IsKnownSystemPriorityClass returns true if there's any of the system priority classes exactly
    53  // matches "name", "value", "globalDefault". otherwise it will return an error.
    54  func IsKnownSystemPriorityClass(name string, value int32, globalDefault bool) (bool, error) {
    55  	for _, spc := range SystemPriorityClasses() {
    56  		if spc.Name == name {
    57  			if spc.Value != value {
    58  				return false, fmt.Errorf("value of %v PriorityClass must be %v", spc.Name, spc.Value)
    59  			}
    60  			if spc.GlobalDefault != globalDefault {
    61  				return false, fmt.Errorf("globalDefault of %v PriorityClass must be %v", spc.Name, spc.GlobalDefault)
    62  			}
    63  			return true, nil
    64  		}
    65  	}
    66  	return false, fmt.Errorf("%v is not a known system priority class", name)
    67  }
    68  

View as plain text