k8s/io/kubernetes/pkg/api.ServiceAccount 示例代码

2022-03-03

以下示例是关于golang中包含api.ServiceAccount用法的示例代码,想了解api.ServiceAccount的具体用法?api.ServiceAccount怎么用?api.ServiceAccount使用的例子?那么可以参考以下10个相关示例代码来学习它的具体使用方法。

示例1:
admission.go开发语言: Go项目名称: abhgupta代码行数: 492
244
245func shouldAutomount(sa *api.ServiceAccount, pod *api.Pod) bool {
246	// Pod's preference wins
259// A global setting of true will override any flag set on the individual service account
260func (s *serviceAccount) enforceMountableSecrets(serviceAccount *api.ServiceAccount) bool {
261	if s.LimitSecretReferences {
273// getServiceAccount returns the ServiceAccount for the given namespace and name if it exists
274func (s *serviceAccount) getServiceAccount(namespace string, name string) (*api.ServiceAccount, error) {
275	serviceAccount, err := s.serviceAccountLister.ServiceAccounts(namespace).Get(name)
306// getReferencedServiceAccountToken returns the name of the first referenced secret which is a ServiceAccountToken for the service account
307func (s *serviceAccount) getReferencedServiceAccountToken(serviceAccount *api.ServiceAccount) (string, error) {
308	if len(serviceAccount.Secrets) == 0 {
331// getServiceAccountTokens returns all ServiceAccountToken secrets for the given ServiceAccount
332func (s *serviceAccount) getServiceAccountTokens(serviceAccount *api.ServiceAccount) ([]*api.Secret, error) {
333	secrets, err := s.secretLister.Secrets(serviceAccount.Namespace).List(labels.Everything())
示例2:
tokens_controller.go开发语言: Go项目名称: amygdala代码行数: 522
80		},
81		&api.ServiceAccount{},
82		options.ServiceAccountResync,
176func (e *TokensController) serviceAccountDeleted(obj interface{}) {
177	serviceAccount, ok := obj.(*api.ServiceAccount)
178	if !ok {
207			secret.Namespace, secret.Name,
208			secret.Annotations[api.ServiceAccountNameKey], secret.Annotations[api.ServiceAccountUIDKey])
209		if err := e.deleteSecret(secret); err != nil {
228			newSecret.Namespace, newSecret.Name,
229			newSecret.Annotations[api.ServiceAccountNameKey], newSecret.Annotations[api.ServiceAccountUIDKey])
230		if err := e.deleteSecret(newSecret); err != nil {
512	}
513	return secret.Annotations[api.ServiceAccountNameKey], secret.Annotations[api.ServiceAccountUIDKey]
514}
示例3:
tokens_controller_test.go开发语言: Go项目名称: amygdala代码行数: 561
30type testGenerator struct {
31	GeneratedServiceAccounts []api.ServiceAccount
32	GeneratedSecrets         []api.Secret
36
37func (t *testGenerator) GenerateToken(serviceAccount api.ServiceAccount, secret api.Secret) (string, error) {
38	t.GeneratedSecrets = append(t.GeneratedSecrets, secret)
68// serviceAccount returns a service account with the given secret refs
69func serviceAccount(secretRefs []api.ObjectReference) *api.ServiceAccount {
70	return &api.ServiceAccount{
81// updatedServiceAccount returns a service account with the resource version modified
82func updatedServiceAccount(secretRefs []api.ObjectReference) *api.ServiceAccount {
83	sa := serviceAccount(secretRefs)
111			Annotations: map[string]string{
112				api.ServiceAccountNameKey: "default",
113				api.ServiceAccountUIDKey:  "12345",
示例4:
admission.go开发语言: Go项目名称: amygdala代码行数: 415
99		},
100		&api.ServiceAccount{},
101		0,
215// A global setting of true will override any flag set on the individual service account
216func (s *serviceAccount) enforceMountableSecrets(serviceAccount *api.ServiceAccount) bool {
217	if s.LimitSecretReferences {
229// getServiceAccount returns the ServiceAccount for the given namespace and name if it exists
230func (s *serviceAccount) getServiceAccount(namespace string, name string) (*api.ServiceAccount, error) {
231	key := &api.ServiceAccount{ObjectMeta: api.ObjectMeta{Namespace: namespace}}
237	for _, obj := range index {
238		serviceAccount := obj.(*api.ServiceAccount)
239		if serviceAccount.Name == name {
267// getReferencedServiceAccountToken returns the name of the first referenced secret which is a ServiceAccountToken for the service account
268func (s *serviceAccount) getReferencedServiceAccountToken(serviceAccount *api.ServiceAccount) (string, error) {
269	if len(serviceAccount.Secrets) == 0 {
示例5:
serviceaccount.go开发语言: Go项目名称: amygdala代码行数: 135
31type ServiceAccountInterface interface {
32	Create(*api.ServiceAccount) (*api.ServiceAccount, error)
33	Update(*api.ServiceAccount) (*api.ServiceAccount, error)
35	DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error
36	Get(name string) (*api.ServiceAccount, error)
37	List(opts api.ListOptions) (*api.ServiceAccountList, error)
56// Create takes the representation of a serviceAccount and creates it.  Returns the server's representation of the serviceAccount, and an error, if there is any.
57func (c *serviceAccounts) Create(serviceAccount *api.ServiceAccount) (result *api.ServiceAccount, err error) {
58	result = &api.ServiceAccount{}
68// Update takes the representation of a serviceAccount and updates it. Returns the server's representation of the serviceAccount, and an error, if there is any.
69func (c *serviceAccounts) Update(serviceAccount *api.ServiceAccount) (result *api.ServiceAccount, err error) {
70	result = &api.ServiceAccount{}
103// Get takes name of the serviceAccount, and returns the corresponding serviceAccount object, and an error if there is any.
104func (c *serviceAccounts) Get(name string) (result *api.ServiceAccount, err error) {
105	result = &api.ServiceAccount{}
示例6:
serviceaccounts_controller.go开发语言: Go项目名称: amygdala代码行数: 256
46	// ServiceAccounts is the list of service accounts to ensure exist in every namespace
47	ServiceAccounts []api.ServiceAccount
48
61	return ServiceAccountsControllerOptions{
62		ServiceAccounts: []api.ServiceAccount{
63			{ObjectMeta: api.ObjectMeta{Name: "default"}},
90		},
91		&api.ServiceAccount{},
92		options.ServiceAccountResync,
124	client                  clientset.Interface
125	serviceAccountsToEnsure []api.ServiceAccount
126
153func (e *ServiceAccountsController) serviceAccountDeleted(obj interface{}) {
154	serviceAccount, ok := obj.(*api.ServiceAccount)
155	if !ok {
示例7:
serviceaccounts_controller_test.go开发语言: Go项目名称: amygdala代码行数: 197
50	}
51	defaultServiceAccount := &api.ServiceAccount{
52		ObjectMeta: api.ObjectMeta{
57	}
58	managedServiceAccount := &api.ServiceAccount{
59		ObjectMeta: api.ObjectMeta{
64	}
65	unmanagedServiceAccount := &api.ServiceAccount{
66		ObjectMeta: api.ObjectMeta{
74		ExistingNamespace       *api.Namespace
75		ExistingServiceAccounts []*api.ServiceAccount
76
78		UpdatedNamespace      *api.Namespace
79		DeletedServiceAccount *api.ServiceAccount
80
示例8:
admission_test.go开发语言: Go项目名称: abhgupta代码行数: 966
150	// Add the default service account for the ns into the cache
151	informerFactory.Core().InternalVersion().ServiceAccounts().Informer().GetStore().Add(&api.ServiceAccount{
152		ObjectMeta: metav1.ObjectMeta{
178	// Add the default service account for the ns into the cache
179	informerFactory.Core().InternalVersion().ServiceAccounts().Informer().GetStore().Add(&api.ServiceAccount{
180		ObjectMeta: metav1.ObjectMeta{
197	// Build a test client that the admission plugin can use to look up the service account missing from its cache
198	client := fake.NewSimpleClientset(&api.ServiceAccount{
199		ObjectMeta: metav1.ObjectMeta{
265	// Add the default service account for the ns with a token into the cache
266	informerFactory.Core().InternalVersion().ServiceAccounts().Informer().GetStore().Add(&api.ServiceAccount{
267		ObjectMeta: metav1.ObjectMeta{
281			Annotations: map[string]string{
282				api.ServiceAccountNameKey: serviceAccountName,
283				api.ServiceAccountUIDKey:  serviceAccountUID,
示例9:
service_accounts.go开发语言: Go项目名称: amygdala代码行数: 120
28type ServiceAccountsInterface interface {
29	Create(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error)
30	Update(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error)
31	Delete(name string) error
32	List(opts api.ListOptions) (*api.ServiceAccountList, error)
33	Get(name string) (*api.ServiceAccount, error)
50
51func (s *serviceAccounts) Create(serviceAccount *api.ServiceAccount) (*api.ServiceAccount, error) {
52	result := &api.ServiceAccount{}
63// List returns a list of serviceAccounts matching the selectors.
64func (s *serviceAccounts) List(opts api.ListOptions) (*api.ServiceAccountList, error) {
65	result := &api.ServiceAccountList{}
108
109func (s *serviceAccounts) Update(serviceAccount *api.ServiceAccount) (result *api.ServiceAccount, err error) {
110	result = &api.ServiceAccount{}
示例10:
service_account_test.go开发语言: Go项目名称: amygdala代码行数: 566
112	// Create service account
113	serviceAccount, err := c.Core().ServiceAccounts(ns).Create(&api.ServiceAccount{ObjectMeta: api.ObjectMeta{Name: name}})
114	if err != nil {
290	// Create "ro" user in myns
291	_, err = c.Core().ServiceAccounts(myns).Create(&api.ServiceAccount{ObjectMeta: api.ObjectMeta{Name: readOnlyServiceAccountName}})
292	if err != nil {
310	// Create "rw" user in myns
311	_, err = c.Core().ServiceAccounts(myns).Create(&api.ServiceAccount{ObjectMeta: api.ObjectMeta{Name: readWriteServiceAccountName}})
312	if err != nil {
435
436func getServiceAccount(c *clientset.Clientset, ns string, name string, shouldWait bool) (*api.ServiceAccount, error) {
437	if !shouldWait {
440
441	var user *api.ServiceAccount
442	var err error

本文地址:https://www.itbaoku.cn/snippets/415680.html