@@ -64,18 +64,17 @@ var (
6464)
6565
6666// Checks that the VolumeSnapshot v1 CRDs exist.
67- func ensureCustomResourceDefinitionsExist (kubeClient * kubernetes. Clientset , client * clientset.Clientset ) error {
67+ func ensureCustomResourceDefinitionsExist (client * clientset.Clientset ) error {
6868 condition := func () (bool , error ) {
6969 var err error
70- _ , err = kubeClient .CoreV1 ().Namespaces ().Get (context .TODO (), "kube-system" , metav1.GetOptions {})
71- if err == nil {
72- // only execute list VolumeSnapshots if the kube-system namespace exists
73- _ , err = client .SnapshotV1 ().VolumeSnapshots ("kube-system" ).List (context .TODO (), metav1.ListOptions {})
74- if err != nil {
75- klog .Errorf ("Failed to list v1 volumesnapshots with error=%+v" , err )
76- return false , nil
77- }
70+
71+ // scoping to an empty namespace makes `List` work across all namespaces
72+ _ , err = client .SnapshotV1 ().VolumeSnapshots ("" ).List (context .TODO (), metav1.ListOptions {})
73+ if err != nil {
74+ klog .Errorf ("Failed to list v1 volumesnapshots with error=%+v" , err )
75+ return false , nil
7876 }
77+
7978 _ , err = client .SnapshotV1 ().VolumeSnapshotClasses ().List (context .TODO (), metav1.ListOptions {})
8079 if err != nil {
8180 klog .Errorf ("Failed to list v1 volumesnapshotclasses with error=%+v" , err )
@@ -173,7 +172,7 @@ func main() {
173172 * resyncPeriod ,
174173 )
175174
176- if err := ensureCustomResourceDefinitionsExist (kubeClient , snapClient ); err != nil {
175+ if err := ensureCustomResourceDefinitionsExist (snapClient ); err != nil {
177176 klog .Errorf ("Exiting due to failure to ensure CRDs exist during startup: %+v" , err )
178177 os .Exit (1 )
179178 }
0 commit comments