Skip to content

Commit

Permalink
Fix pdb defaulting logic (#3200)
Browse files Browse the repository at this point in the history
* Fix PDB defaulting logic

* oop

* chlog

* fix unit

* fix tests

* Update docs
  • Loading branch information
jaronoff97 authored Aug 7, 2024
1 parent 92652a5 commit 0551975
Show file tree
Hide file tree
Showing 17 changed files with 489 additions and 175 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix-pdb-defaulting-logic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixes a bug where the operator would default the PDB in the wrong place.

# One or more tracking issues related to the change
issues: [3198]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
30 changes: 0 additions & 30 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/go-logr/logr"
autoscalingv2 "k8s.io/api/autoscaling/v2"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
Expand Down Expand Up @@ -92,35 +91,6 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error {
}
}

// if pdb isn't provided, we set MaxUnavailable 1,
// which will work even if there is just one replica,
// not blocking node drains but preventing out-of-the-box
// from disruption generated by them with replicas > 1
if otelcol.Spec.PodDisruptionBudget == nil {
otelcol.Spec.PodDisruptionBudget = &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
}
}

// if pdb isn't provided for target allocator and it's enabled
// using a valid strategy (consistent-hashing, per-node),
// we set MaxUnavailable 1, which will work even if there is
// just one replica, not blocking node drains but preventing
// out-of-the-box from disruption generated by them with replicas > 1
if otelcol.Spec.TargetAllocator.Enabled &&
otelcol.Spec.TargetAllocator.AllocationStrategy != TargetAllocatorAllocationStrategyLeastWeighted &&
otelcol.Spec.TargetAllocator.PodDisruptionBudget == nil {
otelcol.Spec.TargetAllocator.PodDisruptionBudget = &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
}
}

if otelcol.Spec.Ingress.Type == IngressTypeRoute && otelcol.Spec.Ingress.Route.Termination == "" {
otelcol.Spec.Ingress.Route.Termination = TLSRouteTerminationTypeEdge
}
Expand Down
60 changes: 0 additions & 60 deletions apis/v1beta1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
ManagementState: ManagementStateManaged,
Replicas: &one,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
Mode: ModeDeployment,
UpgradeStrategy: UpgradeStrategyAutomatic,
Expand Down Expand Up @@ -156,12 +150,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
Replicas: &five,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
},
},
Expand Down Expand Up @@ -191,12 +179,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
Replicas: &five,
ManagementState: ManagementStateUnmanaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
},
},
Expand Down Expand Up @@ -224,12 +206,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
Autoscaler: &AutoscalerSpec{
TargetCPUUtilization: &defaultCPUTarget,
Expand Down Expand Up @@ -261,12 +237,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
ManagementState: ManagementStateManaged,
Replicas: &one,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
Ingress: Ingress{
Type: IngressTypeRoute,
Expand Down Expand Up @@ -345,12 +315,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
UpgradeStrategy: UpgradeStrategyAutomatic,
TargetAllocator: TargetAllocatorEmbedded{
Expand Down Expand Up @@ -396,12 +360,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
UpgradeStrategy: UpgradeStrategyAutomatic,
TargetAllocator: TargetAllocatorEmbedded{
Expand Down Expand Up @@ -442,24 +400,12 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
UpgradeStrategy: UpgradeStrategyAutomatic,
TargetAllocator: TargetAllocatorEmbedded{
Enabled: true,
Replicas: &one,
AllocationStrategy: TargetAllocatorAllocationStrategyConsistentHashing,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
},
},
Expand Down Expand Up @@ -487,12 +433,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
},
UpgradeStrategy: UpgradeStrategyAutomatic,
TargetAllocator: TargetAllocatorEmbedded{
Expand Down
3 changes: 2 additions & 1 deletion apis/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ type OpenTelemetryCommonFields struct {
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// PodDisruptionBudget specifies the pod disruption budget configuration to use
// for the generated workload.
// for the generated workload. By default, a PDB with a MaxUnavailable of one is set.
//
// +optional
PodDisruptionBudget *PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`
// SecurityContext configures the container security context for
Expand Down
3 changes: 2 additions & 1 deletion apis/v1beta1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ type TargetAllocatorEmbedded struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Observability"
Observability ObservabilitySpec `json:"observability,omitempty"`
// PodDisruptionBudget specifies the pod disruption budget configuration to use
// for the target allocator workload.
// for the target allocator workload. By default, a PDB with a MaxUnavailable of one is set for a valid
// allocation strategy.
//
// +optional
PodDisruptionBudget *PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`
Expand Down
Loading

0 comments on commit 0551975

Please sign in to comment.