mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #109755 from p0lyn0mial/harden-test-service-account
hardens integration serviceaccount tests
This commit is contained in:
commit
e514c5d79c
@ -66,7 +66,7 @@ const (
|
||||
)
|
||||
|
||||
func TestServiceAccountAutoCreate(t *testing.T) {
|
||||
c, _, stopFunc, err := startServiceAccountTestServer(t)
|
||||
c, _, stopFunc, err := startServiceAccountTestServerAndWaitForCaches(t)
|
||||
defer stopFunc()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to setup ServiceAccounts server: %v", err)
|
||||
@ -104,7 +104,7 @@ func TestServiceAccountAutoCreate(t *testing.T) {
|
||||
|
||||
func TestServiceAccountTokenAutoCreate(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.LegacyServiceAccountTokenNoAutoGeneration, false)()
|
||||
c, _, stopFunc, err := startServiceAccountTestServer(t)
|
||||
c, _, stopFunc, err := startServiceAccountTestServerAndWaitForCaches(t)
|
||||
defer stopFunc()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to setup ServiceAccounts server: %v", err)
|
||||
@ -202,7 +202,7 @@ func TestServiceAccountTokenAutoCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServiceAccountTokenAutoMount(t *testing.T) {
|
||||
c, _, stopFunc, err := startServiceAccountTestServer(t)
|
||||
c, _, stopFunc, err := startServiceAccountTestServerAndWaitForCaches(t)
|
||||
defer stopFunc()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to setup ServiceAccounts server: %v", err)
|
||||
@ -244,7 +244,7 @@ func TestServiceAccountTokenAutoMount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestServiceAccountTokenAuthentication(t *testing.T) {
|
||||
c, config, stopFunc, err := startServiceAccountTestServer(t)
|
||||
c, config, stopFunc, err := startServiceAccountTestServerAndWaitForCaches(t)
|
||||
defer stopFunc()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to setup ServiceAccounts server: %v", err)
|
||||
@ -320,9 +320,9 @@ func TestServiceAccountTokenAuthentication(t *testing.T) {
|
||||
doServiceAccountAPIRequests(t, rwClient, otherns, true, false, false)
|
||||
}
|
||||
|
||||
// startServiceAccountTestServer returns a started server
|
||||
// startServiceAccountTestServerAndWaitForCaches returns a started server
|
||||
// It is the responsibility of the caller to ensure the returned stopFunc is called
|
||||
func startServiceAccountTestServer(t *testing.T) (*clientset.Clientset, restclient.Config, func(), error) {
|
||||
func startServiceAccountTestServerAndWaitForCaches(t *testing.T) (*clientset.Clientset, restclient.Config, func(), error) {
|
||||
// Listener
|
||||
h := &framework.APIServerHolder{Initialized: make(chan struct{})}
|
||||
apiServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
@ -448,6 +448,13 @@ func startServiceAccountTestServer(t *testing.T) (*clientset.Clientset, restclie
|
||||
externalInformers.Start(ctx.Done())
|
||||
go serviceAccountController.Run(ctx, 5)
|
||||
|
||||
// since this method starts the controllers in a separate goroutine
|
||||
// and the tests don't check /readyz there is no way
|
||||
// the tests can tell it is safe to call the server and requests won't be rejected
|
||||
// thus we wait until caches have synced
|
||||
informers.WaitForCacheSync(ctx.Done())
|
||||
externalInformers.WaitForCacheSync(ctx.Done())
|
||||
|
||||
return rootClientset, clientConfig, stop, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user