Debian Codegraph @

pkg/apis/flowcontrol/bootstrap/default_test.go

raw
1 /*
2 Copyright 2022 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 bootstrap
18
19 import (
20 "testing"
21
22 flowcontrol "k8s.io/api/flowcontrol/v1"
23 )
24
25 func TestBootstrapPriorityLevelConfigurationWithBorrowing(t *testing.T) {
26 tests := []struct {
27 name string
28 nominalSharesExpected int32
29 lendablePercentexpected int32
30 }{
31 {
32 name: "leader-election",
33 nominalSharesExpected: 10,
34 lendablePercentexpected: 0,
35 },
36 {
37 name: "node-high",
38 nominalSharesExpected: 40,
39 lendablePercentexpected: 25,
40 },
41 {
42 name: "system",
43 nominalSharesExpected: 30,
44 lendablePercentexpected: 33,
45 },
46 {
47 name: "workload-high",
48 nominalSharesExpected: 40,
49 lendablePercentexpected: 50,
50 },
51 {
52 name: "workload-low",
53 nominalSharesExpected: 100,
54 lendablePercentexpected: 90,
55 },
56 {
57 name: "global-default",
58 nominalSharesExpected: 20,
59 lendablePercentexpected: 50,
60 },
61 {
62 name: "catch-all",
63 nominalSharesExpected: 5,
64 lendablePercentexpected: 0,
65 },
66 }
67
68 bootstrapPLs := func() map[string]*flowcontrol.PriorityLevelConfiguration {
69 list := make([]*flowcontrol.PriorityLevelConfiguration, 0)
70 list = append(list, MandatoryPriorityLevelConfigurations...)
71 list = append(list, SuggestedPriorityLevelConfigurations...)
72
73 m := map[string]*flowcontrol.PriorityLevelConfiguration{}
74 for i := range list {
75 m[list[i].Name] = list[i]
76 }
77 return m
78 }()
79
80 for _, test := range tests {
81 bootstrapPL := bootstrapPLs[test.name]
82 if bootstrapPL == nil {
83 t.Errorf("Expected bootstrap PriorityLevelConfiguration %q, but not found in bootstrap configuration", test.name)
84 continue
85 }
86 delete(bootstrapPLs, test.name)
87
88 if bootstrapPL.Spec.Type != flowcontrol.PriorityLevelEnablementLimited {
89 t.Errorf("bootstrap PriorityLevelConfiguration %q is not %q", test.name, flowcontrol.PriorityLevelEnablementLimited)
90 continue
91 }
92 if test.nominalSharesExpected != *bootstrapPL.Spec.Limited.NominalConcurrencyShares {
93 t.Errorf("bootstrap PriorityLevelConfiguration %q: expected NominalConcurrencyShares: %d, but got: %d", test.name, test.nominalSharesExpected, bootstrapPL.Spec.Limited.NominalConcurrencyShares)
94 }
95 if test.lendablePercentexpected != *bootstrapPL.Spec.Limited.LendablePercent {
96 t.Errorf("bootstrap PriorityLevelConfiguration %q: expected NominalConcurrencyShares: %d, but got: %d", test.name, test.lendablePercentexpected, bootstrapPL.Spec.Limited.LendablePercent)
97 }
98 if bootstrapPL.Spec.Limited.BorrowingLimitPercent != nil {
99 t.Errorf("bootstrap PriorityLevelConfiguration %q: expected BorrowingLimitPercent to be nil, but got: %d", test.name, *bootstrapPL.Spec.Limited.BorrowingLimitPercent)
100 }
101 }
102
103 if len(bootstrapPLs) != 0 {
104 names := make([]string, 0)
105 for name, bpl := range bootstrapPLs {
106 if bpl.Spec.Type == flowcontrol.PriorityLevelEnablementExempt {
107 t.Logf("bootstrap PriorityLevelConfiguration %q is of %q type, skipped", name, flowcontrol.PriorityLevelConfigurationNameExempt)
108 continue
109 }
110 names = append(names, name)
111 }
112
113 if len(names) != 0 {
114 t.Errorf("bootstrap PriorityLevelConfiguration objects not accounted by this test: %v", names)
115 }
116 }
117 exemptPL := MandatoryPriorityLevelConfigurationExempt
118 if exemptPL.Spec.Exempt.NominalConcurrencyShares != nil && *exemptPL.Spec.Exempt.NominalConcurrencyShares != 0 {
119 t.Errorf("Expected exempt priority level to have NominalConcurrencyShares==0 but got %d instead", *exemptPL.Spec.Exempt.NominalConcurrencyShares)
120 }
121 if exemptPL.Spec.Exempt.LendablePercent != nil && *exemptPL.Spec.Exempt.LendablePercent != 0 {
122 t.Errorf("Expected exempt priority level to have LendablePercent==0 but got %d instead", *exemptPL.Spec.Exempt.LendablePercent)
123 }
124 }