Merge pull request #113584 from yangjunmyfm192085/volume-contextual-logging

volume: use contextual logging
This commit is contained in:
Kubernetes Prow Robot
2023-03-14 10:40:16 -07:00
committed by GitHub
61 changed files with 1326 additions and 1151 deletions

View File

@@ -31,6 +31,7 @@ import (
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
fakecloud "k8s.io/cloud-provider/fake"
"k8s.io/klog/v2/ktesting"
kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"
"k8s.io/kubernetes/pkg/controller/volume/attachdetach"
volumecache "k8s.io/kubernetes/pkg/controller/volume/attachdetach/cache"
@@ -161,7 +162,6 @@ func TestPodDeletionWithDswp(t *testing.T) {
defer framework.DeleteNamespaceOrDie(testClient, ns, t)
pod := fakePodWithVol(namespaceName)
podStopCh := make(chan struct{})
if _, err := testClient.CoreV1().Nodes().Create(context.TODO(), node, metav1.CreateOptions{}); err != nil {
t.Fatalf("Failed to created node : %v", err)
@@ -183,7 +183,7 @@ func TestPodDeletionWithDswp(t *testing.T) {
go informers.Core().V1().PersistentVolumes().Informer().Run(ctx.Done())
go informers.Storage().V1().VolumeAttachments().Informer().Run(ctx.Done())
initCSIObjects(ctx.Done(), informers)
go ctrl.Run(ctx.Done())
go ctrl.Run(ctx)
// Run pvCtrl to avoid leaking goroutines started during its creation.
go pvCtrl.Run(ctx)
@@ -201,7 +201,6 @@ func TestPodDeletionWithDswp(t *testing.T) {
waitForPodsInDSWP(t, ctrl.GetDesiredStateOfWorld())
// let's stop pod events from getting triggered
close(podStopCh)
err = podInformer.GetStore().Delete(podInformerObj)
if err != nil {
t.Fatalf("Error deleting pod : %v", err)
@@ -262,7 +261,7 @@ func TestPodUpdateWithWithADC(t *testing.T) {
go informers.Core().V1().PersistentVolumes().Informer().Run(ctx.Done())
go informers.Storage().V1().VolumeAttachments().Informer().Run(ctx.Done())
initCSIObjects(ctx.Done(), informers)
go ctrl.Run(ctx.Done())
go ctrl.Run(ctx)
// Run pvCtrl to avoid leaking goroutines started during its creation.
go pvCtrl.Run(ctx)
@@ -335,7 +334,7 @@ func TestPodUpdateWithKeepTerminatedPodVolumes(t *testing.T) {
go informers.Core().V1().PersistentVolumes().Informer().Run(ctx.Done())
go informers.Storage().V1().VolumeAttachments().Informer().Run(ctx.Done())
initCSIObjects(ctx.Done(), informers)
go ctrl.Run(ctx.Done())
go ctrl.Run(ctx)
// Run pvCtrl to avoid leaking goroutines started during its creation.
go pvCtrl.Run(ctx)
@@ -426,7 +425,9 @@ func createAdClients(t *testing.T, server *kubeapiservertesting.TestServer, sync
plugins := []volume.VolumePlugin{plugin}
cloud := &fakecloud.Cloud{}
informers := clientgoinformers.NewSharedInformerFactory(testClient, resyncPeriod)
logger, ctx := ktesting.NewTestContext(t)
ctrl, err := attachdetach.NewAttachDetachController(
logger,
testClient,
informers.Core().V1().Pods(),
informers.Core().V1().Nodes(),
@@ -463,7 +464,7 @@ func createAdClients(t *testing.T, server *kubeapiservertesting.TestServer, sync
NodeInformer: informers.Core().V1().Nodes(),
EnableDynamicProvisioning: false,
}
pvCtrl, err := persistentvolume.NewController(params)
pvCtrl, err := persistentvolume.NewController(ctx, params)
if err != nil {
t.Fatalf("Failed to create PV controller: %v", err)
}
@@ -509,14 +510,15 @@ func TestPodAddedByDswp(t *testing.T) {
go podInformer.Run(podStopCh)
// start controller loop
ctx, cancel := context.WithCancel(context.Background())
_, ctx := ktesting.NewTestContext(t)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
go informers.Core().V1().PersistentVolumeClaims().Informer().Run(ctx.Done())
go informers.Core().V1().PersistentVolumes().Informer().Run(ctx.Done())
go informers.Storage().V1().VolumeAttachments().Informer().Run(ctx.Done())
initCSIObjects(ctx.Done(), informers)
go ctrl.Run(ctx.Done())
go ctrl.Run(ctx)
// Run pvCtrl to avoid leaking goroutines started during its creation.
go pvCtrl.Run(ctx)
@@ -605,7 +607,7 @@ func TestPVCBoundWithADC(t *testing.T) {
informers.Start(ctx.Done())
informers.WaitForCacheSync(ctx.Done())
initCSIObjects(ctx.Done(), informers)
go ctrl.Run(ctx.Done())
go ctrl.Run(ctx)
go pvCtrl.Run(ctx)
waitToObservePods(t, informers.Core().V1().Pods().Informer(), 4)

View File

@@ -47,6 +47,7 @@ import (
"k8s.io/kubernetes/test/integration/framework"
"k8s.io/klog/v2"
"k8s.io/klog/v2/ktesting"
)
// Several tests in this file are configurable by environment variables:
@@ -1357,7 +1358,9 @@ func createClients(namespaceName string, t *testing.T, s *kubeapiservertesting.T
plugins := []volume.VolumePlugin{plugin}
cloud := &fakecloud.Cloud{}
informers := informers.NewSharedInformerFactory(testClient, getSyncPeriod(syncPeriod))
_, ctx := ktesting.NewTestContext(t)
ctrl, err := persistentvolumecontroller.NewController(
ctx,
persistentvolumecontroller.ControllerParameters{
KubeClient: binderClient,
SyncPeriod: getSyncPeriod(syncPeriod),

View File

@@ -28,6 +28,7 @@ import (
"time"
"k8s.io/klog/v2"
"k8s.io/klog/v2/ktesting"
v1 "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
@@ -1128,8 +1129,8 @@ func initPVController(t *testing.T, testCtx *testutil.TestContext, provisionDela
NodeInformer: informerFactory.Core().V1().Nodes(),
EnableDynamicProvisioning: true,
}
ctrl, err := persistentvolume.NewController(params)
_, ctx := ktesting.NewTestContext(t)
ctrl, err := persistentvolume.NewController(ctx, params)
if err != nil {
return nil, nil, err
}