Skip to content

Commit 6ae80fe

Browse files
committed
Time-out using cluster context at 5s
This makes kubetrim try for 5s before giving up on a context/ cluster. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent e2a8260 commit 6ae80fe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ func main() {
151151

152152
// checkCluster tries to list nodes in the cluster to verify if the context is working
153153
func checkCluster(clientset *kubernetes.Clientset) error {
154-
_, err := clientset.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
154+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
155+
defer cancel()
156+
157+
_, err := clientset.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
155158
if err != nil {
156159
return fmt.Errorf("failed to connect to cluster: %v", err)
157160
}

0 commit comments

Comments
 (0)