-
Notifications
You must be signed in to change notification settings - Fork 402
/
v0_41_0.go
61 lines (52 loc) · 2.22 KB
/
v0_41_0.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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 (
"fmt"
"strings"
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
"github.com/open-telemetry/opentelemetry-operator/pkg/collector/adapters"
corev1 "k8s.io/api/core/v1"
)
func upgrade0_41_0(u VersionUpgrade, otelcol *v1alpha1.OpenTelemetryCollector) (*v1alpha1.OpenTelemetryCollector, error) {
cfg, err := adapters.ConfigFromString(otelcol.Spec.Config)
if err != nil {
return otelcol, fmt.Errorf("couldn't upgrade to v0.41.0, failed to parse configuration: %w", err)
}
// Re-structure the cors section in otlp receiver
// in reference to https://github.com/open-telemetry/opentelemetry-collector/pull/4492
receivers, _ := cfg["receivers"].(map[interface{}]interface{})
for k1, v1 := range receivers {
if strings.HasPrefix(k1.(string), "otlp") {
otlpReceiver, _ := v1.(map[interface{}]interface{})
var createdCors bool
for k2, v2 := range otlpReceiver {
if k2.(string) == "cors_allowed_origins" || k2.(string) == "cors_allowed_headers" {
if !createdCors {
otlpReceiver["cors"] = make(map[interface{}]interface{})
createdCors = true
}
newsCorsKey := strings.Replace(k2.(string), "cors_", "", 1)
otlpCors, _ := otlpReceiver["cors"].(map[interface{}]interface{})
otlpCors[newsCorsKey] = v2
delete(otlpReceiver, k2)
existing := &corev1.ConfigMap{}
updated := existing.DeepCopy()
u.Recorder.Event(updated, "Normal", "Upgrade", fmt.Sprintf("upgrade to v0.41.0 has re-structured the %s inside otlp "+"receiver config according to the upstream otlp receiver changes in 0.41.0 release.", k2))
}
}
}
}
return updateConfig(otelcol, cfg)
}