Skip to content

Commit c4fd4d7

Browse files
authored
Merge pull request #73 from kubernetes-csi/revert-72-pvclister
Revert "add pvcLister to snapshot controller"
2 parents a40dc65 + 96b6f49 commit c4fd4d7

File tree

5 files changed

+4
-25
lines changed

5 files changed

+4
-25
lines changed

cmd/csi-snapshotter/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/scheme"
3838
informers "github.com/kubernetes-csi/external-snapshotter/pkg/client/informers/externalversions"
3939
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
40-
coreinformers "k8s.io/client-go/informers"
4140
)
4241

4342
const (
@@ -96,7 +95,6 @@ func main() {
9695
}
9796

9897
factory := informers.NewSharedInformerFactory(snapClient, *resyncPeriod)
99-
coreFactory := coreinformers.NewSharedInformerFactory(kubeClient, *resyncPeriod)
10098

10199
// Create CRD resource
102100
aeclientset, err := apiextensionsclient.NewForConfig(config)
@@ -167,7 +165,6 @@ func main() {
167165
factory.Volumesnapshot().V1alpha1().VolumeSnapshots(),
168166
factory.Volumesnapshot().V1alpha1().VolumeSnapshotContents(),
169167
factory.Volumesnapshot().V1alpha1().VolumeSnapshotClasses(),
170-
coreFactory.Core().V1().PersistentVolumeClaims(),
171168
*createSnapshotContentRetryCount,
172169
*createSnapshotContentInterval,
173170
csiConn,

pkg/controller/framework_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ import (
4646
"k8s.io/apimachinery/pkg/util/diff"
4747
"k8s.io/apimachinery/pkg/util/wait"
4848
"k8s.io/apimachinery/pkg/watch"
49-
coreinformers "k8s.io/client-go/informers"
5049
"k8s.io/client-go/kubernetes"
5150
kubefake "k8s.io/client-go/kubernetes/fake"
5251
"k8s.io/client-go/kubernetes/scheme"
53-
corelisters "k8s.io/client-go/listers/core/v1"
5452
core "k8s.io/client-go/testing"
5553
"k8s.io/client-go/tools/cache"
5654
"k8s.io/client-go/tools/record"
@@ -722,8 +720,6 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
722720
informerFactory = informers.NewSharedInformerFactory(clientset, NoResyncPeriodFunc())
723721
}
724722

725-
coreFactory := coreinformers.NewSharedInformerFactory(kubeClient, NoResyncPeriodFunc())
726-
727723
// Construct controller
728724
csiConnection := &fakeCSIConnection{
729725
t: t,
@@ -739,7 +735,6 @@ func newTestController(kubeClient kubernetes.Interface, clientset clientset.Inte
739735
informerFactory.Volumesnapshot().V1alpha1().VolumeSnapshots(),
740736
informerFactory.Volumesnapshot().V1alpha1().VolumeSnapshotContents(),
741737
informerFactory.Volumesnapshot().V1alpha1().VolumeSnapshotClasses(),
742-
coreFactory.Core().V1().PersistentVolumeClaims(),
743738
3,
744739
5*time.Millisecond,
745740
csiConnection,
@@ -1057,14 +1052,9 @@ func runSyncTests(t *testing.T, tests []controllerTest, snapshotClasses []*crdv1
10571052
reactor.contents[content.Name] = content
10581053
}
10591054
}
1060-
1061-
pvcIndexer := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{})
10621055
for _, claim := range test.initialClaims {
10631056
reactor.claims[claim.Name] = claim
1064-
pvcIndexer.Add(claim)
10651057
}
1066-
ctrl.pvcLister = corelisters.NewPersistentVolumeClaimLister(pvcIndexer)
1067-
10681058
for _, volume := range test.initialVolumes {
10691059
reactor.volumes[volume.Name] = volume
10701060
}

pkg/controller/snapshot_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,9 @@ func (ctrl *csiSnapshotController) getClaimFromVolumeSnapshot(snapshot *crdv1.Vo
947947
return nil, fmt.Errorf("the snapshot source does not have the right APIGroup. Expected empty string, Got %s", *(snapshot.Spec.Source.APIGroup))
948948
}
949949

950-
pvc, err := ctrl.pvcLister.PersistentVolumeClaims(snapshot.Namespace).Get(pvcName)
950+
pvc, err := ctrl.client.CoreV1().PersistentVolumeClaims(snapshot.Namespace).Get(pvcName, metav1.GetOptions{})
951951
if err != nil {
952-
return nil, fmt.Errorf("failed to retrieve PVC %s from the lister: %q", pvcName, err)
952+
return nil, fmt.Errorf("failed to retrieve PVC %s from the API server: %q", pvcName, err)
953953
}
954954

955955
return pvc, nil

pkg/controller/snapshot_controller_base.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ import (
3030
"k8s.io/apimachinery/pkg/api/errors"
3131
"k8s.io/apimachinery/pkg/labels"
3232
"k8s.io/apimachinery/pkg/util/wait"
33-
coreinformers "k8s.io/client-go/informers/core/v1"
3433
"k8s.io/client-go/kubernetes"
3534
"k8s.io/client-go/kubernetes/scheme"
3635
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
37-
corelisters "k8s.io/client-go/listers/core/v1"
3836
"k8s.io/client-go/tools/cache"
3937
"k8s.io/client-go/tools/record"
4038
"k8s.io/client-go/util/workqueue"
@@ -55,8 +53,6 @@ type csiSnapshotController struct {
5553
contentListerSynced cache.InformerSynced
5654
classLister storagelisters.VolumeSnapshotClassLister
5755
classListerSynced cache.InformerSynced
58-
pvcLister corelisters.PersistentVolumeClaimLister
59-
pvcListerSynced cache.InformerSynced
6056

6157
snapshotStore cache.Store
6258
contentStore cache.Store
@@ -78,7 +74,6 @@ func NewCSISnapshotController(
7874
volumeSnapshotInformer storageinformers.VolumeSnapshotInformer,
7975
volumeSnapshotContentInformer storageinformers.VolumeSnapshotContentInformer,
8076
volumeSnapshotClassInformer storageinformers.VolumeSnapshotClassInformer,
81-
pvcInformer coreinformers.PersistentVolumeClaimInformer,
8277
createSnapshotContentRetryCount int,
8378
createSnapshotContentInterval time.Duration,
8479
conn connection.CSIConnection,
@@ -109,9 +104,6 @@ func NewCSISnapshotController(
109104
contentQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "csi-snapshotter-content"),
110105
}
111106

112-
ctrl.pvcLister = pvcInformer.Lister()
113-
ctrl.pvcListerSynced = pvcInformer.Informer().HasSynced
114-
115107
volumeSnapshotInformer.Informer().AddEventHandlerWithResyncPeriod(
116108
cache.ResourceEventHandlerFuncs{
117109
AddFunc: func(obj interface{}) { ctrl.enqueueSnapshotWork(obj) },
@@ -147,7 +139,7 @@ func (ctrl *csiSnapshotController) Run(workers int, stopCh <-chan struct{}) {
147139
glog.Infof("Starting CSI snapshotter")
148140
defer glog.Infof("Shutting CSI snapshotter")
149141

150-
if !cache.WaitForCacheSync(stopCh, ctrl.snapshotListerSynced, ctrl.contentListerSynced, ctrl.classListerSynced, ctrl.pvcListerSynced) {
142+
if !cache.WaitForCacheSync(stopCh, ctrl.snapshotListerSynced, ctrl.contentListerSynced, ctrl.classListerSynced) {
151143
glog.Errorf("Cannot sync caches")
152144
return
153145
}

pkg/controller/snapshot_create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func TestCreateSnapshotSync(t *testing.T) {
255255
initialContents: nocontents,
256256
expectedContents: nocontents,
257257
initialSnapshots: newSnapshotArray("snap7-4", classGold, "", "snapuid7-4", "claim7-4", false, nil, nil, nil),
258-
expectedSnapshots: newSnapshotArray("snap7-4", classGold, "", "snapuid7-4", "claim7-4", false, newVolumeError("Failed to create snapshot: failed to get input parameters to create snapshot snap7-4: \"failed to retrieve PVC claim7-4 from the lister: \\\"persistentvolumeclaim \\\\\\\"claim7-4\\\\\\\" not found\\\"\""), nil, nil),
258+
expectedSnapshots: newSnapshotArray("snap7-4", classGold, "", "snapuid7-4", "claim7-4", false, newVolumeError("Failed to create snapshot: failed to get input parameters to create snapshot snap7-4: \"failed to retrieve PVC claim7-4 from the API server: \\\"cannot find claim claim7-4\\\"\""), nil, nil),
259259
initialVolumes: newVolumeArray("volume7-4", "pv-uid7-4", "pv-handle7-4", "1Gi", "pvc-uid7-4", "claim7-4", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classEmpty),
260260
expectedEvents: []string{"Warning SnapshotCreationFailed"},
261261
errors: noerrors,

0 commit comments

Comments
 (0)