|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package upgrade_test |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/stretchr/testify/assert" |
| 22 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 23 | + "k8s.io/client-go/tools/record" |
| 24 | + |
| 25 | + "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" |
| 26 | + "github.com/open-telemetry/opentelemetry-operator/pkg/collector/upgrade" |
| 27 | +) |
| 28 | + |
| 29 | +func Test0_111_0Upgrade(t *testing.T) { |
| 30 | + |
| 31 | + defaultCollector := v1beta1.OpenTelemetryCollector{ |
| 32 | + ObjectMeta: metav1.ObjectMeta{ |
| 33 | + Name: "otel-my-instance", |
| 34 | + Namespace: "somewhere", |
| 35 | + }, |
| 36 | + Status: v1beta1.OpenTelemetryCollectorStatus{ |
| 37 | + Version: "0.110.0", |
| 38 | + }, |
| 39 | + Spec: v1beta1.OpenTelemetryCollectorSpec{ |
| 40 | + OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{}, |
| 41 | + Config: v1beta1.Config{}, |
| 42 | + }, |
| 43 | + } |
| 44 | + |
| 45 | + defaultCollectorWithConfig := defaultCollector.DeepCopy() |
| 46 | + |
| 47 | + defaultCollectorWithConfig.Spec.Config.Service.Telemetry = &v1beta1.AnyConfig{ |
| 48 | + Object: map[string]interface{}{ |
| 49 | + "metrics": map[string]interface{}{ |
| 50 | + "address": "1.2.3.4:8888", |
| 51 | + }, |
| 52 | + }, |
| 53 | + } |
| 54 | + |
| 55 | + tt := []struct { |
| 56 | + name string |
| 57 | + input v1beta1.OpenTelemetryCollector |
| 58 | + expected v1beta1.OpenTelemetryCollector |
| 59 | + }{ |
| 60 | + { |
| 61 | + name: "telemetry settings exist", |
| 62 | + input: *defaultCollectorWithConfig, |
| 63 | + expected: *defaultCollectorWithConfig, |
| 64 | + }, |
| 65 | + { |
| 66 | + name: "telemetry settings do not exist", |
| 67 | + input: *defaultCollector.DeepCopy(), |
| 68 | + expected: func() v1beta1.OpenTelemetryCollector { |
| 69 | + col := defaultCollector.DeepCopy() |
| 70 | + col.Spec.Config.Service.Telemetry = &v1beta1.AnyConfig{ |
| 71 | + Object: map[string]interface{}{ |
| 72 | + "metrics": map[string]interface{}{ |
| 73 | + "address": "0.0.0.0:8888", |
| 74 | + }, |
| 75 | + }, |
| 76 | + } |
| 77 | + return *col |
| 78 | + }(), |
| 79 | + }, |
| 80 | + } |
| 81 | + |
| 82 | + versionUpgrade := &upgrade.VersionUpgrade{ |
| 83 | + Log: logger, |
| 84 | + Version: makeVersion("0.111.0"), |
| 85 | + Client: k8sClient, |
| 86 | + Recorder: record.NewFakeRecorder(upgrade.RecordBufferSize), |
| 87 | + } |
| 88 | + |
| 89 | + for _, tc := range tt { |
| 90 | + t.Run(tc.name, func(t *testing.T) { |
| 91 | + col, err := versionUpgrade.ManagedInstance(context.Background(), tc.input) |
| 92 | + if err != nil { |
| 93 | + t.Errorf("expect err: nil but got: %v", err) |
| 94 | + } |
| 95 | + assert.Equal(t, tc.expected.Spec.Config.Service.Telemetry, col.Spec.Config.Service.Telemetry) |
| 96 | + }) |
| 97 | + } |
| 98 | +} |
0 commit comments