mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Add CSINodes to AttachDetachControllerRecovery test
This commit is contained in:
parent
86f20db7d0
commit
6e716af89e
@ -154,6 +154,7 @@ func attachDetachRecoveryTestCase(t *testing.T, extraPods1 []*v1.Pod, extraPods2
|
||||
plugins := controllervolumetesting.CreateTestPlugin()
|
||||
var prober volume.DynamicPluginProber = nil // TODO (#51147) inject mock
|
||||
nodeInformer := informerFactory.Core().V1().Nodes().Informer()
|
||||
csiNodeInformer := informerFactory.Storage().V1().CSINodes().Informer()
|
||||
podInformer := informerFactory.Core().V1().Pods().Informer()
|
||||
var podsNum, extraPodsNum, nodesNum, i int
|
||||
|
||||
@ -179,11 +180,21 @@ func attachDetachRecoveryTestCase(t *testing.T, extraPods1 []*v1.Pod, extraPods2
|
||||
nodesNum++
|
||||
}
|
||||
|
||||
csiNodes, err := fakeKubeClient.StorageV1().CSINodes().List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Run failed with error. Expected: <no error> Actual: %v", err)
|
||||
}
|
||||
for _, csiNode := range csiNodes.Items {
|
||||
csiNodeToAdd := csiNode
|
||||
csiNodeInformer.GetIndexer().Add(&csiNodeToAdd)
|
||||
}
|
||||
|
||||
informerFactory.Start(stopCh)
|
||||
|
||||
if !kcache.WaitForNamedCacheSync("attach detach", stopCh,
|
||||
informerFactory.Core().V1().Pods().Informer().HasSynced,
|
||||
informerFactory.Core().V1().Nodes().Informer().HasSynced) {
|
||||
informerFactory.Core().V1().Nodes().Informer().HasSynced,
|
||||
informerFactory.Storage().V1().CSINodes().Informer().HasSynced) {
|
||||
t.Fatalf("Error waiting for the informer caches to sync")
|
||||
}
|
||||
|
||||
@ -214,6 +225,19 @@ func attachDetachRecoveryTestCase(t *testing.T, extraPods1 []*v1.Pod, extraPods2
|
||||
podList, err = informerFactory.Core().V1().Pods().Lister().List(labels.Everything())
|
||||
i++
|
||||
}
|
||||
i = 0
|
||||
csiNodesList, err := informerFactory.Storage().V1().CSINodes().Lister().List(labels.Everything())
|
||||
for len(csiNodesList) < nodesNum {
|
||||
if err != nil {
|
||||
t.Fatalf("Error getting list of csi nodes %v", err)
|
||||
}
|
||||
if i > 100 {
|
||||
t.Fatalf("Time out while waiting for the csinodes informer sync: found %d csinodes, expected %d csinodes", len(csiNodesList), nodesNum)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
csiNodesList, err = informerFactory.Storage().V1().CSINodes().Lister().List(labels.Everything())
|
||||
i++
|
||||
}
|
||||
|
||||
// Create the controller
|
||||
adcObj, err := NewAttachDetachController(
|
||||
|
@ -13,6 +13,7 @@ go_library(
|
||||
"//pkg/volume:go_default_library",
|
||||
"//pkg/volume/util:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/api/storage/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
@ -122,6 +123,26 @@ func CreateTestClient() *fake.Clientset {
|
||||
extraPods.Items = append(extraPods.Items, *pod)
|
||||
return true, createAction.GetObject(), nil
|
||||
})
|
||||
fakeClient.AddReactor("list", "csinodes", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
||||
obj := &storagev1.CSINodeList{}
|
||||
nodeNamePrefix := "mynode"
|
||||
for i := 0; i < 5; i++ {
|
||||
var nodeName string
|
||||
if i != 0 {
|
||||
nodeName = fmt.Sprintf("%s-%d", nodeNamePrefix, i)
|
||||
} else {
|
||||
// We want also the "mynode" node since all the testing pods live there
|
||||
nodeName = nodeNamePrefix
|
||||
}
|
||||
csiNode := storagev1.CSINode{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: nodeName,
|
||||
},
|
||||
}
|
||||
obj.Items = append(obj.Items, csiNode)
|
||||
}
|
||||
return true, obj, nil
|
||||
})
|
||||
fakeClient.AddReactor("list", "nodes", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
||||
obj := &v1.NodeList{}
|
||||
nodeNamePrefix := "mynode"
|
||||
|
Loading…
Reference in New Issue
Block a user