From 0dcb758119a38d98cc0d29eb4ee7cbbac6c079d7 Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Thu, 11 Jan 2024 16:02:06 +0000 Subject: [PATCH] Create a dedicated Admin user for use in tests Instead of relying on the default user which is deprecated. Signed-off-by: Richard Wall --- test/acme/fixture.go | 18 +++++++++++++++++- test/acme/util.go | 8 ++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/test/acme/fixture.go b/test/acme/fixture.go index 28711ae80..3e102e1b0 100644 --- a/test/acme/fixture.go +++ b/test/acme/fixture.go @@ -71,7 +71,10 @@ type fixture struct { setupLock sync.Mutex environment *envtest.Environment - clientset kubernetes.Interface + // An admin user for running kubectl commands against this envtest + // environment. + adminUser *envtest.AuthenticatedUser + clientset kubernetes.Interface pollInterval time.Duration propagationLimit time.Duration @@ -114,6 +117,19 @@ func (f *fixture) setup(t *testing.T) func() { env, stopFunc := apiserver.RunBareControlPlane(t) f.environment = env + // An admin user instance for running kubectl against this envtest + // environment. + // Derived from the envtest global config which is configured with very high + // QPS and Burst settings for rapid interactions with the API server. + adminUser, err := env.AddUser(envtest.User{ + Name: "envtest-admin", + Groups: []string{"system:masters"}, + }, env.Config) + if err != nil { + t.Fatalf("unable to provision admin user: %s", err) + } + f.adminUser = adminUser + cl, err := kubernetes.NewForConfig(env.Config) if err != nil { t.Fatal(err) diff --git a/test/acme/util.go b/test/acme/util.go index 807e3ad13..4ce981304 100644 --- a/test/acme/util.go +++ b/test/acme/util.go @@ -46,6 +46,11 @@ func (f *fixture) setupNamespace(t *testing.T, name string) (string, func()) { t.Fatalf("error creating test namespace %q: %v", name, err) } + kubectl, err := f.adminUser.Kubectl() + if err != nil { + t.Fatalf("enable to create kubectl instance: %s", err) + } + if f.kubectlManifestsPath != "" { if err := filepath.Walk(f.kubectlManifestsPath, func(path string, info os.FileInfo, err error) error { if err != nil { @@ -61,8 +66,7 @@ func (f *fixture) setupNamespace(t *testing.T, name string) (string, func()) { t.Logf("skipping file %q with unrecognised extension", path) return nil } - - _, _, err = f.environment.ControlPlane.KubeCtl().Run("apply", "--namespace", name, "-f", path) + _, _, err = kubectl.Run("apply", "--namespace", name, "-f", path) if err != nil { return err }