diff --git a/pkg/collector/upgrade/suite_test.go b/pkg/collector/upgrade/suite_test.go index c5e5cdbd23..7a571bc481 100644 --- a/pkg/collector/upgrade/suite_test.go +++ b/pkg/collector/upgrade/suite_test.go @@ -42,6 +42,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/rbac" + "github.com/open-telemetry/opentelemetry-operator/internal/version" ) var ( @@ -160,3 +161,9 @@ func TestMain(m *testing.M) { os.Exit(code) } + +func makeVersion(v string) version.Version { + return version.Version{ + OpenTelemetryCollector: v, + } +} diff --git a/pkg/collector/upgrade/upgrade.go b/pkg/collector/upgrade/upgrade.go index 9a1f426747..610fca140f 100644 --- a/pkg/collector/upgrade/upgrade.go +++ b/pkg/collector/upgrade/upgrade.go @@ -39,6 +39,17 @@ type VersionUpgrade struct { const RecordBufferSize int = 100 +func (u VersionUpgrade) semVer() *semver.Version { + if len(u.Version.OpenTelemetryCollector) == 0 { + return &Latest.Version + } + if v, err := semver.NewVersion(u.Version.OpenTelemetryCollector); err != nil { + return &Latest.Version + } else { + return v + } +} + // ManagedInstances finds all the otelcol instances for the current operator and upgrades them, if necessary. func (u VersionUpgrade) ManagedInstances(ctx context.Context) error { u.Log.Info("looking for managed instances to upgrade") @@ -107,9 +118,9 @@ func (u VersionUpgrade) ManagedInstance(_ context.Context, otelcol v1beta1.OpenT } updated := *(otelcol.DeepCopy()) - if instanceV.GreaterThan(&Latest.Version) { + if instanceV.GreaterThan(u.semVer()) { // Update with the latest known version, which is what we have from versions.txt - u.Log.V(4).Info("no upgrade routines are needed for the OpenTelemetry instance", "name", updated.Name, "namespace", updated.Namespace, "version", updated.Status.Version, "latest", Latest.Version.String()) + u.Log.V(4).Info("no upgrade routines are needed for the OpenTelemetry instance", "name", updated.Name, "namespace", updated.Namespace, "version", updated.Status.Version, "latest", u.semVer().String()) otelColV, err := semver.NewVersion(u.Version.OpenTelemetryCollector) if err != nil { @@ -126,6 +137,11 @@ func (u VersionUpgrade) ManagedInstance(_ context.Context, otelcol v1beta1.OpenT } for _, available := range versions { + // Don't run upgrades for versions after the webhook's set version. + // This is important only for testing. + if available.GreaterThan(u.semVer()) { + continue + } if available.GreaterThan(instanceV) { if available.upgrade != nil { otelcolV1alpha1 := &v1alpha1.OpenTelemetryCollector{} diff --git a/pkg/collector/upgrade/v0_104_0_test.go b/pkg/collector/upgrade/v0_104_0_test.go index bdf88e7c8e..0c5b939479 100644 --- a/pkg/collector/upgrade/v0_104_0_test.go +++ b/pkg/collector/upgrade/v0_104_0_test.go @@ -24,7 +24,6 @@ import ( "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" ) @@ -46,7 +45,7 @@ func Test0_104_0Upgrade(t *testing.T) { versionUpgrade := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.104.0"), Client: k8sClient, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } @@ -56,7 +55,9 @@ func Test0_104_0Upgrade(t *testing.T) { t.Errorf("expect err: nil but got: %v", err) } assert.EqualValues(t, - map[string]string{}, + map[string]string{ + "feature-gates": "-component.UseLocalHostAsDefaultHost", + }, col.Spec.Args, "missing featuregate") } diff --git a/pkg/collector/upgrade/v0_105_0_test.go b/pkg/collector/upgrade/v0_105_0_test.go index c92880790d..b0af1cd8ea 100644 --- a/pkg/collector/upgrade/v0_105_0_test.go +++ b/pkg/collector/upgrade/v0_105_0_test.go @@ -23,7 +23,6 @@ import ( "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" ) @@ -59,7 +58,7 @@ func Test0_105_0Upgrade(t *testing.T) { versionUpgrade := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.105.0"), Client: k8sClient, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_15_0_test.go b/pkg/collector/upgrade/v0_15_0_test.go index 0a01a3e847..4063f85829 100644 --- a/pkg/collector/upgrade/v0_15_0_test.go +++ b/pkg/collector/upgrade/v0_15_0_test.go @@ -25,7 +25,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -57,7 +56,7 @@ func TestRemoveMetricsTypeFlags(t *testing.T) { // test up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.15.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_19_0_test.go b/pkg/collector/upgrade/v0_19_0_test.go index 63162e5dce..3c3a5e66d0 100644 --- a/pkg/collector/upgrade/v0_19_0_test.go +++ b/pkg/collector/upgrade/v0_19_0_test.go @@ -26,7 +26,6 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -74,7 +73,7 @@ service: // test up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.19.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } @@ -124,7 +123,7 @@ service: // test up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.19.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } @@ -191,7 +190,7 @@ service: // test up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.19.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_24_0_test.go b/pkg/collector/upgrade/v0_24_0_test.go index caf53bdfd2..52669150ff 100644 --- a/pkg/collector/upgrade/v0_24_0_test.go +++ b/pkg/collector/upgrade/v0_24_0_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -64,7 +63,7 @@ service: // test up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.24.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_31_0_test.go b/pkg/collector/upgrade/v0_31_0_test.go index 861cdb492d..dd340ed655 100644 --- a/pkg/collector/upgrade/v0_31_0_test.go +++ b/pkg/collector/upgrade/v0_31_0_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -63,7 +62,7 @@ service: // test up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.31.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_36_0_test.go b/pkg/collector/upgrade/v0_36_0_test.go index 7695d39c00..346adb424c 100644 --- a/pkg/collector/upgrade/v0_36_0_test.go +++ b/pkg/collector/upgrade/v0_36_0_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -79,7 +78,7 @@ service: up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.36.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_38_0_test.go b/pkg/collector/upgrade/v0_38_0_test.go index 26e3d69bbb..efa74d9c6a 100644 --- a/pkg/collector/upgrade/v0_38_0_test.go +++ b/pkg/collector/upgrade/v0_38_0_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -72,7 +71,7 @@ service: // EXPECTED: drop logging args and configure logging parameters into config from args up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.38.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_39_0_test.go b/pkg/collector/upgrade/v0_39_0_test.go index 204c576c8a..39ffa04436 100644 --- a/pkg/collector/upgrade/v0_39_0_test.go +++ b/pkg/collector/upgrade/v0_39_0_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -74,7 +73,7 @@ service: // drop processors.memory_limiter field 'ballast_size_mib' up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.39.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_41_0_test.go b/pkg/collector/upgrade/v0_41_0_test.go index 01903044a5..f13047eefa 100644 --- a/pkg/collector/upgrade/v0_41_0_test.go +++ b/pkg/collector/upgrade/v0_41_0_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -64,7 +63,7 @@ service: // TESTCASE 1: restructure cors for both allowed_origin & allowed_headers up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.41.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_43_0_test.go b/pkg/collector/upgrade/v0_43_0_test.go index 348b1d0b96..957849f941 100644 --- a/pkg/collector/upgrade/v0_43_0_test.go +++ b/pkg/collector/upgrade/v0_43_0_test.go @@ -24,7 +24,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -70,7 +69,7 @@ service: // test up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.43.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_56_0_test.go b/pkg/collector/upgrade/v0_56_0_test.go index 57ced4b07a..fd29c55aed 100644 --- a/pkg/collector/upgrade/v0_56_0_test.go +++ b/pkg/collector/upgrade/v0_56_0_test.go @@ -23,7 +23,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -50,7 +49,7 @@ func Test0_56_0Upgrade(t *testing.T) { collectorInstance.Status.Version = "0.55.0" versionUpgrade := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.56.0"), Client: k8sClient, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_57_2_test.go b/pkg/collector/upgrade/v0_57_2_test.go index a3ca59919c..c43b869591 100644 --- a/pkg/collector/upgrade/v0_57_2_test.go +++ b/pkg/collector/upgrade/v0_57_2_test.go @@ -23,7 +23,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -67,7 +66,7 @@ service: //Test to remove port and change endpoint value. versionUpgrade := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.57.2"), Client: k8sClient, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_61_0_test.go b/pkg/collector/upgrade/v0_61_0_test.go index f702695672..91bfdc447f 100644 --- a/pkg/collector/upgrade/v0_61_0_test.go +++ b/pkg/collector/upgrade/v0_61_0_test.go @@ -23,7 +23,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -72,7 +71,7 @@ func Test0_61_0Upgrade(t *testing.T) { versionUpgrade := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.61.0"), Client: k8sClient, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), } diff --git a/pkg/collector/upgrade/v0_9_0_test.go b/pkg/collector/upgrade/v0_9_0_test.go index c428034000..06c5c8cf7f 100644 --- a/pkg/collector/upgrade/v0_9_0_test.go +++ b/pkg/collector/upgrade/v0_9_0_test.go @@ -25,7 +25,6 @@ import ( "k8s.io/client-go/tools/record" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/internal/version" "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" ) @@ -56,7 +55,7 @@ func TestRemoveConnectionDelay(t *testing.T) { // test up := &upgrade.VersionUpgrade{ Log: logger, - Version: version.Get(), + Version: makeVersion("0.9.0"), Client: nil, Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), }