k8s.io/kubernetes@v1.29.3/pkg/apis/flowcontrol/v1/defaults.go (about) 1 /* 2 Copyright 2023 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 v1 "k8s.io/api/flowcontrol/v1" 21 "k8s.io/utils/ptr" 22 ) 23 24 // Default settings for flow-schema 25 const ( 26 FlowSchemaDefaultMatchingPrecedence int32 = 1000 27 ) 28 29 // Default settings for priority-level-configuration 30 const ( 31 PriorityLevelConfigurationDefaultHandSize int32 = 8 32 PriorityLevelConfigurationDefaultQueues int32 = 64 33 PriorityLevelConfigurationDefaultQueueLengthLimit int32 = 50 34 PriorityLevelConfigurationDefaultNominalConcurrencyShares int32 = 30 35 ) 36 37 // SetDefaults_FlowSchema sets default values for flow schema 38 func SetDefaults_FlowSchemaSpec(spec *v1.FlowSchemaSpec) { 39 if spec.MatchingPrecedence == 0 { 40 spec.MatchingPrecedence = FlowSchemaDefaultMatchingPrecedence 41 } 42 } 43 44 func SetDefaults_ExemptPriorityLevelConfiguration(eplc *v1.ExemptPriorityLevelConfiguration) { 45 if eplc.NominalConcurrencyShares == nil { 46 eplc.NominalConcurrencyShares = new(int32) 47 *eplc.NominalConcurrencyShares = 0 48 } 49 if eplc.LendablePercent == nil { 50 eplc.LendablePercent = new(int32) 51 *eplc.LendablePercent = 0 52 } 53 } 54 55 func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1.LimitedPriorityLevelConfiguration) { 56 if lplc.NominalConcurrencyShares == nil { 57 lplc.NominalConcurrencyShares = ptr.To(PriorityLevelConfigurationDefaultNominalConcurrencyShares) 58 } 59 if lplc.LendablePercent == nil { 60 lplc.LendablePercent = new(int32) 61 *lplc.LendablePercent = 0 62 } 63 } 64 65 // SetDefaults_FlowSchema sets default values for flow schema 66 func SetDefaults_QueuingConfiguration(cfg *v1.QueuingConfiguration) { 67 if cfg.HandSize == 0 { 68 cfg.HandSize = PriorityLevelConfigurationDefaultHandSize 69 } 70 if cfg.Queues == 0 { 71 cfg.Queues = PriorityLevelConfigurationDefaultQueues 72 } 73 if cfg.QueueLengthLimit == 0 { 74 cfg.QueueLengthLimit = PriorityLevelConfigurationDefaultQueueLengthLimit 75 } 76 }