From 1e03155e8b89ce4c77bd1d7db04529e2ff760783 Mon Sep 17 00:00:00 2001
From: stefanprodan <stefan.prodan@gmail.com>
Date: Wed, 29 Apr 2020 10:48:12 +0300
Subject: [PATCH] Add poll interval global variable

---
 cmd/tk/create_kustomization.go |  2 +-
 cmd/tk/create_source_git.go    | 12 +++++-------
 cmd/tk/main.go                 | 13 +++++++------
 cmd/tk/sync_kustomization.go   |  2 +-
 cmd/tk/sync_source_git.go      |  2 +-
 5 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/cmd/tk/create_kustomization.go b/cmd/tk/create_kustomization.go
index a15166da..34ecd526 100644
--- a/cmd/tk/create_kustomization.go
+++ b/cmd/tk/create_kustomization.go
@@ -161,7 +161,7 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error {
 	}
 
 	logWaiting("waiting for kustomization sync")
-	if err := wait.PollImmediate(2*time.Second, timeout,
+	if err := wait.PollImmediate(pollInterval, timeout,
 		isKustomizationReady(ctx, kubeClient, name, namespace)); err != nil {
 		return err
 	}
diff --git a/cmd/tk/create_source_git.go b/cmd/tk/create_source_git.go
index 6c0a409b..b5953b27 100644
--- a/cmd/tk/create_source_git.go
+++ b/cmd/tk/create_source_git.go
@@ -3,21 +3,19 @@ package main
 import (
 	"context"
 	"fmt"
-	"io/ioutil"
-	"net/url"
-	"os"
-	"strings"
-	"time"
-
 	sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
 	"github.com/manifoldco/promptui"
 	"github.com/spf13/cobra"
+	"io/ioutil"
 	corev1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/apimachinery/pkg/util/wait"
+	"net/url"
+	"os"
 	"sigs.k8s.io/controller-runtime/pkg/client"
+	"strings"
 )
 
 var createSourceGitCmd = &cobra.Command{
@@ -158,7 +156,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
 	}
 
 	logWaiting("waiting for git sync")
-	if err := wait.PollImmediate(2*time.Second, timeout,
+	if err := wait.PollImmediate(pollInterval, timeout,
 		isGitRepositoryReady(ctx, kubeClient, name, namespace)); err != nil {
 		return err
 	}
diff --git a/cmd/tk/main.go b/cmd/tk/main.go
index 6fbee802..afd97f65 100644
--- a/cmd/tk/main.go
+++ b/cmd/tk/main.go
@@ -50,12 +50,13 @@ var rootCmd = &cobra.Command{
 }
 
 var (
-	kubeconfig string
-	namespace  string
-	timeout    time.Duration
-	verbose    bool
-	components []string
-	utils      Utils
+	kubeconfig   string
+	namespace    string
+	timeout      time.Duration
+	verbose      bool
+	components   []string
+	utils        Utils
+	pollInterval = 2 * time.Second
 )
 
 func init() {
diff --git a/cmd/tk/sync_kustomization.go b/cmd/tk/sync_kustomization.go
index 20ab29b1..e1def0fa 100644
--- a/cmd/tk/sync_kustomization.go
+++ b/cmd/tk/sync_kustomization.go
@@ -82,7 +82,7 @@ func syncKsCmdRun(cmd *cobra.Command, args []string) error {
 	}
 
 	logWaiting("waiting for kustomization sync")
-	if err := wait.PollImmediate(2*time.Second, timeout,
+	if err := wait.PollImmediate(pollInterval, timeout,
 		isKustomizationReady(ctx, kubeClient, name, namespace)); err != nil {
 		return err
 	}
diff --git a/cmd/tk/sync_source_git.go b/cmd/tk/sync_source_git.go
index b714f2bb..d9c7ffa0 100644
--- a/cmd/tk/sync_source_git.go
+++ b/cmd/tk/sync_source_git.go
@@ -64,7 +64,7 @@ func syncSourceGitCmdRun(cmd *cobra.Command, args []string) error {
 	logSuccess("source annotated")
 
 	logWaiting("waiting for git sync")
-	if err := wait.PollImmediate(2*time.Second, timeout,
+	if err := wait.PollImmediate(pollInterval, timeout,
 		isGitRepositoryReady(ctx, kubeClient, name, namespace)); err != nil {
 		return err
 	}
-- 
GitLab