@@ -39,6 +39,17 @@ type VersionUpgrade struct {
39
39
40
40
const RecordBufferSize int = 100
41
41
42
+ func (u VersionUpgrade ) semVer () * semver.Version {
43
+ if len (u .Version .OpenTelemetryCollector ) == 0 {
44
+ return & Latest .Version
45
+ }
46
+ if v , err := semver .NewVersion (u .Version .OpenTelemetryCollector ); err != nil {
47
+ return & Latest .Version
48
+ } else {
49
+ return v
50
+ }
51
+ }
52
+
42
53
// ManagedInstances finds all the otelcol instances for the current operator and upgrades them, if necessary.
43
54
func (u VersionUpgrade ) ManagedInstances (ctx context.Context ) error {
44
55
u .Log .Info ("looking for managed instances to upgrade" )
@@ -107,9 +118,9 @@ func (u VersionUpgrade) ManagedInstance(_ context.Context, otelcol v1beta1.OpenT
107
118
}
108
119
109
120
updated := * (otelcol .DeepCopy ())
110
- if instanceV .GreaterThan (& Latest . Version ) {
121
+ if instanceV .GreaterThan (u . semVer () ) {
111
122
// Update with the latest known version, which is what we have from versions.txt
112
- 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 ())
123
+ 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 ())
113
124
114
125
otelColV , err := semver .NewVersion (u .Version .OpenTelemetryCollector )
115
126
if err != nil {
@@ -126,6 +137,11 @@ func (u VersionUpgrade) ManagedInstance(_ context.Context, otelcol v1beta1.OpenT
126
137
}
127
138
128
139
for _ , available := range versions {
140
+ // Don't run upgrades for versions after the webhook's set version.
141
+ // This is important only for testing.
142
+ if available .GreaterThan (u .semVer ()) {
143
+ continue
144
+ }
129
145
if available .GreaterThan (instanceV ) {
130
146
if available .upgrade != nil {
131
147
otelcolV1alpha1 := & v1alpha1.OpenTelemetryCollector {}
0 commit comments