From 9bbbe23b43a8ea41ba65c0828329429a20ebc2cf Mon Sep 17 00:00:00 2001 From: Denis Tingajkin Date: Thu, 29 Oct 2020 12:55:17 +0700 Subject: [PATCH] add sample test Signed-off-by: Denis Tingajkin --- k8s/k8s.go | 5 +++-- k8s/require/require.go | 3 ++- spire/spire.go | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/k8s/k8s.go b/k8s/k8s.go index f18270ec2..aa62b1551 100644 --- a/k8s/k8s.go +++ b/k8s/k8s.go @@ -18,6 +18,7 @@ package k8s import ( + "context" "fmt" "io/ioutil" "os" @@ -73,7 +74,7 @@ func ApplyDeployment(path string, mutators ...func(deployment *v1.Deployment)) e for _, m := range mutators { m(&d) } - _, err = client.AppsV1().Deployments(namespace).Create(&d) + _, err = client.AppsV1().Deployments(namespace).Create(context.Background(), &d, metav1.CreateOptions{}) return err } @@ -86,7 +87,7 @@ func ShowLogs(options ...*exechelper.Option) { return } - pods, err := client.CoreV1().Pods(namespace).List(metav1.ListOptions{}) + pods, err := client.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{}) if err != nil { logrus.Errorf("Cannot get pods: %v", err.Error()) diff --git a/k8s/require/require.go b/k8s/require/require.go index f6e81fc76..c26ededf0 100644 --- a/k8s/require/require.go +++ b/k8s/require/require.go @@ -18,6 +18,7 @@ package require import ( + "context" "fmt" "testing" @@ -31,7 +32,7 @@ import ( func NoRestarts(t *testing.T) { c, err := k8s.Client() require.NoError(t, err) - list, err := c.CoreV1().Pods("default").List(metav1.ListOptions{}) + list, err := c.CoreV1().Pods("default").List(context.Background(), metav1.ListOptions{}) require.NoError(t, err) for i := 0; i < len(list.Items); i++ { pod := &list.Items[i] diff --git a/spire/spire.go b/spire/spire.go index 7496e7596..1643e635a 100644 --- a/spire/spire.go +++ b/spire/spire.go @@ -18,6 +18,8 @@ package spire import ( + "context" + "github.com/edwarnicke/exechelper" "github.com/pkg/errors" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -30,7 +32,7 @@ func exist() bool { if err != nil { return false } - _, err = client.CoreV1().Namespaces().Get("spire", v1.GetOptions{}) + _, err = client.CoreV1().Namespaces().Get(context.Background(), "spire", v1.GetOptions{}) return err == nil }