...

Source file src/k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3/defaults.go

Documentation: k8s.io/kubernetes/pkg/apis/flowcontrol/v1beta3

     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 v1beta3
    18  
    19  import (
    20  	"k8s.io/api/flowcontrol/v1beta3"
    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 *v1beta3.FlowSchemaSpec) {
    39  	if spec.MatchingPrecedence == 0 {
    40  		spec.MatchingPrecedence = FlowSchemaDefaultMatchingPrecedence
    41  	}
    42  }
    43  
    44  // SetDefaults_PriorityLevelConfiguration sets the default values for a
    45  // PriorityLevelConfiguration object. Since we need to inspect the presence
    46  // of the roundtrip annotation in order to determine whether the user has
    47  // specified a zero value for the 'NominalConcurrencyShares' field,
    48  // the defaulting logic needs visibility to the annotations field.
    49  func SetDefaults_PriorityLevelConfiguration(in *v1beta3.PriorityLevelConfiguration) {
    50  	if limited := in.Spec.Limited; limited != nil {
    51  		// for v1beta3, we apply a default value to the NominalConcurrencyShares
    52  		// field only when:
    53  		//   a) NominalConcurrencyShares == 0, and
    54  		//   b) the roundtrip annotation is not set
    55  		if _, ok := in.Annotations[v1beta3.PriorityLevelPreserveZeroConcurrencySharesKey]; !ok && limited.NominalConcurrencyShares == 0 {
    56  			limited.NominalConcurrencyShares = PriorityLevelConfigurationDefaultNominalConcurrencyShares
    57  		}
    58  	}
    59  }
    60  
    61  func SetDefaults_ExemptPriorityLevelConfiguration(eplc *v1beta3.ExemptPriorityLevelConfiguration) {
    62  	if eplc.NominalConcurrencyShares == nil {
    63  		eplc.NominalConcurrencyShares = ptr.To(int32(0))
    64  	}
    65  	if eplc.LendablePercent == nil {
    66  		eplc.LendablePercent = ptr.To(int32(0))
    67  	}
    68  }
    69  
    70  func SetDefaults_LimitedPriorityLevelConfiguration(in *v1beta3.LimitedPriorityLevelConfiguration) {
    71  	if in.LendablePercent == nil {
    72  		in.LendablePercent = ptr.To(int32(0))
    73  	}
    74  }
    75  
    76  func SetDefaults_QueuingConfiguration(cfg *v1beta3.QueuingConfiguration) {
    77  	if cfg.HandSize == 0 {
    78  		cfg.HandSize = PriorityLevelConfigurationDefaultHandSize
    79  	}
    80  	if cfg.Queues == 0 {
    81  		cfg.Queues = PriorityLevelConfigurationDefaultQueues
    82  	}
    83  	if cfg.QueueLengthLimit == 0 {
    84  		cfg.QueueLengthLimit = PriorityLevelConfigurationDefaultQueueLengthLimit
    85  	}
    86  }
    87  

View as plain text