k8s.io/kubernetes@v1.29.3/pkg/apis/flowcontrol/internalbootstrap/default-internal.go (about) 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 internalbootstrap 18 19 import ( 20 flowcontrolv1 "k8s.io/api/flowcontrol/v1" 21 "k8s.io/apimachinery/pkg/runtime" 22 "k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap" 23 "k8s.io/kubernetes/pkg/apis/flowcontrol" 24 "k8s.io/kubernetes/pkg/apis/flowcontrol/install" 25 ) 26 27 // MandatoryFlowSchemas holds the untyped renditions of the mandatory 28 // flow schemas. In this map the key is the schema's name and the 29 // value is the `*FlowSchema`. Nobody should mutate anything 30 // reachable from this map. 31 var MandatoryFlowSchemas = internalizeFSes(bootstrap.MandatoryFlowSchemas) 32 33 // MandatoryPriorityLevelConfigurations holds the untyped renditions of the 34 // mandatory priority level configuration objects. In this map the 35 // key is the object's name and the value is the 36 // `*PriorityLevelConfiguration`. Nobody should mutate anything 37 // reachable from this map. 38 var MandatoryPriorityLevelConfigurations = internalizePLs(bootstrap.MandatoryPriorityLevelConfigurations) 39 40 // NewAPFScheme constructs and returns a Scheme configured to handle 41 // the API object types that are used to configure API Priority and 42 // Fairness 43 func NewAPFScheme() *runtime.Scheme { 44 scheme := runtime.NewScheme() 45 install.Install(scheme) 46 return scheme 47 } 48 49 func internalizeFSes(exts []*flowcontrolv1.FlowSchema) map[string]*flowcontrol.FlowSchema { 50 ans := make(map[string]*flowcontrol.FlowSchema, len(exts)) 51 scheme := NewAPFScheme() 52 for _, ext := range exts { 53 var untyped flowcontrol.FlowSchema 54 if err := scheme.Convert(ext, &untyped, nil); err != nil { 55 panic(err) 56 } 57 ans[ext.Name] = &untyped 58 } 59 return ans 60 } 61 62 func internalizePLs(exts []*flowcontrolv1.PriorityLevelConfiguration) map[string]*flowcontrol.PriorityLevelConfiguration { 63 ans := make(map[string]*flowcontrol.PriorityLevelConfiguration, len(exts)) 64 scheme := NewAPFScheme() 65 for _, ext := range exts { 66 var untyped flowcontrol.PriorityLevelConfiguration 67 if err := scheme.Convert(ext, &untyped, nil); err != nil { 68 panic(err) 69 } 70 ans[ext.Name] = &untyped 71 } 72 return ans 73 }