From 77211d3fa3b573b1f1b7038d71cfcacb1a91e845 Mon Sep 17 00:00:00 2001 From: Mauricio Poppe Date: Fri, 7 May 2021 18:25:37 +0000 Subject: [PATCH] remove volumesnapshots requests --- cmd/snapshot-controller/main.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/snapshot-controller/main.go b/cmd/snapshot-controller/main.go index ad1210eb..29afc328 100644 --- a/cmd/snapshot-controller/main.go +++ b/cmd/snapshot-controller/main.go @@ -64,18 +64,17 @@ var ( ) // Checks that the VolumeSnapshot v1 CRDs exist. -func ensureCustomResourceDefinitionsExist(kubeClient *kubernetes.Clientset, client *clientset.Clientset) error { +func ensureCustomResourceDefinitionsExist(client *clientset.Clientset) error { condition := func() (bool, error) { var err error - _, err = kubeClient.CoreV1().Namespaces().Get(context.TODO(), "kube-system", metav1.GetOptions{}) - if err == nil { - // only execute list VolumeSnapshots if the kube-system namespace exists - _, err = client.SnapshotV1().VolumeSnapshots("kube-system").List(context.TODO(), metav1.ListOptions{}) - if err != nil { - klog.Errorf("Failed to list v1 volumesnapshots with error=%+v", err) - return false, nil - } + + // scoping to an empty namespace makes `List` work across all namespaces + _, err = client.SnapshotV1().VolumeSnapshots("").List(context.TODO(), metav1.ListOptions{}) + if err != nil { + klog.Errorf("Failed to list v1 volumesnapshots with error=%+v", err) + return false, nil } + _, err = client.SnapshotV1().VolumeSnapshotClasses().List(context.TODO(), metav1.ListOptions{}) if err != nil { klog.Errorf("Failed to list v1 volumesnapshotclasses with error=%+v", err) @@ -173,7 +172,7 @@ func main() { *resyncPeriod, ) - if err := ensureCustomResourceDefinitionsExist(kubeClient, snapClient); err != nil { + if err := ensureCustomResourceDefinitionsExist(snapClient); err != nil { klog.Errorf("Exiting due to failure to ensure CRDs exist during startup: %+v", err) os.Exit(1) }