defaults.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 v1alpha1
  14. import (
  15. "k8s.io/api/flowcontrol/v1alpha1"
  16. )
  17. // Default settings for flow-schema
  18. const (
  19. FlowSchemaDefaultMatchingPrecedence int32 = 1000
  20. )
  21. // Default settings for priority-level-configuration
  22. const (
  23. PriorityLevelConfigurationDefaultHandSize int32 = 8
  24. PriorityLevelConfigurationDefaultQueues int32 = 64
  25. PriorityLevelConfigurationDefaultQueueLengthLimit int32 = 50
  26. PriorityLevelConfigurationDefaultAssuredConcurrencyShares int32 = 30
  27. )
  28. // SetDefaults_FlowSchema sets default values for flow schema
  29. func SetDefaults_FlowSchemaSpec(spec *v1alpha1.FlowSchemaSpec) {
  30. if spec.MatchingPrecedence == 0 {
  31. spec.MatchingPrecedence = FlowSchemaDefaultMatchingPrecedence
  32. }
  33. }
  34. func SetDefaults_LimitedPriorityLevelConfiguration(lplc *v1alpha1.LimitedPriorityLevelConfiguration) {
  35. if lplc.AssuredConcurrencyShares == 0 {
  36. lplc.AssuredConcurrencyShares = PriorityLevelConfigurationDefaultAssuredConcurrencyShares
  37. }
  38. }
  39. // SetDefaults_FlowSchema sets default values for flow schema
  40. func SetDefaults_QueuingConfiguration(cfg *v1alpha1.QueuingConfiguration) {
  41. if cfg.HandSize == 0 {
  42. cfg.HandSize = PriorityLevelConfigurationDefaultHandSize
  43. }
  44. if cfg.Queues == 0 {
  45. cfg.Queues = PriorityLevelConfigurationDefaultQueues
  46. }
  47. if cfg.QueueLengthLimit == 0 {
  48. cfg.QueueLengthLimit = PriorityLevelConfigurationDefaultQueueLengthLimit
  49. }
  50. }