-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.jsonnet
More file actions
151 lines (143 loc) · 4.32 KB
/
main.jsonnet
File metadata and controls
151 lines (143 loc) · 4.32 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local inv = kap.inventory();
local params = inv.parameters.cloudscale_cloud_controller_manager;
local isOpenShift = std.member([ 'openshift4', 'oke' ], inv.parameters.facts.distribution);
local manifests_version =
local ccm_tag = params.images.cloudscale_cloud_controller_manager.tag;
if params.manifests_version != ccm_tag then
std.trace(
'Parameter `manifests_version` is deprecated, we recommend using ' +
'`images.cloudscale_cloud_controller_manager.tag` to configure the CCM version.',
params.manifests_version
)
else
ccm_tag;
local manifests = std.parseJson(
kap.yaml_load_stream(
'%s/manifests/%s/config.yml'
% [ inv.parameters._base_directory, manifests_version ]
)
);
local patchDaemonset(obj) =
if obj.kind == 'DaemonSet' then
obj {
spec+: {
template+: {
spec+: {
containers: [
if c.name == 'cloudscale-cloud-controller-manager' then
c {
image:
'%(registry)s/%(repository)s:%(tag)s' %
params.images.cloudscale_cloud_controller_manager,
command+: params.args,
env+:
if params.api_timeout_seconds != null then [
{
name: 'CLOUDSCALE_API_TIMEOUT',
value: std.toString(params.api_timeout_seconds),
},
] else [],
}
else
c
for c in super.containers
],
[if isOpenShift then 'nodeSelector']: {
'node-role.kubernetes.io/master': '',
},
[if isOpenShift then 'tolerations']+: [
{
key: 'node-role.kubernetes.io/master',
effect: 'NoSchedule',
},
],
},
},
},
}
else
obj;
local tokenSecret = kube.Secret('cloudscale') {
metadata+: {
namespace: params.namespace,
},
data:: {},
stringData: {
'access-token': params.api_token,
},
};
local customRBAC = if isOpenShift then
[
kube.RoleBinding('ccm-hostnetwork') {
metadata+: {
// Required if we want to deploy this manifest during cluster
// bootstrap.
namespace: params.namespace,
},
roleRef_: kube.ClusterRole('system:openshift:scc:hostnetwork'),
subjects: [
{
kind: 'ServiceAccount',
name: std.filter(
function(obj) obj.kind == 'DaemonSet', manifests
)[0].spec.template.spec.serviceAccountName,
namespace: params.namespace,
},
],
},
]
else
[];
local objKey(prefix, obj) =
local sanitize(str) =
std.asciiLower(std.strReplace(std.strReplace(str, '-', '_'), ':', '_'));
local nsname = if std.objectHas(obj.metadata, 'namespace') then
'%s_%s' % [ sanitize(obj.metadata.namespace), sanitize(obj.metadata.name) ]
else
obj.metadata.name;
'%s_%s_%s' % [ prefix, sanitize(obj.kind), nsname ];
// NOTE(sg): We generate individual files for each object here so that we
// don't need to further process the rendered manifests to feed them to the
// OpenShift install process which requires that additional manifests are
// stored in individual files.
{
[if params.namespace != 'kube-system' then '00_namespace']:
kube.Namespace(params.namespace) {
metadata+: {
annotations+: {
// NOTE(sg): we set this unconditionally since it doesn't matter on
// non-OCP.
'openshift.io/node-selector': '',
},
},
},
'01_secret': tokenSecret,
} + {
[objKey('10_ccm', object)]: patchDaemonset(object) {
metadata+: {
namespace: params.namespace,
},
}
for object in manifests
if std.setMember(object.kind, [ 'DaemonSet', 'ServiceAccount' ])
} + {
[objKey('20_rbac', object)]:
object + if std.objectHas(object, 'subjects') then
{
subjects: [
sub {
namespace: params.namespace,
}
for sub in super.subjects
],
}
else
{}
for object in manifests
if std.setMember(object.kind, [ 'ClusterRole', 'ClusterRoleBinding' ])
} + {
[objKey('30_custom_rbac', object)]: object
for object in customRBAC
}