-
Notifications
You must be signed in to change notification settings - Fork 2
/
rbac.go
59 lines (53 loc) · 1.48 KB
/
rbac.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2023 Volvo Car Corporation
// SPDX-License-Identifier: Apache-2.0
package kubeutil
import (
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// SimpleSA creates a simple ServiceAccount with the given name and namespace.
func SimpleSA(name, namespace string) *corev1.ServiceAccount {
return &corev1.ServiceAccount{
TypeMeta: TypeServiceAccountV1,
ObjectMeta: ObjectMeta(name, namespace, nil, nil),
}
}
// ServiceAccount creates a ServiceAccount with the given name, namespace, labels and annotations.
func ServiceAccount(
name, namespace string,
labels, annotations map[string]string,
) *corev1.ServiceAccount {
return &corev1.ServiceAccount{
TypeMeta: TypeServiceAccountV1,
ObjectMeta: ObjectMeta(name, namespace, labels, annotations),
}
}
// Role creates a Role with the given name, namespace, labels and rules.
func Role(
name, namespace string,
labels map[string]string,
rules []rbacv1.PolicyRule,
) *rbacv1.Role {
return &rbacv1.Role{
TypeMeta: TypeRoleV1,
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: labels,
},
Rules: rules,
}
}
// ClusterRole creates a ClusterRole with the given name, labels and rules.
func ClusterRole(
name string,
labels map[string]string,
rules []rbacv1.PolicyRule,
) *rbacv1.ClusterRole {
return &rbacv1.ClusterRole{
TypeMeta: TypeClusterRoleV1,
ObjectMeta: ObjectMeta(name, "", labels, nil),
Rules: rules,
}
}