-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathsa.go
37 lines (28 loc) · 1.27 KB
/
sa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package k8s
import (
"context"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// GetAllServiceAccounts returns a list of services accounts for all namespaces.
func GetAllServiceAccounts() (*corev1.ServiceAccountList, error) {
return GetServiceAccounts(corev1.NamespaceAll)
}
// GetServiceAccounts returns a list of service accounts in a given namespace
func GetServiceAccounts(namespace string) (*corev1.ServiceAccountList, error) {
clientset := getClientset()
metaOptions := metav1.ListOptions{}
return clientset.CoreV1().ServiceAccounts(namespace).List(context.TODO(), metaOptions)
}
// GetServiceAccount reutrns a single service account by namespace and name.
func GetServiceAccount(namespace, name string) (*corev1.ServiceAccount, error) {
clientset := getClientset()
metaOptions := metav1.GetOptions{}
return clientset.CoreV1().ServiceAccounts(namespace).Get(context.TODO(), name, metaOptions)
}
// SaveServiceAccount updates the given service account in the cluster
func SaveServiceAccount(svcAccount *corev1.ServiceAccount) (*corev1.ServiceAccount, error) {
clientset := getClientset()
metaOptions := metav1.UpdateOptions{}
return clientset.CoreV1().ServiceAccounts(svcAccount.Namespace).Update(context.TODO(), svcAccount, metaOptions)
}