From 4abed7c687b2bc4d62984de9305ebf0892093734 Mon Sep 17 00:00:00 2001 From: Benedikt Bongartz Date: Mon, 7 Oct 2024 23:07:42 +0200 Subject: [PATCH] apis/v1beta1: remove ComponentUseLocalHostAsDefaultHost feature gate Signed-off-by: Benedikt Bongartz --- apis/v1beta1/collector_webhook.go | 22 ---------------------- apis/v1beta1/collector_webhook_test.go | 12 ------------ pkg/collector/upgrade/v0_104_0.go | 22 +++++++++++++++++++++- pkg/collector/upgrade/v0_110_0.go | 25 +++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 35 deletions(-) create mode 100644 pkg/collector/upgrade/v0_110_0.go diff --git a/apis/v1beta1/collector_webhook.go b/apis/v1beta1/collector_webhook.go index 45744ef3a5..e1a53a543d 100644 --- a/apis/v1beta1/collector_webhook.go +++ b/apis/v1beta1/collector_webhook.go @@ -78,8 +78,6 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error { otelcol.Spec.TargetAllocator.Replicas = &one } - ComponentUseLocalHostAsDefaultHost(otelcol) - if otelcol.Spec.Autoscaler != nil && otelcol.Spec.Autoscaler.MaxReplicas != nil { if otelcol.Spec.Autoscaler.MinReplicas == nil { otelcol.Spec.Autoscaler.MinReplicas = otelcol.Spec.Replicas @@ -453,23 +451,3 @@ func SetupCollectorWebhook(mgr ctrl.Manager, cfg config.Config, reviewer *rbac.R WithDefaulter(cvw). Complete() } - -// ComponentUseLocalHostAsDefaultHost enables component.UseLocalHostAsDefaultHost -// featuregate on the given collector instance. -// NOTE: For more details, visit: -// https://github.com/open-telemetry/opentelemetry-collector/issues/8510 -func ComponentUseLocalHostAsDefaultHost(otelcol *OpenTelemetryCollector) { - const ( - baseFlag = "feature-gates" - fgFlag = "component.UseLocalHostAsDefaultHost" - ) - if otelcol.Spec.Args == nil { - otelcol.Spec.Args = make(map[string]string) - } - args, ok := otelcol.Spec.Args[baseFlag] - if !ok || len(args) == 0 { - otelcol.Spec.Args[baseFlag] = "-" + fgFlag - } else if !strings.Contains(otelcol.Spec.Args[baseFlag], fgFlag) { - otelcol.Spec.Args[baseFlag] += ",-" + fgFlag - } -} diff --git a/apis/v1beta1/collector_webhook_test.go b/apis/v1beta1/collector_webhook_test.go index 9407c0f112..0b6b915486 100644 --- a/apis/v1beta1/collector_webhook_test.go +++ b/apis/v1beta1/collector_webhook_test.go @@ -162,7 +162,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, Spec: v1beta1.OpenTelemetryCollectorSpec{ OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, ManagementState: v1beta1.ManagementStateManaged, Replicas: &one, }, @@ -195,7 +194,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, Spec: v1beta1.OpenTelemetryCollectorSpec{ OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, ManagementState: v1beta1.ManagementStateManaged, Replicas: &one, }, @@ -219,7 +217,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, Spec: v1beta1.OpenTelemetryCollectorSpec{ OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, ManagementState: v1beta1.ManagementStateManaged, Replicas: &one, }, @@ -247,7 +244,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Mode: v1beta1.ModeSidecar, UpgradeStrategy: "adhoc", OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, Replicas: &five, ManagementState: v1beta1.ManagementStateManaged, }, @@ -274,7 +270,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Mode: v1beta1.ModeSidecar, UpgradeStrategy: "adhoc", OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, Replicas: &five, ManagementState: v1beta1.ManagementStateUnmanaged, }, @@ -299,7 +294,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Mode: v1beta1.ModeDeployment, UpgradeStrategy: v1beta1.UpgradeStrategyAutomatic, OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, Replicas: &one, ManagementState: v1beta1.ManagementStateManaged, }, @@ -328,7 +322,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: v1beta1.ModeDeployment, OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, ManagementState: v1beta1.ManagementStateManaged, Replicas: &one, }, @@ -364,7 +357,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: v1beta1.ModeDeployment, OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, Replicas: &one, ManagementState: v1beta1.ManagementStateManaged, PodDisruptionBudget: &v1beta1.PodDisruptionBudgetSpec{ @@ -402,7 +394,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: v1beta1.ModeDeployment, OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, Replicas: &one, ManagementState: v1beta1.ManagementStateManaged, }, @@ -445,7 +436,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: v1beta1.ModeDeployment, OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, Replicas: &one, ManagementState: v1beta1.ManagementStateManaged, }, @@ -483,7 +473,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: v1beta1.ModeDeployment, OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, Replicas: &one, ManagementState: v1beta1.ManagementStateManaged, }, @@ -514,7 +503,6 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: v1beta1.ModeDeployment, OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Args: map[string]string{"feature-gates": "-component.UseLocalHostAsDefaultHost"}, Replicas: &one, ManagementState: v1beta1.ManagementStateManaged, }, diff --git a/pkg/collector/upgrade/v0_104_0.go b/pkg/collector/upgrade/v0_104_0.go index 45fe8a7461..50a74cc08b 100644 --- a/pkg/collector/upgrade/v0_104_0.go +++ b/pkg/collector/upgrade/v0_104_0.go @@ -27,7 +27,7 @@ func upgrade0_104_0_TA(_ VersionUpgrade, otelcol *v1beta1.OpenTelemetryCollector } func upgrade0_104_0(u VersionUpgrade, otelcol *v1beta1.OpenTelemetryCollector) (*v1beta1.OpenTelemetryCollector, error) { - v1beta1.ComponentUseLocalHostAsDefaultHost(otelcol) + ComponentUseLocalHostAsDefaultHost(otelcol) const issueID = "https://github.com/open-telemetry/opentelemetry-collector/issues/8510" warnStr := fmt.Sprintf( @@ -69,3 +69,23 @@ func TAUnifyEnvVarExpansion(otelcol *v1beta1.OpenTelemetryCollector) { otelcol.Spec.Args[baseFlag] += ",-" + fgFlag } } + +// ComponentUseLocalHostAsDefaultHost enables component.UseLocalHostAsDefaultHost +// featuregate on the given collector instance. +// NOTE: For more details, visit: +// https://github.com/open-telemetry/opentelemetry-collector/issues/8510 +func ComponentUseLocalHostAsDefaultHost(otelcol *v1beta1.OpenTelemetryCollector) { + const ( + baseFlag = "feature-gates" + fgFlag = "component.UseLocalHostAsDefaultHost" + ) + if otelcol.Spec.Args == nil { + otelcol.Spec.Args = make(map[string]string) + } + args, ok := otelcol.Spec.Args[baseFlag] + if !ok || len(args) == 0 { + otelcol.Spec.Args[baseFlag] = "-" + fgFlag + } else if !strings.Contains(otelcol.Spec.Args[baseFlag], fgFlag) { + otelcol.Spec.Args[baseFlag] += ",-" + fgFlag + } +} diff --git a/pkg/collector/upgrade/v0_110_0.go b/pkg/collector/upgrade/v0_110_0.go new file mode 100644 index 0000000000..043d7bbd9f --- /dev/null +++ b/pkg/collector/upgrade/v0_110_0.go @@ -0,0 +1,25 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package upgrade + +import ( + "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" +) + +func upgrade0_110_0(_ VersionUpgrade, otelcol *v1beta1.OpenTelemetryCollector) (*v1beta1.OpenTelemetryCollector, error) { + envVarExpansionFeatureFlag := "-component.UseLocalHostAsDefaultHost" + otelcol.Spec.OpenTelemetryCommonFields.Args = RemoveFeatureGate(otelcol.Spec.OpenTelemetryCommonFields.Args, envVarExpansionFeatureFlag) + return otelcol, nil +}