Skip to content

Commit 80e81e4

Browse files
committed
Fix panic due to empty version in the ClusterOperator controller.
If the ClusterVersion singleton "version" has an empty string for the value of its field .Status.Desired.Version, then the ClusterOperator controller would panic. Signed-off-by: Ben Luddy <[email protected]>
1 parent b044fdc commit 80e81e4

File tree

2 files changed

+75
-4
lines changed

2 files changed

+75
-4
lines changed

pkg/controller/operators/openshift/helpers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ func incompatibleOperators(ctx context.Context, cli client.Client) (skews, error
104104
if err != nil {
105105
return nil, err
106106
}
107+
108+
if next == nil {
109+
return nil, nil
110+
}
107111
next.Minor++
108112

109113
csvList := &operatorsv1alpha1.ClusterServiceVersionList{}

pkg/controller/operators/openshift/helpers_test.go

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,22 @@ func TestIncompatibleOperators(t *testing.T) {
219219
}
220220
for _, tt := range []struct {
221221
description string
222+
cv configv1.ClusterVersion
222223
in skews
223224
expect expect
224225
}{
225226
{
226227
description: "Compatible",
228+
cv: configv1.ClusterVersion{
229+
ObjectMeta: metav1.ObjectMeta{
230+
Name: "version",
231+
},
232+
Status: configv1.ClusterVersionStatus{
233+
Desired: configv1.Update{
234+
Version: "1.0.0",
235+
},
236+
},
237+
},
227238
in: skews{
228239
{
229240
name: "almond",
@@ -248,6 +259,16 @@ func TestIncompatibleOperators(t *testing.T) {
248259
},
249260
{
250261
description: "Incompatible",
262+
cv: configv1.ClusterVersion{
263+
ObjectMeta: metav1.ObjectMeta{
264+
Name: "version",
265+
},
266+
Status: configv1.ClusterVersionStatus{
267+
Desired: configv1.Update{
268+
Version: "1.0.0",
269+
},
270+
},
271+
},
251272
in: skews{
252273
{
253274
name: "almond",
@@ -298,6 +319,16 @@ func TestIncompatibleOperators(t *testing.T) {
298319
},
299320
{
300321
description: "Mixed",
322+
cv: configv1.ClusterVersion{
323+
ObjectMeta: metav1.ObjectMeta{
324+
Name: "version",
325+
},
326+
Status: configv1.ClusterVersionStatus{
327+
Desired: configv1.Update{
328+
Version: "1.0.0",
329+
},
330+
},
331+
},
301332
in: skews{
302333
{
303334
name: "almond",
@@ -323,6 +354,16 @@ func TestIncompatibleOperators(t *testing.T) {
323354
},
324355
{
325356
description: "Mixed/BadVersion",
357+
cv: configv1.ClusterVersion{
358+
ObjectMeta: metav1.ObjectMeta{
359+
Name: "version",
360+
},
361+
Status: configv1.ClusterVersionStatus{
362+
Desired: configv1.Update{
363+
Version: "1.0.0",
364+
},
365+
},
366+
},
326367
in: skews{
327368
{
328369
name: "almond",
@@ -351,12 +392,38 @@ func TestIncompatibleOperators(t *testing.T) {
351392
},
352393
},
353394
},
395+
{
396+
description: "Compatible/EmptyVersion",
397+
cv: configv1.ClusterVersion{
398+
ObjectMeta: metav1.ObjectMeta{
399+
Name: "version",
400+
},
401+
Status: configv1.ClusterVersionStatus{
402+
Desired: configv1.Update{
403+
Version: "",
404+
},
405+
},
406+
},
407+
in: skews{
408+
{
409+
name: "almond",
410+
namespace: "default",
411+
maxOpenShiftVersion: "1.1.0",
412+
},
413+
{
414+
name: "beech",
415+
namespace: "default",
416+
maxOpenShiftVersion: "1.0.0",
417+
},
418+
},
419+
expect: expect{
420+
err: false,
421+
incompatible: nil,
422+
},
423+
},
354424
} {
355425
t.Run(tt.description, func(t *testing.T) {
356-
cv := &configv1.ClusterVersion{}
357-
cv.SetName("version")
358-
cv.Status.Desired.Version = "1.0.0"
359-
objs := []client.Object{cv}
426+
objs := []client.Object{tt.cv.DeepCopy()}
360427

361428
for _, s := range tt.in {
362429
csv := &operatorsv1alpha1.ClusterServiceVersion{}

0 commit comments

Comments
 (0)