mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
test: use cancelation from ktesting
The return type of ktesting.NewTestContext is now a TContext. Code which combined it WithCancel often didn't compile anymore (cannot overwrite ktesting.TContext with context.Context). This is a good thing because all of that code can be simplified to let ktesting handle the cancelation.
This commit is contained in:
@@ -58,11 +58,8 @@ func alwaysAlice(req *http.Request) (*authenticator.Response, bool, error) {
|
||||
}
|
||||
|
||||
func TestSubjectAccessReview(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
clientset, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
clientset, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Unset BearerToken to disable BearerToken authenticator.
|
||||
config.GenericConfig.LoopbackClientConfig.BearerToken = ""
|
||||
@@ -132,7 +129,7 @@ func TestSubjectAccessReview(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
response, err := clientset.AuthorizationV1().SubjectAccessReviews().Create(ctx, test.sar, metav1.CreateOptions{})
|
||||
response, err := clientset.AuthorizationV1().SubjectAccessReviews().Create(tCtx, test.sar, metav1.CreateOptions{})
|
||||
switch {
|
||||
case err == nil && len(test.expectedError) == 0:
|
||||
|
||||
@@ -154,9 +151,7 @@ func TestSubjectAccessReview(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSelfSubjectAccessReview(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
tCtx := ktesting.Init(t)
|
||||
|
||||
var mutex sync.Mutex
|
||||
|
||||
@@ -174,7 +169,7 @@ func TestSelfSubjectAccessReview(t *testing.T) {
|
||||
}, true, nil
|
||||
}
|
||||
|
||||
clientset, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
clientset, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Unset BearerToken to disable BearerToken authenticator.
|
||||
config.GenericConfig.LoopbackClientConfig.BearerToken = ""
|
||||
@@ -235,7 +230,7 @@ func TestSelfSubjectAccessReview(t *testing.T) {
|
||||
username = test.username
|
||||
mutex.Unlock()
|
||||
|
||||
response, err := clientset.AuthorizationV1().SelfSubjectAccessReviews().Create(ctx, test.sar, metav1.CreateOptions{})
|
||||
response, err := clientset.AuthorizationV1().SelfSubjectAccessReviews().Create(tCtx, test.sar, metav1.CreateOptions{})
|
||||
switch {
|
||||
case err == nil && len(test.expectedError) == 0:
|
||||
|
||||
@@ -257,11 +252,8 @@ func TestSelfSubjectAccessReview(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLocalSubjectAccessReview(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
clientset, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
clientset, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Unset BearerToken to disable BearerToken authenticator.
|
||||
config.GenericConfig.LoopbackClientConfig.BearerToken = ""
|
||||
@@ -359,7 +351,7 @@ func TestLocalSubjectAccessReview(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
response, err := clientset.AuthorizationV1().LocalSubjectAccessReviews(test.namespace).Create(ctx, test.sar, metav1.CreateOptions{})
|
||||
response, err := clientset.AuthorizationV1().LocalSubjectAccessReviews(test.namespace).Create(tCtx, test.sar, metav1.CreateOptions{})
|
||||
switch {
|
||||
case err == nil && len(test.expectedError) == 0:
|
||||
|
||||
|
||||
@@ -454,11 +454,8 @@ func getTestRequests(namespace string) []testRequest {
|
||||
//
|
||||
// TODO(etune): write a fuzz test of the REST API.
|
||||
func TestAuthModeAlwaysAllow(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -562,11 +559,8 @@ func getPreviousResourceVersionKey(url, id string) string {
|
||||
}
|
||||
|
||||
func TestAuthModeAlwaysDeny(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -610,11 +604,8 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
|
||||
// TestAliceNotForbiddenOrUnauthorized tests a user who is known to
|
||||
// the authentication system and authorized to do any actions.
|
||||
func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -690,11 +681,8 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
|
||||
// the authentication system but not authorized to do any actions
|
||||
// should receive "Forbidden".
|
||||
func TestBobIsForbidden(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -743,11 +731,8 @@ func TestBobIsForbidden(t *testing.T) {
|
||||
// An authorization module is installed in this scenario for integration
|
||||
// test purposes, but requests aren't expected to reach it.
|
||||
func TestUnknownUserIsUnauthorized(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -819,11 +804,8 @@ func (impersonateAuthorizer) Authorize(ctx context.Context, a authorizer.Attribu
|
||||
}
|
||||
|
||||
func TestImpersonateIsForbidden(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -1125,13 +1107,11 @@ func (a *trackingAuthorizer) Authorize(ctx context.Context, attributes authorize
|
||||
|
||||
// TestAuthorizationAttributeDetermination tests that authorization attributes are built correctly
|
||||
func TestAuthorizationAttributeDetermination(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
tCtx := ktesting.Init(t)
|
||||
|
||||
trackingAuthorizer := &trackingAuthorizer{}
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -1201,11 +1181,9 @@ func TestAuthorizationAttributeDetermination(t *testing.T) {
|
||||
// TestNamespaceAuthorization tests that authorization can be controlled
|
||||
// by namespace.
|
||||
func TestNamespaceAuthorization(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
tCtx := ktesting.Init(t)
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -1306,11 +1284,9 @@ func TestNamespaceAuthorization(t *testing.T) {
|
||||
// TestKindAuthorization tests that authorization can be controlled
|
||||
// by namespace.
|
||||
func TestKindAuthorization(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
tCtx := ktesting.Init(t)
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -1393,11 +1369,8 @@ func TestKindAuthorization(t *testing.T) {
|
||||
// TestReadOnlyAuthorization tests that authorization can be controlled
|
||||
// by namespace.
|
||||
func TestReadOnlyAuthorization(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -1461,10 +1434,7 @@ func TestWebhookTokenAuthenticatorCustomDial(t *testing.T) {
|
||||
}
|
||||
|
||||
func testWebhookTokenAuthenticator(customDialer bool, t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
tCtx := ktesting.Init(t)
|
||||
authServer := newTestWebhookTokenAuthServer()
|
||||
defer authServer.Close()
|
||||
var authenticator authenticator.Request
|
||||
@@ -1480,7 +1450,7 @@ func testWebhookTokenAuthenticator(customDialer bool, t *testing.T) {
|
||||
t.Fatalf("error starting webhook token authenticator server: %v", err)
|
||||
}
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
|
||||
@@ -18,7 +18,6 @@ package auth
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -121,13 +120,10 @@ func TestBootstrapTokenAuth(t *testing.T) {
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
tCtx := ktesting.Init(t)
|
||||
authenticator := group.NewAuthenticatedGroupAdder(bearertoken.New(bootstrap.NewTokenAuthenticator(bootstrapSecrets{test.secret})))
|
||||
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
opts.Authorization.Modes = []string{"AlwaysAllow"}
|
||||
},
|
||||
|
||||
@@ -54,11 +54,8 @@ func TestDynamicClientBuilder(t *testing.T) {
|
||||
t.Fatalf("parse duration failed: %v", err)
|
||||
}
|
||||
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
baseClient, baseConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
baseClient, baseConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
opts.ServiceAccountSigningKeyFile = tmpfile.Name()
|
||||
opts.ServiceAccountTokenMaxExpiration = maxExpirationDuration
|
||||
@@ -102,7 +99,7 @@ func TestDynamicClientBuilder(t *testing.T) {
|
||||
|
||||
// We want to trigger token rotation here by deleting service account
|
||||
// the dynamic client was using.
|
||||
if err = dymClient.CoreV1().ServiceAccounts(ns).Delete(ctx, saName, metav1.DeleteOptions{}); err != nil {
|
||||
if err = dymClient.CoreV1().ServiceAccounts(ns).Delete(tCtx, saName, metav1.DeleteOptions{}); err != nil {
|
||||
t.Fatalf("delete service account %s failed: %v", saName, err)
|
||||
}
|
||||
time.Sleep(time.Second * 10)
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
rbacapi "k8s.io/api/rbac/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -538,10 +537,7 @@ func TestRBAC(t *testing.T) {
|
||||
"user-with-no-permissions": {Name: "user-with-no-permissions"},
|
||||
})))
|
||||
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
tCtx := ktesting.Init(t)
|
||||
var tearDownAuthorizerFn func()
|
||||
defer func() {
|
||||
if tearDownAuthorizerFn != nil {
|
||||
@@ -549,7 +545,7 @@ func TestRBAC(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
_, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
_, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
// Also disable namespace lifecycle to workaroung the test limitation that first creates
|
||||
@@ -675,23 +671,20 @@ func TestRBAC(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBootstrapping(t *testing.T) {
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
clientset, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
clientset, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
opts.Authorization.Modes = []string{"RBAC"}
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
watcher, err := clientset.RbacV1().ClusterRoles().Watch(ctx, metav1.ListOptions{ResourceVersion: "0"})
|
||||
watcher, err := clientset.RbacV1().ClusterRoles().Watch(tCtx, metav1.ListOptions{ResourceVersion: "0"})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
_, err = watchtools.UntilWithoutRetry(ctx, watcher, func(event watch.Event) (bool, error) {
|
||||
_, err = watchtools.UntilWithoutRetry(tCtx, watcher, func(event watch.Event) (bool, error) {
|
||||
if event.Type != watch.Added {
|
||||
return false, nil
|
||||
}
|
||||
@@ -701,7 +694,7 @@ func TestBootstrapping(t *testing.T) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
clusterRoles, err := clientset.RbacV1().ClusterRoles().List(ctx, metav1.ListOptions{})
|
||||
clusterRoles, err := clientset.RbacV1().ClusterRoles().List(tCtx, metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -717,7 +710,7 @@ func TestBootstrapping(t *testing.T) {
|
||||
|
||||
t.Errorf("missing cluster-admin: %v", clusterRoles)
|
||||
|
||||
healthBytes, err := clientset.Discovery().RESTClient().Get().AbsPath("/healthz/poststarthook/rbac/bootstrap-roles").DoRaw(ctx)
|
||||
healthBytes, err := clientset.Discovery().RESTClient().Get().AbsPath("/healthz/poststarthook/rbac/bootstrap-roles").DoRaw(tCtx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -736,11 +729,8 @@ func TestDiscoveryUpgradeBootstrapping(t *testing.T) {
|
||||
|
||||
etcdConfig := framework.SharedEtcd()
|
||||
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
client, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
client, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Ensure we're using the same etcd across apiserver restarts.
|
||||
opts.Etcd.StorageConfig = *etcdConfig
|
||||
@@ -751,7 +741,7 @@ func TestDiscoveryUpgradeBootstrapping(t *testing.T) {
|
||||
// Modify the default RBAC discovery ClusterRoleBidnings to look more like the defaults that
|
||||
// existed prior to v1.14, but with user modifications.
|
||||
t.Logf("Modifying default `system:discovery` ClusterRoleBinding")
|
||||
discRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(ctx, "system:discovery", metav1.GetOptions{})
|
||||
discRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(tCtx, "system:discovery", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get `system:discovery` ClusterRoleBinding: %v", err)
|
||||
}
|
||||
@@ -764,21 +754,21 @@ func TestDiscoveryUpgradeBootstrapping(t *testing.T) {
|
||||
APIGroup: "rbac.authorization.k8s.io",
|
||||
},
|
||||
}
|
||||
if discRoleBinding, err = client.RbacV1().ClusterRoleBindings().Update(ctx, discRoleBinding, metav1.UpdateOptions{}); err != nil {
|
||||
if discRoleBinding, err = client.RbacV1().ClusterRoleBindings().Update(tCtx, discRoleBinding, metav1.UpdateOptions{}); err != nil {
|
||||
t.Fatalf("Failed to update `system:discovery` ClusterRoleBinding: %v", err)
|
||||
}
|
||||
t.Logf("Modifying default `system:basic-user` ClusterRoleBinding")
|
||||
basicUserRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(ctx, "system:basic-user", metav1.GetOptions{})
|
||||
basicUserRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(tCtx, "system:basic-user", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get `system:basic-user` ClusterRoleBinding: %v", err)
|
||||
}
|
||||
basicUserRoleBinding.Annotations["rbac.authorization.kubernetes.io/autoupdate"] = "false"
|
||||
basicUserRoleBinding.Annotations["rbac-discovery-upgrade-test"] = "pass"
|
||||
if basicUserRoleBinding, err = client.RbacV1().ClusterRoleBindings().Update(ctx, basicUserRoleBinding, metav1.UpdateOptions{}); err != nil {
|
||||
if basicUserRoleBinding, err = client.RbacV1().ClusterRoleBindings().Update(tCtx, basicUserRoleBinding, metav1.UpdateOptions{}); err != nil {
|
||||
t.Fatalf("Failed to update `system:basic-user` ClusterRoleBinding: %v", err)
|
||||
}
|
||||
t.Logf("Deleting default `system:public-info-viewer` ClusterRoleBinding")
|
||||
if err = client.RbacV1().ClusterRoleBindings().Delete(ctx, "system:public-info-viewer", metav1.DeleteOptions{}); err != nil {
|
||||
if err = client.RbacV1().ClusterRoleBindings().Delete(tCtx, "system:public-info-viewer", metav1.DeleteOptions{}); err != nil {
|
||||
t.Fatalf("Failed to delete `system:public-info-viewer` ClusterRoleBinding: %v", err)
|
||||
}
|
||||
|
||||
@@ -788,7 +778,7 @@ func TestDiscoveryUpgradeBootstrapping(t *testing.T) {
|
||||
|
||||
// Check that upgraded API servers inherit `system:public-info-viewer` settings from
|
||||
// `system:discovery`, and respect auto-reconciliation annotations.
|
||||
client, _, tearDownFn = framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
client, _, tearDownFn = framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Ensure we're using the same etcd across apiserver restarts.
|
||||
opts.Etcd.StorageConfig = *etcdConfig
|
||||
@@ -796,21 +786,21 @@ func TestDiscoveryUpgradeBootstrapping(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
newDiscRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(ctx, "system:discovery", metav1.GetOptions{})
|
||||
newDiscRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(tCtx, "system:discovery", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get `system:discovery` ClusterRoleBinding: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(newDiscRoleBinding, discRoleBinding) {
|
||||
t.Errorf("`system:discovery` should have been unmodified. Wanted: %v, got %v", discRoleBinding, newDiscRoleBinding)
|
||||
}
|
||||
newBasicUserRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(ctx, "system:basic-user", metav1.GetOptions{})
|
||||
newBasicUserRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(tCtx, "system:basic-user", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get `system:basic-user` ClusterRoleBinding: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(newBasicUserRoleBinding, basicUserRoleBinding) {
|
||||
t.Errorf("`system:basic-user` should have been unmodified. Wanted: %v, got %v", basicUserRoleBinding, newBasicUserRoleBinding)
|
||||
}
|
||||
publicInfoViewerRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(ctx, "system:public-info-viewer", metav1.GetOptions{})
|
||||
publicInfoViewerRoleBinding, err := client.RbacV1().ClusterRoleBindings().Get(tCtx, "system:public-info-viewer", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get `system:public-info-viewer` ClusterRoleBinding: %v", err)
|
||||
}
|
||||
|
||||
@@ -86,16 +86,13 @@ func TestGetsSelfAttributes(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
tCtx := ktesting.Init(t)
|
||||
var respMu sync.RWMutex
|
||||
response := &user.DefaultInfo{
|
||||
Name: "stub",
|
||||
}
|
||||
|
||||
kubeClient, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
kubeClient, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1alpha1=true")
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1beta1=true")
|
||||
@@ -122,7 +119,7 @@ func TestGetsSelfAttributes(t *testing.T) {
|
||||
|
||||
res, err := kubeClient.AuthenticationV1alpha1().
|
||||
SelfSubjectReviews().
|
||||
Create(ctx, &authenticationv1alpha1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
Create(tCtx, &authenticationv1alpha1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -149,7 +146,7 @@ func TestGetsSelfAttributes(t *testing.T) {
|
||||
|
||||
res2, err := kubeClient.AuthenticationV1beta1().
|
||||
SelfSubjectReviews().
|
||||
Create(ctx, &authenticationv1beta1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
Create(tCtx, &authenticationv1beta1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -208,11 +205,8 @@ func TestGetsSelfAttributesError(t *testing.T) {
|
||||
toggle := &atomic.Value{}
|
||||
toggle.Store(true)
|
||||
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
kubeClient, _, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
tCtx := ktesting.Init(t)
|
||||
kubeClient, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1alpha1=true")
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1beta1=true")
|
||||
@@ -244,7 +238,7 @@ func TestGetsSelfAttributesError(t *testing.T) {
|
||||
|
||||
_, err := kubeClient.AuthenticationV1alpha1().
|
||||
SelfSubjectReviews().
|
||||
Create(ctx, &authenticationv1alpha1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
Create(tCtx, &authenticationv1alpha1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
if err == nil {
|
||||
t.Fatalf("expected error: %v, got nil", err)
|
||||
}
|
||||
@@ -260,7 +254,7 @@ func TestGetsSelfAttributesError(t *testing.T) {
|
||||
|
||||
_, err := kubeClient.AuthenticationV1beta1().
|
||||
SelfSubjectReviews().
|
||||
Create(ctx, &authenticationv1beta1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
Create(tCtx, &authenticationv1beta1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
if err == nil {
|
||||
t.Fatalf("expected error: %v, got nil", err)
|
||||
}
|
||||
|
||||
@@ -79,9 +79,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
|
||||
var tokenGenerator serviceaccount.TokenGenerator
|
||||
|
||||
_, ctx := ktesting.NewTestContext(t)
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
tCtx := ktesting.Init(t)
|
||||
|
||||
// Enable the node token improvements feature gates prior to starting the apiserver, as the node getter is
|
||||
// conditionally passed to the service account token generator based on feature enablement.
|
||||
@@ -91,7 +89,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
|
||||
// Start the server
|
||||
var serverAddress string
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(ctx, t, framework.TestServerSetup{
|
||||
kubeClient, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
// Disable ServiceAccount admission plugin as we don't have serviceaccount controller running.
|
||||
opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount"}
|
||||
@@ -193,7 +191,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token for nonexistant svcacct but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -202,18 +200,18 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
|
||||
treqWithBadName := treq.DeepCopy()
|
||||
treqWithBadName.Name = "invalid-name"
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treqWithBadName, metav1.CreateOptions{}); err == nil || !strings.Contains(err.Error(), "must match the service account name") {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treqWithBadName, metav1.CreateOptions{}); err == nil || !strings.Contains(err.Error(), "must match the service account name") {
|
||||
t.Fatalf("expected err creating token with mismatched name but got: %#v", resp)
|
||||
}
|
||||
|
||||
treqWithBadNamespace := treq.DeepCopy()
|
||||
treqWithBadNamespace.Namespace = "invalid-namespace"
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treqWithBadNamespace, metav1.CreateOptions{}); err == nil || !strings.Contains(err.Error(), "does not match the namespace") {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treqWithBadNamespace, metav1.CreateOptions{}); err == nil || !strings.Contains(err.Error(), "does not match the namespace") {
|
||||
t.Fatalf("expected err creating token with mismatched namespace but got: %#v, %v", resp, err)
|
||||
}
|
||||
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -259,7 +257,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token for nonexistant svcacct but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -267,7 +265,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
defer del()
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token bound to nonexistant pod but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -277,21 +275,21 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
// right uid
|
||||
treq.Spec.BoundObjectRef.UID = pod.UID
|
||||
warningHandler.clear()
|
||||
if _, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
if _, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
// wrong uid
|
||||
treq.Spec.BoundObjectRef.UID = wrongUID
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token bound to pod with wrong uid but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
// no uid
|
||||
treq.Spec.BoundObjectRef.UID = noUID
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -333,7 +331,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token for nonexistant svcacct but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -341,7 +339,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
defer del()
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token bound to nonexistant pod but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -357,21 +355,21 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
// right uid
|
||||
treq.Spec.BoundObjectRef.UID = pod.UID
|
||||
warningHandler.clear()
|
||||
if _, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
if _, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
// wrong uid
|
||||
treq.Spec.BoundObjectRef.UID = wrongUID
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token bound to pod with wrong uid but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
// no uid
|
||||
treq.Spec.BoundObjectRef.UID = noUID
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -437,7 +435,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token with featuregate disabled but got: %#v", resp)
|
||||
} else if err.Error() != "cannot bind token to a Node object as the \"ServiceAccountTokenNodeBinding\" feature-gate is disabled" {
|
||||
t.Fatalf("expected error due to feature gate being disabled, but got: %s", err.Error())
|
||||
@@ -459,7 +457,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token for nonexistant svcacct but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -467,7 +465,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
defer del()
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token bound to nonexistant node but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -477,21 +475,21 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
// right uid
|
||||
treq.Spec.BoundObjectRef.UID = node.UID
|
||||
warningHandler.clear()
|
||||
if _, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
if _, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
// wrong uid
|
||||
treq.Spec.BoundObjectRef.UID = wrongUID
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token bound to node with wrong uid but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
// no uid
|
||||
treq.Spec.BoundObjectRef.UID = noUID
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -523,7 +521,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token for nonexistant svcacct but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -531,7 +529,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
defer del()
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token bound to nonexistant secret but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -541,21 +539,21 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
// right uid
|
||||
treq.Spec.BoundObjectRef.UID = secret.UID
|
||||
warningHandler.clear()
|
||||
if _, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
if _, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
// wrong uid
|
||||
treq.Spec.BoundObjectRef.UID = wrongUID
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err creating token bound to secret with wrong uid but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
// no uid
|
||||
treq.Spec.BoundObjectRef.UID = noUID
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -591,7 +589,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
defer del()
|
||||
|
||||
warningHandler.clear()
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
if resp, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err == nil {
|
||||
t.Fatalf("expected err but got: %#v", resp)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -608,7 +606,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
defer del()
|
||||
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -662,7 +660,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
treq.Spec.BoundObjectRef.UID = pod.UID
|
||||
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -718,7 +716,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
treq.Spec.BoundObjectRef.UID = pod.UID
|
||||
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -760,7 +758,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
defer del()
|
||||
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -778,7 +776,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
defer del()
|
||||
|
||||
warningHandler.clear()
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{})
|
||||
treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
@@ -808,7 +806,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
|
||||
treq.Spec.BoundObjectRef.UID = originalPod.UID
|
||||
warningHandler.clear()
|
||||
if treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
if treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -851,7 +849,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
|
||||
treq.Spec.BoundObjectRef.UID = originalSecret.UID
|
||||
warningHandler.clear()
|
||||
if treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
if treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -896,7 +894,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
|
||||
treq.Spec.BoundObjectRef.UID = originalSecret.UID
|
||||
warningHandler.clear()
|
||||
if treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
if treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
warningHandler.assertEqual(t, nil)
|
||||
@@ -942,7 +940,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
|
||||
treq.Spec.BoundObjectRef.UID = originalSecret.UID
|
||||
warningHandler.clear()
|
||||
if treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
if treq, err = cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name, treq, metav1.CreateOptions{}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
warningHandler.assertEqual(t, []string{fmt.Sprintf("requested expiration of %d seconds shortened to %d seconds", tooLongExpirationTime, maxExpirationSeconds)})
|
||||
@@ -971,7 +969,7 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
|
||||
t.Log("get token")
|
||||
warningHandler.clear()
|
||||
tokenRequest, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(ctx, sa.Name,
|
||||
tokenRequest, err := cs.CoreV1().ServiceAccounts(sa.Namespace).CreateToken(tCtx, sa.Name,
|
||||
&authenticationv1.TokenRequest{
|
||||
Spec: authenticationv1.TokenRequestSpec{
|
||||
Audiences: []string{"api"},
|
||||
|
||||
Reference in New Issue
Block a user