...

Source file src/k8s.io/kubernetes/pkg/apis/scheduling/v1/helpers_test.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  	"testing"
    21  
    22  	v1 "k8s.io/api/scheduling/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  	"k8s.io/kubernetes/pkg/apis/scheduling"
    25  )
    26  
    27  func TestIsKnownSystemPriorityClass(t *testing.T) {
    28  	tests := []struct {
    29  		name     string
    30  		pc       *v1.PriorityClass
    31  		expected bool
    32  	}{
    33  		{
    34  			name:     "system priority class",
    35  			pc:       SystemPriorityClasses()[0],
    36  			expected: true,
    37  		},
    38  		{
    39  			name: "non-system priority class",
    40  			pc: &v1.PriorityClass{
    41  				ObjectMeta: metav1.ObjectMeta{
    42  					Name: scheduling.SystemNodeCritical,
    43  				},
    44  				Value:       scheduling.SystemCriticalPriority, // This is the value of system cluster critical
    45  				Description: "Used for system critical pods that must not be moved from their current node.",
    46  			},
    47  			expected: false,
    48  		},
    49  		{
    50  			name: "not a known system priority class",
    51  			pc: &v1.PriorityClass{
    52  				ObjectMeta: metav1.ObjectMeta{
    53  					Name: "unknown",
    54  				},
    55  				Value:       scheduling.SystemCriticalPriority,
    56  				Description: "Used for system critical pods that must run in the cluster, but can be moved to another node if necessary.",
    57  			},
    58  			expected: false,
    59  		},
    60  		{
    61  			name: "global default changed",
    62  			pc: &v1.PriorityClass{
    63  				ObjectMeta: metav1.ObjectMeta{
    64  					Name: scheduling.SystemClusterCritical,
    65  				},
    66  				GlobalDefault: true,
    67  				Value:         scheduling.SystemCriticalPriority,
    68  				Description:   "Used for system critical pods that must run in the cluster, but can be moved to another node if necessary.",
    69  			},
    70  			expected: false,
    71  		},
    72  	}
    73  
    74  	for _, test := range tests {
    75  		if is, err := IsKnownSystemPriorityClass(test.pc.Name, test.pc.Value, test.pc.GlobalDefault); test.expected != is {
    76  			t.Errorf("Test [%v]: Expected %v, but got %v. Error: %v", test.name, test.expected, is, err)
    77  		}
    78  	}
    79  }
    80  

View as plain text