Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify wait logic for service account creation in e2e validating webhook test #979

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/e2e/validatingwebhook/kubeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io/ioutil"
"path/filepath"
"time"

"github.com/mitchellh/go-homedir"
admissionv1 "k8s.io/api/admissionregistration/v1"
Expand Down Expand Up @@ -170,3 +171,19 @@ func (k *KubernetesClient) CreateService(resourceFile string) (*v1.Service, erro
func (k *KubernetesClient) DeleteService(serviceName string) error {
return k.client.CoreV1().Services(namespace).Delete(context.TODO(), serviceName, metav1.DeleteOptions{})
}

// WaitForServiceAccount will wait for the default serviceaccount to get created
func (k *KubernetesClient) WaitForServiceAccount(ctx context.Context) error {
for {
svcAcc, err := k.client.CoreV1().ServiceAccounts(namespace).List(ctx, metav1.ListOptions{})
if err != nil || ctx.Err() != nil {
return err
}
if len(svcAcc.Items) == 0 {
time.Sleep(100 * time.Millisecond)
continue
}
break
}
return nil
}
13 changes: 10 additions & 3 deletions test/e2e/validatingwebhook/validating_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package validatingwebhook_test

import (
"context"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -90,9 +91,15 @@ var _ = Describe("ValidatingWebhook", func() {
Fail(errMessage)
}

// sleep added so that the default serviceaccount is get created
// this logic needs to be improved
time.Sleep(20 * time.Second)
// wait 1 minute max for the service account to get created
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()

err = kubeClient.WaitForServiceAccount(ctx)
if err != nil {
errMessage := fmt.Sprintf("service account for default namespace not created after 1 minute, error: %s", err.Error())
Fail(errMessage)
}
})

AfterSuite(func() {
Expand Down