add support for /token subresource in serviceaccount registry

Kubernetes-commit: 8ad1c6655bde4ca8d61c3574980cffce5ee937a5
This commit is contained in:
Mike Danese 2018-02-05 20:53:25 -08:00 committed by Kubernetes Publisher
parent f09bc8b437
commit d5f7182e00
5 changed files with 76 additions and 2 deletions

View File

@ -32,9 +32,11 @@ go_library(
"service.go",
"service_expansion.go",
"serviceaccount.go",
"serviceaccount_expansion.go",
],
importpath = "k8s.io/client-go/kubernetes/typed/core/v1",
deps = [
"//vendor/k8s.io/api/authentication/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/api/policy/v1beta1:go_default_library",

View File

@ -31,9 +31,11 @@ go_library(
"fake_service.go",
"fake_service_expansion.go",
"fake_serviceaccount.go",
"fake_serviceaccount_expansion.go",
],
importpath = "k8s.io/client-go/kubernetes/typed/core/v1/fake",
deps = [
"//vendor/k8s.io/api/authentication/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/api/policy/v1beta1:go_default_library",

View File

@ -0,0 +1,31 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package fake
import (
authenticationv1 "k8s.io/api/authentication/v1"
core "k8s.io/client-go/testing"
)
func (c *FakeServiceAccounts) CreateToken(name string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error) {
obj, err := c.Fake.Invokes(core.NewCreateSubresourceAction(serviceaccountsResource, name, "token", c.ns, tr), &authenticationv1.TokenRequest{})
if obj == nil {
return nil, err
}
return obj.(*authenticationv1.TokenRequest), err
}

View File

@ -35,5 +35,3 @@ type ReplicationControllerExpansion interface{}
type ResourceQuotaExpansion interface{}
type SecretExpansion interface{}
type ServiceAccountExpansion interface{}

View File

@ -0,0 +1,41 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1
import (
authenticationv1 "k8s.io/api/authentication/v1"
)
// The ServiceAccountExpansion interface allows manually adding extra methods
// to the ServiceAccountInterface.
type ServiceAccountExpansion interface {
CreateToken(name string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error)
}
// CreateToken creates a new token for a serviceaccount.
func (c *serviceAccounts) CreateToken(name string, tr *authenticationv1.TokenRequest) (*authenticationv1.TokenRequest, error) {
result := &authenticationv1.TokenRequest{}
err := c.client.Post().
Namespace(c.ns).
Resource("serviceaccounts").
SubResource("token").
Name(name).
Body(tr).
Do().
Into(result)
return result, err
}