@@ -23,6 +23,7 @@ import (
23
23
v1 "k8s.io/api/core/v1"
24
24
"k8s.io/apimachinery/pkg/api/resource"
25
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
+ "k8s.io/apimachinery/pkg/util/intstr"
26
27
)
27
28
28
29
func TestOTELColDefaultingWebhook (t * testing.T ) {
@@ -48,6 +49,12 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
48
49
Mode : ModeDeployment ,
49
50
Replicas : & one ,
50
51
UpgradeStrategy : UpgradeStrategyAutomatic ,
52
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
53
+ MaxUnavailable : & intstr.IntOrString {
54
+ Type : intstr .Int ,
55
+ IntVal : 1 ,
56
+ },
57
+ },
51
58
},
52
59
},
53
60
},
@@ -70,6 +77,12 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
70
77
Mode : ModeSidecar ,
71
78
Replicas : & five ,
72
79
UpgradeStrategy : "adhoc" ,
80
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
81
+ MaxUnavailable : & intstr.IntOrString {
82
+ Type : intstr .Int ,
83
+ IntVal : 1 ,
84
+ },
85
+ },
73
86
},
74
87
},
75
88
},
@@ -98,6 +111,12 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
98
111
MaxReplicas : & five ,
99
112
MinReplicas : & one ,
100
113
},
114
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
115
+ MaxUnavailable : & intstr.IntOrString {
116
+ Type : intstr .Int ,
117
+ IntVal : 1 ,
118
+ },
119
+ },
101
120
},
102
121
},
103
122
},
@@ -126,6 +145,12 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
126
145
MinReplicas : & one ,
127
146
},
128
147
MaxReplicas : & five ,
148
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
149
+ MaxUnavailable : & intstr.IntOrString {
150
+ Type : intstr .Int ,
151
+ IntVal : 1 ,
152
+ },
153
+ },
129
154
},
130
155
},
131
156
},
@@ -155,6 +180,44 @@ func TestOTELColDefaultingWebhook(t *testing.T) {
155
180
},
156
181
Replicas : & one ,
157
182
UpgradeStrategy : UpgradeStrategyAutomatic ,
183
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
184
+ MaxUnavailable : & intstr.IntOrString {
185
+ Type : intstr .Int ,
186
+ IntVal : 1 ,
187
+ },
188
+ },
189
+ },
190
+ },
191
+ },
192
+ {
193
+ name : "Defined PDB" ,
194
+ otelcol : OpenTelemetryCollector {
195
+ Spec : OpenTelemetryCollectorSpec {
196
+ Mode : ModeDeployment ,
197
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
198
+ MinAvailable : & intstr.IntOrString {
199
+ Type : intstr .String ,
200
+ StrVal : "10%" ,
201
+ },
202
+ },
203
+ },
204
+ },
205
+ expected : OpenTelemetryCollector {
206
+ ObjectMeta : metav1.ObjectMeta {
207
+ Labels : map [string ]string {
208
+ "app.kubernetes.io/managed-by" : "opentelemetry-operator" ,
209
+ },
210
+ },
211
+ Spec : OpenTelemetryCollectorSpec {
212
+ Mode : ModeDeployment ,
213
+ Replicas : & one ,
214
+ UpgradeStrategy : UpgradeStrategyAutomatic ,
215
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
216
+ MinAvailable : & intstr.IntOrString {
217
+ Type : intstr .String ,
218
+ StrVal : "10%" ,
219
+ },
220
+ },
158
221
},
159
222
},
160
223
},
@@ -237,6 +300,12 @@ func TestOTELColValidatingWebhook(t *testing.T) {
237
300
},
238
301
TargetCPUUtilization : & five ,
239
302
},
303
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
304
+ MinAvailable : & intstr.IntOrString {
305
+ Type : intstr .Int ,
306
+ IntVal : 1 ,
307
+ },
308
+ },
240
309
},
241
310
},
242
311
},
@@ -489,6 +558,25 @@ func TestOTELColValidatingWebhook(t *testing.T) {
489
558
},
490
559
expectedErr : "the OpenTelemetry Spec autoscale configuration is incorrect, invalid pods target type" ,
491
560
},
561
+ {
562
+ name : "pdb minAvailable and maxUnavailable have been set together" ,
563
+ otelcol : OpenTelemetryCollector {
564
+ Spec : OpenTelemetryCollectorSpec {
565
+ MaxReplicas : & three ,
566
+ PodDisruptionBudget : & PodDisruptionBudgetSpec {
567
+ MinAvailable : & intstr.IntOrString {
568
+ Type : intstr .Int ,
569
+ IntVal : 1 ,
570
+ },
571
+ MaxUnavailable : & intstr.IntOrString {
572
+ Type : intstr .Int ,
573
+ IntVal : 1 ,
574
+ },
575
+ },
576
+ },
577
+ },
578
+ expectedErr : "the OpenTelemetry Spec podDisruptionBudget configuration is incorrect, minAvailable and maxUnavailable are mutually exclusive" ,
579
+ },
492
580
{
493
581
name : "invalid deployment mode incompabible with ingress settings" ,
494
582
otelcol : OpenTelemetryCollector {
0 commit comments