Skip to content
This repository was archived by the owner on Sep 24, 2021. It is now read-only.

Commit 0a418a5

Browse files
committed
Struct-ize some YAML
1 parent da3b509 commit 0a418a5

File tree

3 files changed

+219
-0
lines changed

3 files changed

+219
-0
lines changed

objects/all.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package objects
2+
3+
import "k8s.io/apimachinery/pkg/runtime"
4+
5+
func GetAll(capdImage string) []runtime.Object {
6+
statefulSet := GetStatefulSet(capdImage)
7+
8+
return []runtime.Object{
9+
&Namespace,
10+
&statefulSet,
11+
&ClusterRole,
12+
&ClusterRoleBinding,
13+
}
14+
}

objects/control_plane.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package objects
2+
3+
import (
4+
apps "k8s.io/api/apps/v1"
5+
core "k8s.io/api/core/v1"
6+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
9+
)
10+
11+
const namespace = "docker-provider-system"
12+
13+
var Namespace = core.Namespace{
14+
ObjectMeta: meta.ObjectMeta{
15+
Labels: map[string]string{"controller-tools.k8s.io": "1.0"},
16+
Name: namespace,
17+
},
18+
}
19+
20+
var (
21+
controlPlaneLabel = map[string]string{"control-plane": "controller-manager"}
22+
hostPathSocket = core.HostPathSocket
23+
hostPathDirectory = core.HostPathDirectory
24+
)
25+
26+
const (
27+
dockerSockVolumeName = "dockersock"
28+
dockerSockPath = "/var/run/docker.sock"
29+
dockerLibVolumeName = "dockerlib"
30+
dockerLibPath = "/var/lib/docker"
31+
)
32+
33+
func GetStatefulSet(image string) apps.StatefulSet {
34+
return apps.StatefulSet{
35+
ObjectMeta: meta.ObjectMeta{
36+
Labels: controlPlaneLabel,
37+
Name: "docker-provider-controller-manager",
38+
Namespace: namespace,
39+
},
40+
Spec: apps.StatefulSetSpec{
41+
Selector: &v1.LabelSelector{
42+
MatchLabels: controlPlaneLabel,
43+
},
44+
ServiceName: "docker-provider-controller-manager-service",
45+
Template: core.PodTemplateSpec{
46+
ObjectMeta: meta.ObjectMeta{
47+
Labels: controlPlaneLabel,
48+
},
49+
Spec: core.PodSpec{
50+
Containers: []core.Container{
51+
{
52+
Name: "capd-manager",
53+
Image: image,
54+
Command: []string{
55+
"capd-manager",
56+
},
57+
VolumeMounts: []core.VolumeMount{
58+
{
59+
MountPath: dockerSockPath,
60+
Name: dockerSockVolumeName,
61+
},
62+
{
63+
MountPath: dockerLibPath,
64+
Name: dockerLibVolumeName,
65+
},
66+
},
67+
},
68+
},
69+
Volumes: []core.Volume{
70+
{
71+
Name: dockerSockVolumeName,
72+
VolumeSource: core.VolumeSource{
73+
HostPath: &core.HostPathVolumeSource{
74+
Path: dockerSockPath,
75+
Type: &hostPathSocket,
76+
},
77+
},
78+
},
79+
{
80+
Name: dockerLibVolumeName,
81+
VolumeSource: core.VolumeSource{
82+
HostPath: &core.HostPathVolumeSource{
83+
Path: dockerLibPath,
84+
Type: &hostPathDirectory,
85+
},
86+
},
87+
},
88+
},
89+
Tolerations: []core.Toleration{
90+
{
91+
Key: constants.LabelNodeRoleMaster,
92+
Effect: core.TaintEffectNoExecute,
93+
},
94+
{
95+
Key: "CriticalAddonsOnly",
96+
Operator: core.TolerationOpExists,
97+
},
98+
{
99+
Key: "node.alpha.kubernetes.io/notReady",
100+
Operator: core.TolerationOpExists,
101+
Effect: core.TaintEffectNoExecute,
102+
},
103+
{
104+
Key: "node.alpha.kubernetes.io/unreachable",
105+
Operator: core.TolerationOpExists,
106+
Effect: core.TaintEffectNoExecute,
107+
},
108+
},
109+
},
110+
},
111+
},
112+
}
113+
}

objects/rbac.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package objects
2+
3+
import (
4+
core "k8s.io/api/core/v1"
5+
rbac "k8s.io/api/rbac/v1"
6+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
capi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
8+
)
9+
10+
var ClusterRole = rbac.ClusterRole{
11+
ObjectMeta: meta.ObjectMeta{
12+
Name: "docker-provider-manager-role",
13+
},
14+
Rules: []rbac.PolicyRule{
15+
{
16+
APIGroups: []string{
17+
capi.SchemeGroupVersion.Group,
18+
},
19+
Resources: []string{
20+
"clusters",
21+
"clusters/status",
22+
},
23+
Verbs: []string{
24+
"get",
25+
"list",
26+
"watch",
27+
"create",
28+
"update",
29+
"patch",
30+
"delete",
31+
},
32+
},
33+
{
34+
APIGroups: []string{
35+
capi.SchemeGroupVersion.Group,
36+
},
37+
Resources: []string{
38+
"machines",
39+
"machines/status",
40+
"machinedeployments",
41+
"machinedeployments/status",
42+
"machinesets",
43+
"machinesets/status",
44+
"machineclasses",
45+
},
46+
Verbs: []string{
47+
"get",
48+
"list",
49+
"watch",
50+
"create",
51+
"update",
52+
"patch",
53+
"delete",
54+
},
55+
},
56+
{
57+
APIGroups: []string{
58+
core.GroupName,
59+
},
60+
Resources: []string{
61+
"nodes",
62+
"events",
63+
"secrets",
64+
},
65+
Verbs: []string{
66+
"get",
67+
"list",
68+
"watch",
69+
"create",
70+
"update",
71+
"patch",
72+
"delete",
73+
},
74+
},
75+
},
76+
}
77+
78+
var ClusterRoleBinding = rbac.ClusterRoleBinding{
79+
ObjectMeta: meta.ObjectMeta{
80+
Name: "docker-provider-manager-rolebinding",
81+
},
82+
RoleRef: rbac.RoleRef{
83+
Kind: "ClusterRole",
84+
Name: ClusterRole.ObjectMeta.Name,
85+
APIGroup: rbac.GroupName,
86+
},
87+
Subjects: []rbac.Subject{{
88+
Kind: rbac.ServiceAccountKind,
89+
Name: "default",
90+
Namespace: namespace,
91+
}},
92+
}

0 commit comments

Comments
 (0)