| 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 v1 |
| 18 |
|
| 19 |
import ( |
| 20 |
"time" |
| 21 |
|
| 22 |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 23 |
"k8s.io/apimachinery/pkg/runtime" |
| 24 |
) |
| 25 |
|
| 26 |
var ( |
| 27 |
defaultTimeout = &metav1.Duration{Duration: 3 * time.Second} |
| 28 |
defaultCacheSize int32 = 1000 |
| 29 |
defaultAPIVersion = "v1" |
| 30 |
) |
| 31 |
|
| 32 |
func addDefaultingFuncs(scheme *runtime.Scheme) error { |
| 33 |
return RegisterDefaults(scheme) |
| 34 |
} |
| 35 |
|
| 36 |
// SetDefaults_KMSConfiguration applies defaults to KMSConfiguration. |
| 37 |
func SetDefaults_KMSConfiguration(obj *KMSConfiguration) { |
| 38 |
if obj.Timeout == nil { |
| 39 |
obj.Timeout = defaultTimeout |
| 40 |
} |
| 41 |
|
| 42 |
if obj.APIVersion == "" { |
| 43 |
obj.APIVersion = defaultAPIVersion |
| 44 |
} |
| 45 |
|
| 46 |
// cacheSize is relevant only for kms v1 |
| 47 |
if obj.CacheSize == nil && obj.APIVersion == "v1" { |
| 48 |
obj.CacheSize = &defaultCacheSize |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
func SetDefaults_WebhookConfiguration(obj *WebhookConfiguration) { |
| 53 |
if obj.AuthorizedTTL.Duration == 0 { |
| 54 |
obj.AuthorizedTTL.Duration = 5 * time.Minute |
| 55 |
} |
| 56 |
if obj.UnauthorizedTTL.Duration == 0 { |
| 57 |
obj.UnauthorizedTTL.Duration = 30 * time.Second |
| 58 |
} |
| 59 |
} |