This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
data.go
111 lines (108 loc) · 2.71 KB
/
data.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package controller
import (
"context"
apiv1 "github.com/acorn-io/runtime/pkg/apis/api.acorn.io/v1"
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/config"
"github.com/acorn-io/runtime/pkg/system"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (c *Controller) initData(ctx context.Context) error {
err := c.apply.Ensure(ctx, &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: system.Namespace,
},
}, &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: system.ImagesNamespace,
},
}, &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: "acorn:system:builder",
},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
APIGroups: []string{""},
Resources: []string{"configmaps"},
ResourceNames: []string{"acorn-config"},
},
{
Verbs: []string{"list"},
APIGroups: []string{""},
Resources: []string{"nodes"},
},
{
Verbs: []string{"get", "list"},
APIGroups: []string{""},
Resources: []string{"secrets", "namespaces"},
},
{
Verbs: []string{"get"},
APIGroups: []string{""},
Resources: []string{"services"},
},
{
Verbs: []string{"get", "create", "patch", "update"},
APIGroups: []string{v1.SchemeGroupVersion.Group},
Resources: []string{"imageinstances"},
},
{
Verbs: []string{"get", "list", "watch"},
APIGroups: []string{v1.SchemeGroupVersion.Group},
Resources: []string{"acornimagebuildinstances"},
},
{
Verbs: []string{"update"},
APIGroups: []string{v1.SchemeGroupVersion.Group},
Resources: []string{"acornimagebuildinstances/status"},
},
{
Verbs: []string{"get", "list", "watch"},
APIGroups: []string{apiv1.SchemeGroupVersion.Group},
Resources: []string{"images"},
},
},
}, &rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "acorn:system:builder",
},
Subjects: []rbacv1.Subject{
{
Kind: "ServiceAccount",
Name: "acorn-builder",
Namespace: system.ImagesNamespace,
},
},
RoleRef: rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Name: "acorn:system:builder",
Kind: "ClusterRole",
},
}, &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "acorn-builder",
Namespace: system.ImagesNamespace,
},
}, &v1.ProjectInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "acorn",
},
})
if err != nil {
return err
}
if system.IsLocal() {
err = c.apply.Ensure(ctx, &v1.ProjectInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "local",
},
})
if err != nil {
return err
}
}
return config.Init(ctx, c.client)
}