Skip to content

Commit cf85180

Browse files
Merge pull request #1993 from gnufied/fix-panic-required-labels-csi-driver
OCPBUGS-60464: Fix panic in required labels handling
2 parents 378de07 + 5c7c63d commit cf85180

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

pkg/operator/resource/resourceapply/storage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ func ApplyCSIDriver(ctx context.Context, client storageclientv1.CSIDriversGetter
142142
if required.Annotations == nil {
143143
required.Annotations = map[string]string{}
144144
}
145+
if required.Labels == nil {
146+
required.Labels = map[string]string{}
147+
}
145148
if err := SetSpecHashAnnotation(&required.ObjectMeta, required.Spec); err != nil {
146149
return nil, false, err
147150
}

pkg/operator/resource/resourceapply/storage_test.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package resourceapply
33
import (
44
"context"
55
"fmt"
6-
clocktesting "k8s.io/utils/clock/testing"
76
"strings"
87
"testing"
98
"time"
109

10+
clocktesting "k8s.io/utils/clock/testing"
11+
1112
"github.com/davecgh/go-spew/spew"
1213
"github.com/openshift/library-go/pkg/operator/events"
1314
v1 "k8s.io/api/core/v1"
@@ -622,6 +623,45 @@ func TestApplyCSIDriver(t *testing.T) {
622623
}
623624
},
624625
},
626+
{
627+
name: "exempt label with missing labels on original object",
628+
existing: []*storagev1.CSIDriver{
629+
{
630+
ObjectMeta: metav1.ObjectMeta{
631+
Name: "foo",
632+
Annotations: map[string]string{"my.csi.driver/foo": "bar"},
633+
Labels: map[string]string{
634+
csiInlineVolProfileLabel: "restricted",
635+
},
636+
},
637+
Spec: storagev1.CSIDriverSpec{
638+
VolumeLifecycleModes: []storagev1.VolumeLifecycleMode{
639+
storagev1.VolumeLifecyclePersistent,
640+
},
641+
},
642+
},
643+
},
644+
input: &storagev1.CSIDriver{
645+
ObjectMeta: metav1.ObjectMeta{
646+
Name: "foo",
647+
Annotations: map[string]string{"my.csi.driver/foo": "bar"},
648+
},
649+
Spec: storagev1.CSIDriverSpec{
650+
VolumeLifecycleModes: []storagev1.VolumeLifecycleMode{
651+
storagev1.VolumeLifecyclePersistent,
652+
},
653+
},
654+
},
655+
expectedModified: false,
656+
verifyActions: func(actions []clienttesting.Action, t *testing.T) {
657+
if len(actions) != 1 {
658+
t.Fatal(spew.Sdump(actions))
659+
}
660+
if !actions[0].Matches("get", "csidrivers") || actions[0].(clienttesting.GetAction).GetName() != "foo" {
661+
t.Error(spew.Sdump(actions))
662+
}
663+
},
664+
},
625665
{
626666
name: "exempt label with differing value should not be overwritten during update",
627667
existing: []*storagev1.CSIDriver{

0 commit comments

Comments
 (0)