Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ func TestController(t *testing.T) {
stopCh := make(chan struct{})
informerFactory.Start(stopCh)

ctx := context.TODO()
defer ctx.Done()
go controller.Run(1, ctx)
go controller.Run(1, t.Context())

for _, obj := range initialObjects {
switch obj.(type) {
Expand Down
36 changes: 14 additions & 22 deletions pkg/modifycontroller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,22 @@ import (
"context"
"errors"
"fmt"
"github.com/kubernetes-csi/external-resizer/pkg/util"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
"testing"
"time"

"github.com/kubernetes-csi/external-resizer/pkg/features"

"k8s.io/client-go/util/workqueue"

"github.com/kubernetes-csi/external-resizer/pkg/csi"
"github.com/kubernetes-csi/external-resizer/pkg/features"
"github.com/kubernetes-csi/external-resizer/pkg/modifier"

"github.com/kubernetes-csi/external-resizer/pkg/util"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
v1 "k8s.io/api/core/v1"
storagev1beta1 "k8s.io/api/storage/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
featuregatetesting "k8s.io/component-base/featuregate/testing"
)

Expand Down Expand Up @@ -71,8 +68,7 @@ func TestController(t *testing.T) {
client := csi.NewMockClient(testDriverName, true, true, true, true, true, false)

initialObjects := []runtime.Object{test.pvc, test.pv, testVacObject, targetVacObject}
ctrlInstance, ctx := setupFakeK8sEnvironment(t, client, initialObjects)
defer ctx.Done()
ctrlInstance := setupFakeK8sEnvironment(t, client, initialObjects)

_, _, err, _ := ctrlInstance.modify(test.pvc, test.pv)
if err != nil {
Expand Down Expand Up @@ -126,8 +122,7 @@ func TestModifyPVC(t *testing.T) {
}

initialObjects := []runtime.Object{test.pvc, test.pv, testVacObject, targetVacObject}
ctrlInstance, ctx := setupFakeK8sEnvironment(t, client, initialObjects)
defer ctx.Done()
ctrlInstance := setupFakeK8sEnvironment(t, client, initialObjects)

_, _, err, _ := ctrlInstance.modify(test.pvc, test.pv)

Expand Down Expand Up @@ -225,8 +220,7 @@ func TestSyncPVC(t *testing.T) {
client := csi.NewMockClient(testDriverName, true, true, true, true, true, false)

initialObjects := []runtime.Object{test.pvc, test.pv, testVacObject, targetVacObject}
ctrlInstance, ctx := setupFakeK8sEnvironment(t, client, initialObjects)
defer ctx.Done()
ctrlInstance := setupFakeK8sEnvironment(t, client, initialObjects)

err := ctrlInstance.syncPVC(pvcNamespace + "/" + pvcName)
if err != nil {
Expand Down Expand Up @@ -289,8 +283,7 @@ func TestInfeasibleRetry(t *testing.T) {
}

initialObjects := []runtime.Object{test.pvc, basePV, testVacObject, targetVacObject}
ctrlInstance, ctx := setupFakeK8sEnvironment(t, client, initialObjects)
defer ctx.Done()
ctrlInstance := setupFakeK8sEnvironment(t, client, initialObjects)

// Attempt modification first time
err := ctrlInstance.syncPVC(pvcNamespace + "/" + pvcName)
Expand Down Expand Up @@ -329,7 +322,7 @@ func TestInfeasibleRetry(t *testing.T) {
}

// setupFakeK8sEnvironment creates fake K8s environment and starts Informers and ModifyController
func setupFakeK8sEnvironment(t *testing.T, client *csi.MockClient, initialObjects []runtime.Object) (*modifyController, context.Context) {
func setupFakeK8sEnvironment(t *testing.T, client *csi.MockClient, initialObjects []runtime.Object) *modifyController {
t.Helper()

featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.VolumeAttributesClass, true)
Expand All @@ -356,8 +349,7 @@ func setupFakeK8sEnvironment(t *testing.T, client *csi.MockClient, initialObject
stopCh := make(chan struct{})
informerFactory.Start(stopCh)

ctx := context.TODO()
go controller.Run(1, ctx)
go controller.Run(1, t.Context())

/* Add initial objects to informer caches */
for _, obj := range initialObjects {
Expand All @@ -375,5 +367,5 @@ func setupFakeK8sEnvironment(t *testing.T, client *csi.MockClient, initialObject

ctrlInstance, _ := controller.(*modifyController)

return ctrlInstance, ctx
return ctrlInstance
}
4 changes: 1 addition & 3 deletions pkg/modifycontroller/modify_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@ func TestRemovePVCFromModifyVolumeUncertainCache(t *testing.T) {
stopCh := make(chan struct{})
informerFactory.Start(stopCh)

ctx := context.TODO()
defer ctx.Done()
success := ctrlInstance.init(ctx)
success := ctrlInstance.init(t.Context())
if !success {
t.Fatal("failed to init controller")
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/modifycontroller/modify_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ func TestModify(t *testing.T) {
if test.vacExists {
initialObjects = append(initialObjects, targetVacObject)
}
ctrlInstance, ctx := setupFakeK8sEnvironment(t, client, initialObjects)
defer ctx.Done()
ctrlInstance := setupFakeK8sEnvironment(t, client, initialObjects)

// Action
pvc, pv, err, modifyCalled := ctrlInstance.modify(test.pvc, test.pv)
Expand Down