...

Source file src/k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/policy_best_effort_test.go

Documentation: k8s.io/kubernetes/pkg/kubelet/cm/topologymanager

     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 topologymanager
    18  
    19  import (
    20  	"testing"
    21  )
    22  
    23  func TestPolicyBestEffortCanAdmitPodResult(t *testing.T) {
    24  	tcases := []struct {
    25  		name     string
    26  		hint     TopologyHint
    27  		expected bool
    28  	}{
    29  		{
    30  			name:     "Preferred is set to false in topology hints",
    31  			hint:     TopologyHint{nil, false},
    32  			expected: true,
    33  		},
    34  		{
    35  			name:     "Preferred is set to true in topology hints",
    36  			hint:     TopologyHint{nil, true},
    37  			expected: true,
    38  		},
    39  	}
    40  
    41  	for _, tc := range tcases {
    42  		numaInfo := commonNUMAInfoTwoNodes()
    43  		policy := &bestEffortPolicy{numaInfo: numaInfo}
    44  		result := policy.canAdmitPodResult(&tc.hint)
    45  
    46  		if result != tc.expected {
    47  			t.Errorf("Expected result to be %t, got %t", tc.expected, result)
    48  		}
    49  	}
    50  }
    51  
    52  func TestPolicyBestEffortMerge(t *testing.T) {
    53  	numaInfo := commonNUMAInfoFourNodes()
    54  	policy := &bestEffortPolicy{numaInfo: numaInfo}
    55  
    56  	tcases := commonPolicyMergeTestCases(numaInfo.Nodes)
    57  	tcases = append(tcases, policy.mergeTestCases(numaInfo.Nodes)...)
    58  	tcases = append(tcases, policy.mergeTestCasesNoPolicies(numaInfo.Nodes)...)
    59  
    60  	testPolicyMerge(policy, tcases, t)
    61  }
    62  
    63  func TestPolicyBestEffortMergeClosestNUMA(t *testing.T) {
    64  	numaInfo := commonNUMAInfoEightNodes()
    65  	opts := PolicyOptions{
    66  		PreferClosestNUMA: true,
    67  	}
    68  	policy := &bestEffortPolicy{numaInfo: numaInfo, opts: opts}
    69  
    70  	tcases := commonPolicyMergeTestCases(numaInfo.Nodes)
    71  	tcases = append(tcases, policy.mergeTestCases(numaInfo.Nodes)...)
    72  	tcases = append(tcases, policy.mergeTestCasesClosestNUMA(numaInfo.Nodes)...)
    73  
    74  	testPolicyMerge(policy, tcases, t)
    75  }
    76  

View as plain text