Skip to content

Commit 0551975

Browse files
authored
Fix pdb defaulting logic (#3200)
* Fix PDB defaulting logic * oop * chlog * fix unit * fix tests * Update docs
1 parent 92652a5 commit 0551975

17 files changed

+489
-175
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Fixes a bug where the operator would default the PDB in the wrong place.
9+
10+
# One or more tracking issues related to the change
11+
issues: [3198]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

apis/v1beta1/collector_webhook.go

-30
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/go-logr/logr"
2323
autoscalingv2 "k8s.io/api/autoscaling/v2"
2424
"k8s.io/apimachinery/pkg/runtime"
25-
"k8s.io/apimachinery/pkg/util/intstr"
2625
"k8s.io/apimachinery/pkg/util/validation"
2726
ctrl "sigs.k8s.io/controller-runtime"
2827
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -92,35 +91,6 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error {
9291
}
9392
}
9493

95-
// if pdb isn't provided, we set MaxUnavailable 1,
96-
// which will work even if there is just one replica,
97-
// not blocking node drains but preventing out-of-the-box
98-
// from disruption generated by them with replicas > 1
99-
if otelcol.Spec.PodDisruptionBudget == nil {
100-
otelcol.Spec.PodDisruptionBudget = &PodDisruptionBudgetSpec{
101-
MaxUnavailable: &intstr.IntOrString{
102-
Type: intstr.Int,
103-
IntVal: 1,
104-
},
105-
}
106-
}
107-
108-
// if pdb isn't provided for target allocator and it's enabled
109-
// using a valid strategy (consistent-hashing, per-node),
110-
// we set MaxUnavailable 1, which will work even if there is
111-
// just one replica, not blocking node drains but preventing
112-
// out-of-the-box from disruption generated by them with replicas > 1
113-
if otelcol.Spec.TargetAllocator.Enabled &&
114-
otelcol.Spec.TargetAllocator.AllocationStrategy != TargetAllocatorAllocationStrategyLeastWeighted &&
115-
otelcol.Spec.TargetAllocator.PodDisruptionBudget == nil {
116-
otelcol.Spec.TargetAllocator.PodDisruptionBudget = &PodDisruptionBudgetSpec{
117-
MaxUnavailable: &intstr.IntOrString{
118-
Type: intstr.Int,
119-
IntVal: 1,
120-
},
121-
}
122-
}
123-
12494
if otelcol.Spec.Ingress.Type == IngressTypeRoute && otelcol.Spec.Ingress.Route.Termination == "" {
12595
otelcol.Spec.Ingress.Route.Termination = TLSRouteTerminationTypeEdge
12696
}

apis/v1beta1/collector_webhook_test.go

