defaults.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright 2018 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. auditregistrationv1alpha1 "k8s.io/api/auditregistration/v1alpha1"
  16. "k8s.io/apimachinery/pkg/runtime"
  17. utilpointer "k8s.io/utils/pointer"
  18. )
  19. const (
  20. // DefaultQPS is the default QPS value
  21. DefaultQPS = int64(10)
  22. // DefaultBurst is the default burst value
  23. DefaultBurst = int64(15)
  24. )
  25. // DefaultThrottle is a default throttle config
  26. func DefaultThrottle() *auditregistrationv1alpha1.WebhookThrottleConfig {
  27. return &auditregistrationv1alpha1.WebhookThrottleConfig{
  28. QPS: utilpointer.Int64Ptr(DefaultQPS),
  29. Burst: utilpointer.Int64Ptr(DefaultBurst),
  30. }
  31. }
  32. func addDefaultingFuncs(scheme *runtime.Scheme) error {
  33. return RegisterDefaults(scheme)
  34. }
  35. // SetDefaults_AuditSink sets defaults if the audit sink isn't present
  36. func SetDefaults_AuditSink(obj *auditregistrationv1alpha1.AuditSink) {
  37. if obj.Spec.Webhook.Throttle != nil {
  38. if obj.Spec.Webhook.Throttle.QPS == nil {
  39. obj.Spec.Webhook.Throttle.QPS = utilpointer.Int64Ptr(DefaultQPS)
  40. }
  41. if obj.Spec.Webhook.Throttle.Burst == nil {
  42. obj.Spec.Webhook.Throttle.Burst = utilpointer.Int64Ptr(DefaultBurst)
  43. }
  44. } else {
  45. obj.Spec.Webhook.Throttle = DefaultThrottle()
  46. }
  47. }
  48. // SetDefaults_ServiceReference sets defaults for AuditSync Webhook's ServiceReference
  49. func SetDefaults_ServiceReference(obj *auditregistrationv1alpha1.ServiceReference) {
  50. if obj.Port == nil {
  51. obj.Port = utilpointer.Int32Ptr(443)
  52. }
  53. }