Skip to content

Commit

Permalink
Only execute list VolumeSnapshots if the kube-system namespace exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciopoppe committed Apr 23, 2021
1 parent a628278 commit 6d44eb3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cmd/snapshot-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ var (
)

// Checks that the VolumeSnapshot v1 CRDs exist.
func ensureCustomResourceDefinitionsExist(client *clientset.Clientset) error {
func ensureCustomResourceDefinitionsExist(kubeClient *kubernetes.Clientset, client *clientset.Clientset) error {
condition := func() (bool, error) {
var err error
_, err = client.SnapshotV1().VolumeSnapshots("kube-system").List(context.TODO(), metav1.ListOptions{})
_, err = kubeClient.CoreV1().Namespaces().Get(context.TODO(), "kube-system", metav1.GetOptions{})
if err != nil {
klog.Errorf("Failed to list v1 volumesnapshots with error=%+v", err)
return false, 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
}
}
_, err = client.SnapshotV1().VolumeSnapshotClasses().List(context.TODO(), metav1.ListOptions{})
if err != nil {
Expand All @@ -94,6 +98,7 @@ func ensureCustomResourceDefinitionsExist(client *clientset.Clientset) error {
if err := wait.ExponentialBackoff(backoff, condition); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -168,8 +173,8 @@ func main() {
*resyncPeriod,
)

if err := ensureCustomResourceDefinitionsExist(snapClient); err != nil {
klog.Errorf("Failed to ensure CRDs exist during startup: %+v", err)
if err := ensureCustomResourceDefinitionsExist(kubeClient, snapClient); err != nil {
klog.Errorf("Exiting due to failure to ensure CRDs exist during startup: %+v", err)
os.Exit(1)
}

Expand Down

0 comments on commit 6d44eb3

Please sign in to comment.