Skip to content

Commit

Permalink
adapt to breaking changes
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
  • Loading branch information
frzifus committed Jul 13, 2024
1 parent a4b6da4 commit 01f97ef
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
27 changes: 27 additions & 0 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error {
otelcol.Spec.TargetAllocator.Replicas = &one
}

if otelcol.Spec.TargetAllocator.Enabled {
TAUnifiyEnvVarExpansion(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 @@ -449,3 +453,26 @@ func SetupCollectorWebhook(mgr ctrl.Manager, cfg config.Config, reviewer *rbac.R
WithDefaulter(cvw).
Complete()
}

// TAUnifiyEnvVarExpansion enables confmap.unifyEnvVarExpansion featuregate on collector instances associated to TA..
// NOTE: We need this for now until 0.105.0 is out with this fix:
// https://github.com/open-telemetry/opentelemetry-collector/commit/637b1f42fcb7cbb7ef8a50dcf41d0a089623a8b7
func TAUnifiyEnvVarExpansion(otelcol *OpenTelemetryCollector) {
if !otelcol.Spec.TargetAllocator.Enabled {
return
}
const (
baseFlag = "feature-gates"
fgFlag = "-confmap.unifyEnvVarExpansion"
)
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
}

}
47 changes: 47 additions & 0 deletions apis/v1beta1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
OpenTelemetryCommonFields: OpenTelemetryCommonFields{
Args: map[string]string{
"feature-gates": "-confmap.unifyEnvVarExpansion",
},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
Expand Down Expand Up @@ -386,6 +389,9 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
OpenTelemetryCommonFields: OpenTelemetryCommonFields{
Args: map[string]string{
"feature-gates": "-confmap.unifyEnvVarExpansion",
},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
Expand Down Expand Up @@ -431,6 +437,9 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
OpenTelemetryCommonFields: OpenTelemetryCommonFields{
Args: map[string]string{
"feature-gates": "-confmap.unifyEnvVarExpansion",
},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
Expand Down Expand Up @@ -475,6 +484,9 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
OpenTelemetryCommonFields: OpenTelemetryCommonFields{
Args: map[string]string{
"feature-gates": "-confmap.unifyEnvVarExpansion",
},
Replicas: &one,
ManagementState: ManagementStateManaged,
PodDisruptionBudget: &PodDisruptionBudgetSpec{
Expand Down Expand Up @@ -1325,3 +1337,38 @@ func getReviewer(shouldFailSAR bool) *rbac.Reviewer {
})
return rbac.NewReviewer(c)
}

func TestTAUnifiyEnvVarExpansion(t *testing.T) {
otelcol := &OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
OpenTelemetryCommonFields: OpenTelemetryCommonFields{
Args: nil,
},
},
}
TAUnifiyEnvVarExpansion(otelcol)
assert.Nil(t, otelcol.Spec.OpenTelemetryCommonFields.Args, "expect nil")
otelcol.Spec.TargetAllocator.Enabled = true
TAUnifiyEnvVarExpansion(otelcol)
assert.NotNil(t, otelcol.Spec.OpenTelemetryCommonFields.Args, "expect not nil")
expect := map[string]string{
"feature-gates": "-confmap.unifyEnvVarExpansion",
}
assert.EqualValues(t, otelcol.Spec.OpenTelemetryCommonFields.Args, expect)
TAUnifiyEnvVarExpansion(otelcol)
assert.EqualValues(t, otelcol.Spec.OpenTelemetryCommonFields.Args, expect)
expect = map[string]string{
"feature-gates": "-confmap.unifyEnvVarExpansion,+abc",
}
otelcol.Spec.OpenTelemetryCommonFields.Args = expect
TAUnifiyEnvVarExpansion(otelcol)
assert.EqualValues(t, otelcol.Spec.OpenTelemetryCommonFields.Args, expect)
otelcol.Spec.OpenTelemetryCommonFields.Args = map[string]string{
"feature-gates": "+abc",
}
TAUnifiyEnvVarExpansion(otelcol)
expect = map[string]string{
"feature-gates": "+abc,-confmap.unifyEnvVarExpansion",
}
assert.EqualValues(t, otelcol.Spec.OpenTelemetryCommonFields.Args, expect)
}
9 changes: 9 additions & 0 deletions pkg/collector/upgrade/v0_104_0.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ import (
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
)

func upgrade0_104_0_TA(_ VersionUpgrade, otelcol *v1beta1.OpenTelemetryCollector) (*v1beta1.OpenTelemetryCollector, error) {
if !otelcol.Spec.TargetAllocator.Enabled {
return otelcol, nil
}

v1beta1.TAUnifiyEnvVarExpansion(otelcol)
return otelcol, nil
}

func upgrade0_104_0(u VersionUpgrade, otelcol *v1beta1.OpenTelemetryCollector) (*v1beta1.OpenTelemetryCollector, error) {
for key, rc := range otelcol.Spec.Config.Receivers.Object {
// check if otel is configured
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/upgrade/v0_104_0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import (
_ "embed"
"testing"

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/record"

"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"github.com/open-telemetry/opentelemetry-operator/internal/version"
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade"
"github.com/stretchr/testify/assert"
)

func Test0_104_0Upgrade(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/collector/upgrade/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ var (
Version: *semver.MustParse("0.104.0"),
upgradeV1beta1: upgrade0_104_0,
},
{
Version: *semver.MustParse("0.104.0"),
upgradeV1beta1: upgrade0_104_0_TA,
},
}

// Latest represents the latest version that we need to upgrade. This is not necessarily the latest known version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spec:
containers:
- args:
- --config=/conf/collector.yaml
- --feature-gates=-confmap.unifyEnvVarExpansion
name: otc-container
volumeMounts:
- mountPath: /conf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ spec:
debug:
extensions:
health_check:
endpoint: "0.0.0.0:13133"
service:
telemetry:
metrics:
Expand Down

0 comments on commit 01f97ef

Please sign in to comment.