From 38ddb4413a82ec8bf3a0c560212887411bf04d7e Mon Sep 17 00:00:00 2001 From: "zuoxiu.jm" <291271447@qq.com> Date: Wed, 24 Oct 2018 14:38:42 +0800 Subject: [PATCH] update token authn constructor --- cmd/kube-apiserver/app/server.go | 6 +++--- test/integration/auth/bootstraptoken_test.go | 22 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/kube-apiserver/app/server.go b/cmd/kube-apiserver/app/server.go index 8eec41ba560..f7879f29a0f 100644 --- a/cmd/kube-apiserver/app/server.go +++ b/cmd/kube-apiserver/app/server.go @@ -524,7 +524,7 @@ func buildGenericConfig( } serviceResolver = aggregatorapiserver.NewLoopbackServiceResolver(serviceResolver, localHost) - genericConfig.Authentication.Authenticator, genericConfig.OpenAPIConfig.SecurityDefinitions, err = BuildAuthenticator(s, clientgoExternalClient, sharedInformers) + genericConfig.Authentication.Authenticator, genericConfig.OpenAPIConfig.SecurityDefinitions, err = BuildAuthenticator(s, clientgoExternalClient, versionedInformers) if err != nil { lastErr = fmt.Errorf("invalid authentication config: %v", err) return @@ -625,13 +625,13 @@ func BuildAdmissionPluginInitializers( } // BuildAuthenticator constructs the authenticator -func BuildAuthenticator(s *options.ServerRunOptions, extclient clientgoclientset.Interface, sharedInformers informers.SharedInformerFactory) (authenticator.Request, *spec.SecurityDefinitions, error) { +func BuildAuthenticator(s *options.ServerRunOptions, extclient clientgoclientset.Interface, versionedInformer clientgoinformers.SharedInformerFactory) (authenticator.Request, *spec.SecurityDefinitions, error) { authenticatorConfig := s.Authentication.ToAuthenticationConfig() if s.Authentication.ServiceAccounts.Lookup { authenticatorConfig.ServiceAccountTokenGetter = serviceaccountcontroller.NewGetterFromClient(extclient) } authenticatorConfig.BootstrapTokenAuthenticator = bootstrap.NewTokenAuthenticator( - sharedInformers.Core().InternalVersion().Secrets().Lister().Secrets(v1.NamespaceSystem), + versionedInformer.Core().V1().Secrets().Lister().Secrets(v1.NamespaceSystem), ) return authenticatorConfig.New() diff --git a/test/integration/auth/bootstraptoken_test.go b/test/integration/auth/bootstraptoken_test.go index aeeb72bd81d..89f2a9d46d6 100644 --- a/test/integration/auth/bootstraptoken_test.go +++ b/test/integration/auth/bootstraptoken_test.go @@ -24,24 +24,24 @@ import ( "testing" "time" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apiserver/pkg/authentication/request/bearertoken" bootstrapapi "k8s.io/cluster-bootstrap/token/api" - api "k8s.io/kubernetes/pkg/apis/core" "k8s.io/kubernetes/plugin/pkg/auth/authenticator/token/bootstrap" bootstraputil "k8s.io/kubernetes/test/e2e/lifecycle/bootstrap" "k8s.io/kubernetes/test/integration" "k8s.io/kubernetes/test/integration/framework" ) -type bootstrapSecrets []*api.Secret +type bootstrapSecrets []*corev1.Secret -func (b bootstrapSecrets) List(selector labels.Selector) (ret []*api.Secret, err error) { +func (b bootstrapSecrets) List(selector labels.Selector) (ret []*corev1.Secret, err error) { return b, nil } -func (b bootstrapSecrets) Get(name string) (*api.Secret, error) { +func (b bootstrapSecrets) Get(name string) (*corev1.Secret, error) { return b[0], nil } @@ -55,36 +55,36 @@ func TestBootstrapTokenAuth(t *testing.T) { if err != nil { t.Fatalf("unexpected error: %v", err) } - var bootstrapSecretValid = &api.Secret{ + var bootstrapSecretValid = &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: metav1.NamespaceSystem, Name: bootstrapapi.BootstrapTokenSecretPrefix, }, - Type: api.SecretTypeBootstrapToken, + Type: corev1.SecretTypeBootstrapToken, Data: map[string][]byte{ bootstrapapi.BootstrapTokenIDKey: []byte(tokenId), bootstrapapi.BootstrapTokenSecretKey: []byte(secret), bootstrapapi.BootstrapTokenUsageAuthentication: []byte("true"), }, } - var bootstrapSecretInvalid = &api.Secret{ + var bootstrapSecretInvalid = &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: metav1.NamespaceSystem, Name: bootstrapapi.BootstrapTokenSecretPrefix, }, - Type: api.SecretTypeBootstrapToken, + Type: corev1.SecretTypeBootstrapToken, Data: map[string][]byte{ bootstrapapi.BootstrapTokenIDKey: []byte(tokenId), bootstrapapi.BootstrapTokenSecretKey: []byte("invalid"), bootstrapapi.BootstrapTokenUsageAuthentication: []byte("true"), }, } - var expiredBootstrapToken = &api.Secret{ + var expiredBootstrapToken = &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: metav1.NamespaceSystem, Name: bootstrapapi.BootstrapTokenSecretPrefix, }, - Type: api.SecretTypeBootstrapToken, + Type: corev1.SecretTypeBootstrapToken, Data: map[string][]byte{ bootstrapapi.BootstrapTokenIDKey: []byte(tokenId), bootstrapapi.BootstrapTokenSecretKey: []byte("invalid"), @@ -101,7 +101,7 @@ func TestBootstrapTokenAuth(t *testing.T) { tests := []struct { name string request request - secret *api.Secret + secret *corev1.Secret }{ { name: "valid token",