forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_template.go
60 lines (48 loc) · 1.95 KB
/
sample_template.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
package delegated
import (
kapi "k8s.io/kubernetes/pkg/api"
authorizationapi "github.com/openshift/origin/pkg/authorization/api"
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
projectapi "github.com/openshift/origin/pkg/project/api"
templateapi "github.com/openshift/origin/pkg/template/api"
)
const (
DefaultTemplateName = "project-request"
ProjectNameParam = "PROJECT_NAME"
ProjectDisplayNameParam = "PROJECT_DISPLAYNAME"
ProjectDescriptionParam = "PROJECT_DESCRIPTION"
ProjectAdminUserParam = "PROJECT_ADMIN_USER"
ProjectRequesterParam = "PROJECT_REQUESTING_USER"
)
var (
parameters = []string{ProjectNameParam, ProjectDisplayNameParam, ProjectDescriptionParam, ProjectAdminUserParam, ProjectRequesterParam}
)
func DefaultTemplate() *templateapi.Template {
ret := &templateapi.Template{}
ret.Name = DefaultTemplateName
ns := "${" + ProjectNameParam + "}"
project := &projectapi.Project{}
project.Name = ns
project.Annotations = map[string]string{
projectapi.ProjectDescription: "${" + ProjectDescriptionParam + "}",
projectapi.ProjectDisplayName: "${" + ProjectDisplayNameParam + "}",
projectapi.ProjectRequester: "${" + ProjectRequesterParam + "}",
}
ret.Objects = append(ret.Objects, project)
binding := &authorizationapi.RoleBinding{}
binding.Name = bootstrappolicy.AdminRoleName
binding.Namespace = ns
binding.Subjects = []kapi.ObjectReference{{Kind: authorizationapi.UserKind, Name: "${" + ProjectAdminUserParam + "}"}}
binding.RoleRef.Name = bootstrappolicy.AdminRoleName
ret.Objects = append(ret.Objects, binding)
serviceAccountRoleBindings := bootstrappolicy.GetBootstrapServiceAccountProjectRoleBindings(ns)
for i := range serviceAccountRoleBindings {
ret.Objects = append(ret.Objects, &serviceAccountRoleBindings[i])
}
for _, parameterName := range parameters {
parameter := templateapi.Parameter{}
parameter.Name = parameterName
ret.Parameters = append(ret.Parameters, parameter)
}
return ret
}