-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtls.libsonnet
195 lines (188 loc) · 5.02 KB
/
tls.libsonnet
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
local cm = import 'lib/cert-manager.libsonnet';
local com = import 'lib/commodore.libjsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local inv = kap.inventory();
local params = inv.parameters.openshift4_console;
local isTlsSecret(secret) =
local secretKeys = std.set(std.objectFields(secret.stringData));
local keyDiff = std.setDiff(secretKeys, std.set([
'ca.crt',
'tls.crt',
'tls.key',
]));
secret.type == 'kubernetes.io/tls' && std.length(keyDiff) == 0;
local secrets = std.filter(
function(it) it != null,
[
local scontent = params.secrets[s];
local secret = kube.Secret(s) {
type: 'kubernetes.io/tls',
metadata+: {
// Secrets must be deployed in namespace openshift-config
namespace: 'openshift-config',
},
} + com.makeMergeable(scontent);
if scontent != null then
if isTlsSecret(secret) then
secret
else
error "Invalid secret definition for key '%s'. This component expects secret definitions which are valid for kubernetes.io/tls secrets." % s
for s in std.objectFields(params.secrets)
]
);
local makeCert(c, cert) =
local sa = kube.ServiceAccount('openshift4-console-sync-' + c) {
metadata+: {
namespace: params.namespace,
},
};
local sourceNsRole = kube.Role('openshift4-console-sync-' + c) {
metadata+: {
namespace: params.namespace,
},
rules: [
{
apiGroups: [ '' ],
resources: [ 'secrets' ],
verbs: [ 'get', 'list', 'watch' ],
},
],
};
local targetNsRole = kube.Role('openshift4-console-sync-' + c) {
metadata+: {
namespace: 'openshift-config',
},
rules: [
{
apiGroups: [ '' ],
resources: [ 'secrets' ],
verbs: [ 'get', 'update', 'patch' ],
},
],
};
[
cm.cert(c) {
metadata+: {
// Certificate must be deployed in the same namespace as the web
// console, otherwise OpenShift won't admit the HTTP01 solver route.
// We copy the resulting secret to namespace 'openshift-config', see below.
namespace: params.namespace,
},
spec+: {
secretName: '%s' % c,
},
} + com.makeMergeable(cert),
kube.ConfigMap('openshift4-console-sync-' + c) {
metadata+: {
namespace: params.namespace,
},
data: {
'reconcile-console-secret.sh': (importstr 'scripts/reconcile-console-secret.sh'),
},
},
sa,
sourceNsRole,
targetNsRole,
kube.RoleBinding('openshift4-console-sync-' + c) {
metadata+: {
namespace: sourceNsRole.metadata.namespace,
},
subjects_: [ sa ],
roleRef_: sourceNsRole,
},
kube.RoleBinding('openshift4-console-sync-' + c) {
metadata+: {
namespace: targetNsRole.metadata.namespace,
},
subjects_: [ sa ],
roleRef_: targetNsRole,
},
kube.Deployment('openshift4-console-sync-' + c) {
metadata+: {
namespace: params.namespace,
},
strategy: {
type: 'Recreate',
},
spec+: {
replicas: 1,
selector: {
matchLabels: {
app: 'openshift4-console-sync-' + c,
},
},
template+: {
metadata: {
labels: {
app: 'openshift4-console-sync-' + c,
},
},
spec+: {
serviceAccountName: 'openshift4-console-sync-' + c,
containers: [
{
name: 'sync',
image: '%(registry)s/%(repository)s:%(tag)s' % params.images.oc,
workingDir: '/export',
env: [
{
name: 'SECRET_NAME',
value: c,
},
{
name: 'HOME',
value: '/export',
},
],
command: [
'/scripts/reconcile-console-secret.sh',
],
volumeMounts: [
{
name: 'export',
mountPath: '/export',
},
{
name: 'scripts',
mountPath: '/scripts',
},
],
},
],
volumes: [
{
name: 'scripts',
configMap: {
name: 'openshift4-console-sync-' + c,
defaultMode: 365, // 365 = 0555
},
},
{
name: 'export',
emptyDir: {},
},
],
},
},
},
},
];
local certs =
std.foldl(
function(arr, e) arr + e,
std.filter(
function(it) it != null,
[
local cert = params.cert_manager_certs[c];
if cert != null then
makeCert(c, cert)
for c in std.objectFields(params.cert_manager_certs)
],
),
[]
);
{
certs: certs,
secrets: secrets,
}