Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Bongartz <[email protected]>
  • Loading branch information
frzifus committed Jul 12, 2024
1 parent a4b6da4 commit fdf0f4c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
24 changes: 24 additions & 0 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/go-logr/logr"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-metadata-filters)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-instrumentation)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-automatic-rbac)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-opampbridge)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-pdb)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-targetallocator)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-prometheuscr)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-automatic-rbac)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-upgrade)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

"k8s.io/api/core/v1" imported as corev1 and not used) (typecheck)

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

"k8s.io/api/core/v1" imported as corev1 and not used) (typecheck)

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

"k8s.io/api/core/v1" imported as corev1 and not used) (typecheck)

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-autoscale)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / Unit tests

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-multi-instrumentation)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-instrumentation)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-metadata-filters)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-multi-instrumentation)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-pdb)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-targetallocator)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-opampbridge)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-prometheuscr)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-upgrade)

"k8s.io/api/core/v1" imported as corev1 and not used

Check failure on line 24 in apis/v1beta1/collector_webhook.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.30, e2e-autoscale)

"k8s.io/api/core/v1" imported as corev1 and not used
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation"
Expand Down Expand Up @@ -79,6 +80,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 +454,22 @@ 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) {
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 {
otelcol.Spec.Args[baseFlag] += "," + fgFlag
}
}
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

0 comments on commit fdf0f4c

Please sign in to comment.