default-internal.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package internalbootstrap
  14. import (
  15. fcv1a1 "k8s.io/api/flowcontrol/v1alpha1"
  16. "k8s.io/apimachinery/pkg/conversion"
  17. "k8s.io/apimachinery/pkg/runtime"
  18. "k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
  19. "k8s.io/kubernetes/pkg/apis/flowcontrol"
  20. "k8s.io/kubernetes/pkg/apis/flowcontrol/install"
  21. )
  22. // MandatoryFlowSchemas holds the untyped renditions of the mandatory
  23. // flow schemas. In this map the key is the schema's name and the
  24. // value is the `*FlowSchema`. Nobody should mutate anything
  25. // reachable from this map.
  26. var MandatoryFlowSchemas = internalizeFSes(bootstrap.MandatoryFlowSchemas)
  27. // MandatoryPriorityLevelConfigurations holds the untyped renditions of the
  28. // mandatory priority level configuration objects. In this map the
  29. // key is the object's name and the value is the
  30. // `*PriorityLevelConfiguration`. Nobody should mutate anything
  31. // reachable from this map.
  32. var MandatoryPriorityLevelConfigurations = internalizePLs(bootstrap.MandatoryPriorityLevelConfigurations)
  33. // NewAPFScheme constructs and returns a Scheme configured to handle
  34. // the API object types that are used to configure API Priority and
  35. // Fairness
  36. func NewAPFScheme() *runtime.Scheme {
  37. scheme := runtime.NewScheme()
  38. install.Install(scheme)
  39. return scheme
  40. }
  41. func internalizeFSes(exts []*fcv1a1.FlowSchema) map[string]*flowcontrol.FlowSchema {
  42. ans := make(map[string]*flowcontrol.FlowSchema, len(exts))
  43. converter := NewAPFScheme().Converter()
  44. for _, ext := range exts {
  45. var untyped flowcontrol.FlowSchema
  46. err := converter.Convert(ext, &untyped, 0, &conversion.Meta{})
  47. if err != nil {
  48. panic(err)
  49. }
  50. ans[ext.Name] = &untyped
  51. }
  52. return ans
  53. }
  54. func internalizePLs(exts []*fcv1a1.PriorityLevelConfiguration) map[string]*flowcontrol.PriorityLevelConfiguration {
  55. ans := make(map[string]*flowcontrol.PriorityLevelConfiguration, len(exts))
  56. converter := NewAPFScheme().Converter()
  57. for _, ext := range exts {
  58. var untyped flowcontrol.PriorityLevelConfiguration
  59. err := converter.Convert(ext, &untyped, 0, &conversion.Meta{})
  60. if err != nil {
  61. panic(err)
  62. }
  63. ans[ext.Name] = &untyped
  64. }
  65. return ans
  66. }