...
1
16
17 package v1beta1
18
19 import (
20 appsv1beta1 "k8s.io/api/apps/v1beta1"
21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22 "k8s.io/apimachinery/pkg/runtime"
23 "k8s.io/apimachinery/pkg/util/intstr"
24 utilfeature "k8s.io/apiserver/pkg/util/feature"
25 "k8s.io/kubernetes/pkg/features"
26 "k8s.io/utils/ptr"
27 )
28
29 func addDefaultingFuncs(scheme *runtime.Scheme) error {
30 return RegisterDefaults(scheme)
31 }
32
33 func SetDefaults_StatefulSet(obj *appsv1beta1.StatefulSet) {
34 if len(obj.Spec.PodManagementPolicy) == 0 {
35 obj.Spec.PodManagementPolicy = appsv1beta1.OrderedReadyPodManagement
36 }
37
38 if obj.Spec.UpdateStrategy.Type == "" {
39 obj.Spec.UpdateStrategy.Type = appsv1beta1.OnDeleteStatefulSetStrategyType
40 }
41 labels := obj.Spec.Template.Labels
42 if labels != nil {
43 if obj.Spec.Selector == nil {
44 obj.Spec.Selector = &metav1.LabelSelector{
45 MatchLabels: labels,
46 }
47 }
48 if len(obj.Labels) == 0 {
49 obj.Labels = labels
50 }
51 }
52
53 if utilfeature.DefaultFeatureGate.Enabled(features.StatefulSetAutoDeletePVC) {
54 if obj.Spec.PersistentVolumeClaimRetentionPolicy == nil {
55 obj.Spec.PersistentVolumeClaimRetentionPolicy = &appsv1beta1.StatefulSetPersistentVolumeClaimRetentionPolicy{}
56 }
57 if len(obj.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted) == 0 {
58 obj.Spec.PersistentVolumeClaimRetentionPolicy.WhenDeleted = appsv1beta1.RetainPersistentVolumeClaimRetentionPolicyType
59 }
60 if len(obj.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled) == 0 {
61 obj.Spec.PersistentVolumeClaimRetentionPolicy.WhenScaled = appsv1beta1.RetainPersistentVolumeClaimRetentionPolicyType
62 }
63 }
64
65 if obj.Spec.Replicas == nil {
66 obj.Spec.Replicas = new(int32)
67 *obj.Spec.Replicas = 1
68 }
69 if obj.Spec.RevisionHistoryLimit == nil {
70 obj.Spec.RevisionHistoryLimit = new(int32)
71 *obj.Spec.RevisionHistoryLimit = 10
72 }
73 if obj.Spec.UpdateStrategy.Type == appsv1beta1.RollingUpdateStatefulSetStrategyType &&
74 obj.Spec.UpdateStrategy.RollingUpdate != nil {
75
76 if obj.Spec.UpdateStrategy.RollingUpdate.Partition == nil {
77 obj.Spec.UpdateStrategy.RollingUpdate.Partition = ptr.To[int32](0)
78 }
79 if utilfeature.DefaultFeatureGate.Enabled(features.MaxUnavailableStatefulSet) {
80 if obj.Spec.UpdateStrategy.RollingUpdate.MaxUnavailable == nil {
81 obj.Spec.UpdateStrategy.RollingUpdate.MaxUnavailable = ptr.To(intstr.FromInt32(1))
82 }
83 }
84 }
85 }
86
87
88
89
90
91
92
93 func SetDefaults_Deployment(obj *appsv1beta1.Deployment) {
94
95 labels := obj.Spec.Template.Labels
96
97 if labels != nil {
98 if obj.Spec.Selector == nil {
99 obj.Spec.Selector = &metav1.LabelSelector{MatchLabels: labels}
100 }
101 if len(obj.Labels) == 0 {
102 obj.Labels = labels
103 }
104 }
105
106 if obj.Spec.Replicas == nil {
107 obj.Spec.Replicas = new(int32)
108 *obj.Spec.Replicas = 1
109 }
110 strategy := &obj.Spec.Strategy
111
112 if strategy.Type == "" {
113 strategy.Type = appsv1beta1.RollingUpdateDeploymentStrategyType
114 }
115 if strategy.Type == appsv1beta1.RollingUpdateDeploymentStrategyType {
116 if strategy.RollingUpdate == nil {
117 rollingUpdate := appsv1beta1.RollingUpdateDeployment{}
118 strategy.RollingUpdate = &rollingUpdate
119 }
120 if strategy.RollingUpdate.MaxUnavailable == nil {
121
122 maxUnavailable := intstr.FromString("25%")
123 strategy.RollingUpdate.MaxUnavailable = &maxUnavailable
124 }
125 if strategy.RollingUpdate.MaxSurge == nil {
126
127 maxSurge := intstr.FromString("25%")
128 strategy.RollingUpdate.MaxSurge = &maxSurge
129 }
130 }
131 if obj.Spec.RevisionHistoryLimit == nil {
132 obj.Spec.RevisionHistoryLimit = new(int32)
133 *obj.Spec.RevisionHistoryLimit = 2
134 }
135 if obj.Spec.ProgressDeadlineSeconds == nil {
136 obj.Spec.ProgressDeadlineSeconds = new(int32)
137 *obj.Spec.ProgressDeadlineSeconds = 600
138 }
139 }
140
View as plain text