games/factorio: factor out modproxy jsonnet

This moves all the proxy Kube resources to proxy.libsonnet.

Effect is a zero diff against prod:

    $ kubecfg diff --diff-strategy=subset prod.jsonnet
    [...]
    namespaces factorio unchanged
    [...]
    deployments factorio.proxy unchanged
    [...]
    services factorio.proxy unchanged
    [...]
    persistentvolumeclaims factorio.proxy-cas unchanged

Change-Id: I9c6281e836f7b78373aad21120340994e801f8b4
This commit is contained in:
q3k 2021-06-12 22:02:25 +00:00
parent e7f4cc121a
commit c684ca9b81
2 changed files with 75 additions and 59 deletions

View file

@ -1,4 +1,5 @@
local factorio = import "factorio.libsonnet";
local proxy = import "proxy.libsonnet";
local kube = import "../../../kube/kube.libsonnet";
// This deploys factorio instances and the modproxy in the `factorio`
@ -12,74 +13,21 @@ local kube = import "../../../kube/kube.libsonnet";
{
local prod = self,
proxyImage:: "registry.k0.hswaw.net/games/factorio/modproxy:1589157915-eafe7be328477e8a6590c4210466ef12901f1b9a",
namespace: kube.Namespace("factorio"),
// instance makes a factorio server with a given name and at a
// given tag/version.
instance(name, tag):: factorio {
cfg+: {
namespace: "factorio",
prefix: name + "-",
tag: tag,
proxyImage: prod.proxyImage,
}
},
proxy: {
pvc: kube.PersistentVolumeClaim("proxy-cas") {
metadata+: {
namespace: "factorio",
},
spec+: {
storageClassName: "waw-hdd-redundant-3",
accessModes: [ "ReadWriteOnce" ],
resources: {
requests: {
storage: "32Gi",
},
},
},
},
deploy: kube.Deployment("proxy") {
metadata+: {
namespace: "factorio",
},
spec+: {
template+: {
spec+: {
volumes_: {
cas: kube.PersistentVolumeClaimVolume(prod.proxy.pvc),
},
containers_: {
proxy: kube.Container("proxy") {
image:prod.proxyImage,
command: [
"/games/factorio/modproxy/modproxy",
"-hspki_disable",
"-cas_directory", "/mnt/cas",
"-listen_address", "0.0.0.0:4200",
],
volumeMounts_: {
cas: { mountPath: "/mnt/cas" },
},
ports_: {
client: { containerPort: 4200 },
},
},
},
},
},
},
},
svc: kube.Service("proxy") {
metadata+: {
namespace: "factorio",
},
target_pod:: prod.proxy.deploy.spec.template,
spec+: {
ports: [
{ name: "client", port: 4200, targetPort: 4200, protocol: "TCP" },
],
},
proxy: proxy {
cfg+: {
namespace: "factorio",
},
},

View file

@ -0,0 +1,68 @@
local kube = import "../../../kube/kube.libsonnet";
{
local proxy = self,
local cfg = proxy.cfg,
cfg:: {
image:: "registry.k0.hswaw.net/games/factorio/modproxy:1589157915-eafe7be328477e8a6590c4210466ef12901f1b9a",
namespace: error "namespace must be set",
},
pvc: kube.PersistentVolumeClaim("proxy-cas") {
metadata+: {
namespace: cfg.namespace,
},
spec+: {
storageClassName: "waw-hdd-redundant-3",
accessModes: [ "ReadWriteOnce" ],
resources: {
requests: {
storage: "32Gi",
},
},
},
},
deploy: kube.Deployment("proxy") {
metadata+: {
namespace: "factorio",
},
spec+: {
template+: {
spec+: {
volumes_: {
cas: kube.PersistentVolumeClaimVolume(proxy.pvc),
},
containers_: {
proxy: kube.Container("proxy") {
image: cfg.image,
command: [
"/games/factorio/modproxy/modproxy",
"-hspki_disable",
"-cas_directory", "/mnt/cas",
"-listen_address", "0.0.0.0:4200",
],
volumeMounts_: {
cas: { mountPath: "/mnt/cas" },
},
ports_: {
client: { containerPort: 4200 },
},
},
},
},
},
},
},
svc: kube.Service("proxy") {
metadata+: {
namespace: "factorio",
},
target_pod:: proxy.deploy.spec.template,
spec+: {
ports: [
{ name: "client", port: 4200, targetPort: 4200, protocol: "TCP" },
],
},
},
}