-60
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
120120
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
121121
ManagementState: ManagementStateManaged,
122122
Replicas: &one,
123-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
124-
MaxUnavailable: &intstr.IntOrString{
125-
Type: intstr.Int,
126-
IntVal: 1,
127-
},
128-
},
129123
},
130124
Mode: ModeDeployment,
131125
UpgradeStrategy: UpgradeStrategyAutomatic,
@@ -156,12 +150,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
156150
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
157151
Replicas: &five,
158152
ManagementState: ManagementStateManaged,
159-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
160-
MaxUnavailable: &intstr.IntOrString{
161-
Type: intstr.Int,
162-
IntVal: 1,
163-
},
164-
},
165153
},
166154
},
167155
},
@@ -191,12 +179,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
191179
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
192180
Replicas: &five,
193181
ManagementState: ManagementStateUnmanaged,
194-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
195-
MaxUnavailable: &intstr.IntOrString{
196-
Type: intstr.Int,
197-
IntVal: 1,
198-
},
199-
},
200182
},
201183
},
202184
},
@@ -224,12 +206,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
224206
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
225207
Replicas: &one,
226208
ManagementState: ManagementStateManaged,
227-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
228-
MaxUnavailable: &intstr.IntOrString{
229-
Type: intstr.Int,
230-
IntVal: 1,
231-
},
232-
},
233209
},
234210
Autoscaler: &AutoscalerSpec{
235211
TargetCPUUtilization: &defaultCPUTarget,
@@ -261,12 +237,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
261237
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
262238
ManagementState: ManagementStateManaged,
263239
Replicas: &one,
264-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
265-
MaxUnavailable: &intstr.IntOrString{
266-
Type: intstr.Int,
267-
IntVal: 1,
268-
},
269-
},
270240
},
271241
Ingress: Ingress{
272242
Type: IngressTypeRoute,
@@ -345,12 +315,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
345315
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
346316
Replicas: &one,
347317
ManagementState: ManagementStateManaged,
348-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
349-
MaxUnavailable: &intstr.IntOrString{
350-
Type: intstr.Int,
351-
IntVal: 1,
352-
},
353-
},
354318
},
355319
UpgradeStrategy: UpgradeStrategyAutomatic,
356320
TargetAllocator: TargetAllocatorEmbedded{
@@ -396,12 +360,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
396360
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
397361
Replicas: &one,
398362
ManagementState: ManagementStateManaged,
399-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
400-
MaxUnavailable: &intstr.IntOrString{
401-
Type: intstr.Int,
402-
IntVal: 1,
403-
},
404-
},
405363
},
406364
UpgradeStrategy: UpgradeStrategyAutomatic,
407365
TargetAllocator: TargetAllocatorEmbedded{
@@ -442,24 +400,12 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
442400
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
443401
Replicas: &one,
444402
ManagementState: ManagementStateManaged,
445-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
446-
MaxUnavailable: &intstr.IntOrString{
447-
Type: intstr.Int,
448-
IntVal: 1,
449-
},
450-
},
451403
},
452404
UpgradeStrategy: UpgradeStrategyAutomatic,
453405
TargetAllocator: TargetAllocatorEmbedded{
454406
Enabled: true,
455407
Replicas: &one,
456408
AllocationStrategy: TargetAllocatorAllocationStrategyConsistentHashing,
457-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
458-
MaxUnavailable: &intstr.IntOrString{
459-
Type: intstr.Int,
460-
IntVal: 1,
461-
},
462-
},
463409
},
464410
},
465411
},
@@ -487,12 +433,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
487433
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
488434
Replicas: &one,
489435
ManagementState: ManagementStateManaged,
490-
PodDisruptionBudget: &PodDisruptionBudgetSpec{
491-
MaxUnavailable: &intstr.IntOrString{
492-
Type: intstr.Int,
493-
IntVal: 1,
494-
},
495-
},
496436
},
497437
UpgradeStrategy: UpgradeStrategyAutomatic,
498438
TargetAllocator: TargetAllocatorEmbedded{

apis/v1beta1/common.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ type OpenTelemetryCommonFields struct {
116116
// +optional
117117
Replicas *int32 `json:"replicas,omitempty"`
118118
// PodDisruptionBudget specifies the pod disruption budget configuration to use
119-
// for the generated workload.
119+
// for the generated workload. By default, a PDB with a MaxUnavailable of one is set.
120+
//
120121
// +optional
121122
PodDisruptionBudget *PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`
122123
// SecurityContext configures the container security context for

apis/v1beta1/opentelemetrycollector_types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ type TargetAllocatorEmbedded struct {
216216
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Observability"
217217
Observability ObservabilitySpec `json:"observability,omitempty"`
218218
// PodDisruptionBudget specifies the pod disruption budget configuration to use
219-
// for the target allocator workload.
219+
// for the target allocator workload. By default, a PDB with a MaxUnavailable of one is set for a valid
220+
// allocation strategy.
220221
//
221222
// +optional
222223
PodDisruptionBudget *PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`

0 commit comments

Comments
 (0)