Skip to content

Commit

Permalink
apis/v1beta1: remove ComponentUseLocalHostAsDefaultHost feature gate
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
  • Loading branch information
frzifus committed Oct 7, 2024
1 parent 8eb13f1 commit 4abed7c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 35 deletions.
22 changes: 0 additions & 22 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
12 changes: 0 additions & 12 deletions apis/v1beta1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down
22 changes: 21 additions & 1 deletion pkg/collector/upgrade/v0_104_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
}
}
25 changes: 25 additions & 0 deletions pkg/collector/upgrade/v0_110_0.go
Original file line number Diff line number Diff line change
@@ -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) {

Check failure on line 21 in pkg/collector/upgrade/v0_110_0.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

upgrade0_110_0 - result 1 (error) is always nil (unparam)
envVarExpansionFeatureFlag := "-component.UseLocalHostAsDefaultHost"
otelcol.Spec.OpenTelemetryCommonFields.Args = RemoveFeatureGate(otelcol.Spec.OpenTelemetryCommonFields.Args, envVarExpansionFeatureFlag)
return otelcol, nil
}

0 comments on commit 4abed7c

Please sign in to comment.