blob: 9e24975a0745955fa5b0fcc605ebc605bb29a7e2 [file] [log] [blame]
Radek Pietruszewskif5844312023-10-27 22:41:18 +02001local kube = import "../../../kube/hscloud.libsonnet";
Serge Bazanski1572e522020-12-03 23:19:28 +01002
3{
4 local wow = self,
5 local cfg = wow.cfg,
6 local ns = wow.ns,
7 cfg:: {
8 namespace: error "namespace must be set",
9 prefix: "",
10 images: {
11 acore: "registry.k0.hswaw.net/q3k/azerothcore-wowtlk:1606950998",
Serge Bazanski7ea8e472020-12-04 10:48:37 +010012 panel: "registry.k0.hswaw.net/q3k/panel:1607075221-54d0e977e57cc2c8d949c3a7ecf2ff21abd9d143",
Serge Bazanski1572e522020-12-03 23:19:28 +010013 },
14 db: {
15 local mkConfig = function(name) {
16 host: error ("db.%s.host must be set" % [name]),
17 port: error ("db.%s.prt must be set" % [name]),
18 user: error ("db.%s.user must be set" % [name]),
19 password: error ("db.%s.password must be set" % [name]),
20 database: "acore_%s" % [name],
21 },
22 auth: mkConfig("auth"),
23 world: mkConfig("world"),
24 characters: mkConfig("characters"),
25 },
26 panel: {
27 domain: error "panel.domain must be set",
28 soap: {
29 username: error "panel.soap.username must be set",
30 password: error "panel.soap.password must be set",
31 },
32 secret: error "panel.secret must be set",
33 oauth: {
34 clientID: error "panel.oauth.clientID must set",
35 clientSecret: error "panel.oauth.clientSecret must set",
36 redirectURL: "https://%s/callback" % [cfg.panel.domain],
37 },
38 motd: "",
39 },
40 overrides: {
41 authserver: {},
42 worldserver: {},
43 ahbot: {},
44 },
45 },
46
47 ns: kube.Namespace(cfg.namespace),
48
49 data: ns.Contain(kube.PersistentVolumeClaim(cfg.prefix + "data")) {
Radek Pietruszewskif28cd622023-11-03 17:30:10 +010050 storage: "50Gi",
51 storageClass: "waw-hdd-redundant-3",
Serge Bazanski1572e522020-12-03 23:19:28 +010052 },
53
54 // Make a *DatabaseInfo string for use by acore config. These are not any real
55 // standardized DSN format, just some semicolon-delimited proprietary format.
56 local mkDbString = function(config) (
57 "%s;%d;%s;%s;%s" % [
58 config.host,
59 config.port,
60 config.user,
61 config.password,
62 config.database,
63 ]
64 ),
65
66 etc: ns.Contain(kube.Secret(cfg.prefix + "etc")) {
67 data: {
68 "worldserver.conf": std.base64(std.manifestIni({
69 sections: {
70 worldserver: {
71 RealmID: 1,
72 DataDir: "/data/current",
73 LoginDatabaseInfo: mkDbString(cfg.db.auth),
74 WorldDatabaseInfo: mkDbString(cfg.db.world),
75 CharacterDatabaseInfo: mkDbString(cfg.db.characters),
76 LogLevel: 2,
77
78 "Console.Enable": 0,
79 "Ra.Enable": 1,
80 "Ra.IP": "127.0.0.1",
81 "SOAP.Enabled": 1,
82 "SOAP.IP": "0.0.0.0",
83
84 } + cfg.overrides.worldserver,
85
86 },
87 })),
88 "mod_ahbot.conf": std.base64(std.manifestIni({
89 sections: {
90 worldserver: cfg.overrides.ahbot,
91 },
92 })),
93 "authserver.conf": std.base64(std.manifestIni({
94 sections: {
95 authserver: {
96 LoginDatabaseInfo: mkDbString(cfg.db.auth),
97 } + cfg.overrides.authserver,
98 },
99 })),
100 },
101 },
102
103 worldserverDeploy: ns.Contain(kube.Deployment(cfg.prefix + "worldserver")) {
104 spec+: {
105 template+: {
106 spec+: {
107 containers_: {
108 default: kube.Container("default") {
109 image: cfg.images.acore,
110 volumeMounts: [
111 { name: "data", mountPath: "/data" },
112 { name: "etc", mountPath: "/azeroth-server/etc/worldserver.conf", subPath: "worldserver.conf", },
113 { name: "etc", mountPath: "/azeroth-server/etc/mod_ahbot.conf", subPath: "mod_ahbot.conf", },
114 ],
115 command: [
116 "/entrypoint.sh",
117 "/azeroth-server/bin/worldserver",
118 ],
119 },
120 },
121 securityContext: {
122 runAsUser: 999,
123 runAsGroup: 999,
124 fsGroup: 999,
125 },
126 volumes_: {
127 data: kube.PersistentVolumeClaimVolume(wow.data),
128 etc: kube.SecretVolume(wow.etc),
129 },
130 },
131 },
132 },
133 },
134
135 authserverDeploy: ns.Contain(kube.Deployment(cfg.prefix + "authserver")) {
136 spec+: {
137 template+: {
138 spec+: {
139 containers_: {
140 default: kube.Container("default") {
141 image: cfg.images.acore,
142 volumeMounts_: {
143 etc: { mountPath: "/azeroth-server/etc/authserver.conf", subPath: "authserver.conf", },
144 },
145 command: [
146 "/azeroth-server/bin/authserver",
147 ],
148 },
149 },
150 securityContext: {
151 runAsUser: 999,
152 runAsGroup: 999,
153 },
154 volumes_: {
155 etc: kube.SecretVolume(wow.etc),
156 },
157 },
158 },
159 },
160 },
Radek Pietruszewskif28cd622023-11-03 17:30:10 +0100161
Serge Bazanski1572e522020-12-03 23:19:28 +0100162 soapSvc: ns.Contain(kube.Service(cfg.prefix + "worldserver-soap")) {
163 target_pod:: wow.worldserverDeploy.spec.template,
164 spec+: {
165 ports: [
166 { name: "soap", port: 7878, targetPort: 7878, protocol: "TCP" },
167 ],
168 },
169 },
170 worldserverSvc: ns.Contain(kube.Service(cfg.prefix + "worldserver")) {
171 target_pod:: wow.worldserverDeploy.spec.template,
172 metadata+: {
173 annotations+: {
174 "metallb.universe.tf/allow-shared-ip": "%s/%ssvc" % [cfg.namespace, cfg.prefix],
175 },
176 },
177 spec+: {
178 ports: [
179 { name: "worldserver", port: 8085, targetPort: 8085, protocol: "TCP" },
180 ],
181 type: "LoadBalancer",
182 externalTrafficPolicy: "Cluster",
183 loadBalancerIP: cfg.address,
184 },
185 },
186 authserverSvc: ns.Contain(kube.Service(cfg.prefix + "authserver")) {
187 target_pod:: wow.authserverDeploy.spec.template,
188 metadata+: {
189 annotations+: {
190 "metallb.universe.tf/allow-shared-ip": "%s/%ssvc" % [cfg.namespace, cfg.prefix],
191 },
192 },
193 spec+: {
194 ports: [
195 { name: "authserver", port: 3724, targetPort: 3724, protocol: "TCP" },
196 ],
197 type: "LoadBalancer",
198 externalTrafficPolicy: "Cluster",
199 loadBalancerIP: cfg.address,
200 },
201 },
202
203 panelSecret: ns.Contain(kube.Secret(cfg.prefix + "panel-secret")) {
204 data+: {
205 soapPassword: std.base64(cfg.panel.soap.password),
206 secret: std.base64(cfg.panel.secret),
207 oauthSecret: std.base64(cfg.panel.oauth.clientSecret),
208 "motd.txt": std.base64(cfg.panel.motd),
209 },
210 },
211 panelData: ns.Contain(kube.PersistentVolumeClaim(cfg.prefix + "panel-data")) {
Radek Pietruszewskif28cd622023-11-03 17:30:10 +0100212 storage: "128Mi",
213 storageClass: "waw-hdd-redundant-3",
Serge Bazanski1572e522020-12-03 23:19:28 +0100214 },
215 panelDeploy: ns.Contain(kube.Deployment(cfg.prefix + "panel")) {
216 spec+: {
217 template+: {
218 spec+: {
219 containers_: {
220 default: kube.Container("default") {
221 image: cfg.images.panel,
222 env_: {
223 SOAP_PASSWORD: kube.SecretKeyRef(wow.panelSecret, "soapPassword"),
224 SECRET: kube.SecretKeyRef(wow.panelSecret, "secret"),
225 OAUTH_SECRET: kube.SecretKeyRef(wow.panelSecret, "oauthSecret"),
226 },
227 command: [
228 "/personal/q3k/wow/panel/panel",
229 "-listen", "0.0.0.0:8080",
230 "-db", "/data/panel.db",
231 "-soap_address", "http://%s" % [wow.soapSvc.host_colon_port],
232 "-soap_password", "$(SOAP_PASSWORD)",
233 "-secret", "$(SECRET)",
Radek Pietruszewskif28cd622023-11-03 17:30:10 +0100234 "-oauth_client_id", cfg.panel.oauth.clientID,
Serge Bazanski1572e522020-12-03 23:19:28 +0100235 "-oauth_client_secret", "$(OAUTH_SECRET)",
236 "-oauth_redirect_url", cfg.panel.oauth.redirectURL,
237 "-motd", "/secret/motd.txt",
238 ],
239 volumeMounts_: {
240 data: { mountPath: "/data" },
241 secret: { mountPath: "/secret" },
242 },
243 },
244 },
245 volumes_: {
246 data: kube.PersistentVolumeClaimVolume(wow.panelData),
247 secret: kube.SecretVolume(wow.panelSecret),
248 },
249 },
250 },
251 },
252 },
253 panelSvc: ns.Contain(kube.Service(cfg.prefix + "panel")) {
254 target_pod:: wow.panelDeploy.spec.template,
255 spec+: {
256 ports: [
257 { name: "web", port: 8080, targetPort: 8080, protocol: "TCP" },
258 ],
259 },
260 },
Radek Pietruszewskif5844312023-10-27 22:41:18 +0200261 panelIngress: ns.Contain(kube.SimpleIngress(cfg.prefix + "panel")) {
262 hosts:: [cfg.panel.domain],
263 target_service:: wow.panelSvc,
Serge Bazanski1572e522020-12-03 23:19:28 +0100264 },
265}