forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
defaults.go
81 lines (73 loc) · 2.18 KB
/
defaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package v1beta3
import (
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/intstr"
deployapi "github.com/openshift/origin/pkg/deploy/api"
)
func addDefaultingFuncs(scheme *runtime.Scheme) {
mkintp := func(i int64) *int64 {
return &i
}
err := scheme.AddDefaultingFuncs(
func(obj *DeploymentConfigSpec) {
if obj.Triggers == nil {
obj.Triggers = []DeploymentTriggerPolicy{
{Type: DeploymentTriggerOnConfigChange},
}
}
if len(obj.Selector) == 0 && obj.Template != nil {
obj.Selector = obj.Template.Labels
}
},
func(obj *DeploymentStrategy) {
if len(obj.Type) == 0 {
obj.Type = DeploymentStrategyTypeRolling
}
if obj.Type == DeploymentStrategyTypeRolling && obj.RollingParams == nil {
obj.RollingParams = &RollingDeploymentStrategyParams{
IntervalSeconds: mkintp(deployapi.DefaultRollingIntervalSeconds),
UpdatePeriodSeconds: mkintp(deployapi.DefaultRollingUpdatePeriodSeconds),
TimeoutSeconds: mkintp(deployapi.DefaultRollingTimeoutSeconds),
}
}
if obj.Type == DeploymentStrategyTypeRecreate && obj.RecreateParams == nil {
obj.RecreateParams = &RecreateDeploymentStrategyParams{}
}
},
func(obj *RecreateDeploymentStrategyParams) {
if obj.TimeoutSeconds == nil {
obj.TimeoutSeconds = mkintp(deployapi.DefaultRollingTimeoutSeconds)
}
},
func(obj *RollingDeploymentStrategyParams) {
if obj.IntervalSeconds == nil {
obj.IntervalSeconds = mkintp(deployapi.DefaultRollingIntervalSeconds)
}
if obj.UpdatePeriodSeconds == nil {
obj.UpdatePeriodSeconds = mkintp(deployapi.DefaultRollingUpdatePeriodSeconds)
}
if obj.TimeoutSeconds == nil {
obj.TimeoutSeconds = mkintp(deployapi.DefaultRollingTimeoutSeconds)
}
if obj.UpdatePercent == nil {
// Apply defaults.
if obj.MaxUnavailable == nil {
maxUnavailable := intstr.FromString("25%")
obj.MaxUnavailable = &maxUnavailable
}
if obj.MaxSurge == nil {
maxSurge := intstr.FromString("25%")
obj.MaxSurge = &maxSurge
}
}
},
func(obj *DeploymentTriggerImageChangeParams) {
if len(obj.From.Kind) == 0 {
obj.From.Kind = "ImageStreamTag"
}
},
)
if err != nil {
panic(err)
}
}