Skip to content

Commit

Permalink
Namespace Creation and Deletion Adhere to timeout rules (#230)
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Sipe <kensipe@gmail.com>
  • Loading branch information
kensipe authored Oct 16, 2020
1 parent 13edfef commit f052443
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pkg/test/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sort"
"strconv"
"testing"
"time"

petname "github.com/dustinkirkland/golang-petname"
"github.com/thoas/go-funk"
Expand Down Expand Up @@ -64,7 +65,14 @@ func (t *Case) DeleteNamespace(ns *namespace) error {
return err
}

return cl.Delete(context.TODO(), &corev1.Namespace{
ctx := context.Background()
if t.Timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, time.Duration(t.Timeout)*time.Second)
defer cancel()
}

return cl.Delete(ctx, &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: ns.Name,
},
Expand All @@ -87,7 +95,14 @@ func (t *Case) CreateNamespace(ns *namespace) error {
return err
}

return cl.Create(context.TODO(), &corev1.Namespace{
ctx := context.Background()
if t.Timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, time.Duration(t.Timeout)*time.Second)
defer cancel()
}

return cl.Create(ctx, &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: ns.Name,
},
Expand Down

0 comments on commit f052443

Please sign in to comment.