Skip to content

Commit

Permalink
fix: Use framework.WithDisruptive()
Browse files Browse the repository at this point in the history
  • Loading branch information
bryantbiggs committed Jan 9, 2024
1 parent acbfad3 commit 6c94ad6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
33 changes: 12 additions & 21 deletions tests/e2e/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import (
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
restclientset "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/kubernetes/test/e2e/framework"
)

Expand All @@ -41,33 +38,27 @@ const (
testTimeout = 300 * time.Second
)

var _ = Describe("[apiserver] the apiserver", framework.WithDisruptive(), func() {
var (
cs clientset.Interface
cfg *restclientset.Config
)
var _ = Describe("the apiserver", framework.WithDisruptive(), func() {
f := framework.NewDefaultFramework("apiserver")

When("the manifest changes", func() {
When("the manifest changes", func(ctx context.Context) {
BeforeEach(func() {
cfg, _ = clientcmd.BuildConfigFromFlags("", framework.TestContext.KubeConfig)
cs, _ = clientset.NewForConfig(cfg)

jobPath := filepath.Join(os.Getenv("BASE_DIR"), "apiserver-restart.yaml")

b, _ := os.ReadFile(jobPath)
decoder := yamlutil.NewYAMLOrJSONDecoder(bytes.NewReader(b), 100)
jobSpec := &batchv1.Job{}
_ = decoder.Decode(&jobSpec)

_, _ = cs.BatchV1().
_, _ = f.ClientSet.BatchV1().
Jobs(kubeSystemNs).
Create(context.TODO(), jobSpec, metav1.CreateOptions{})
Create(ctx, jobSpec, metav1.CreateOptions{})

fmt.Printf("Waiting for apiserver to go down...\n")
err := wait.PollImmediate(restartDelay, restartWait, func() (bool, error) {
_, pingErr := cs.CoreV1().
_, pingErr := f.ClientSet.CoreV1().
Nodes().
List(context.TODO(), metav1.ListOptions{})
List(ctx, metav1.ListOptions{})

if pingErr == nil {
return false, nil
Expand All @@ -81,16 +72,16 @@ var _ = Describe("[apiserver] the apiserver", framework.WithDisruptive(), func()
}
})

AfterEach(func() {
cs.BatchV1().Jobs(kubeSystemNs).Delete(context.TODO(), "apiserver-restarter", metav1.DeleteOptions{})
AfterEach(func(ctx context.Context) {
f.ClientSet.BatchV1().Jobs(kubeSystemNs).Delete(ctx, "apiserver-restarter", metav1.DeleteOptions{})
})

It("restarts successfully", func() {
It("restarts successfully", func(ctx context.Context) {
startTime := time.Now()
err := wait.PollImmediate(1, testTimeout, func() (bool, error) {
res, pingErr := cs.CoreV1().
res, pingErr := f.ClientSet.CoreV1().
Nodes().
List(context.TODO(), metav1.ListOptions{})
List(ctx, metav1.ListOptions{})

if pingErr == nil {
fmt.Printf("after %ds: apiserver back up: %v nodes\n", int(time.Since(startTime).Seconds()), len(res.Items))
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module sigs.k8s.io/aws-iam-authenticator/tests/e2e
go 1.21

require (
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/gomega v1.29.0
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v1.5.2
Expand Down Expand Up @@ -44,7 +44,7 @@ require (
github.com/prometheus/procfs v0.10.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -112,8 +112,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.15.0 h1:s8pnnxNVzjWyrvYdFUQq5llS1PX2zhPXmccZv99h7uQ=
golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCAM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down

0 comments on commit 6c94ad6

Please sign in to comment.