games/factorio: move jsonnet from //personal/q3k
We also remove the definition of two instances that are long since dead.
Change-Id: I0cd83321403053cb72837da1497842109eeacd2b
diff --git a/games/factorio/kube/factorio.libsonnet b/games/factorio/kube/factorio.libsonnet
new file mode 100644
index 0000000..4f2ff39
--- /dev/null
+++ b/games/factorio/kube/factorio.libsonnet
@@ -0,0 +1,148 @@
+# Factorio on Kubernetes.
+
+local kube = import "../../../../kube/kube.libsonnet";
+
+{
+ local factorio = self,
+ local cfg = factorio.cfg,
+
+ cfg:: {
+ namespace: error "namespace must be set",
+ appName: "factorio",
+ storageClassName: "waw-hdd-redundant-2",
+ prefix: "", # if set, should be 'foo-'
+ proxyImage: error "proxyImage must be set",
+
+ rconPort: 2137,
+ rconPassword: "farts",
+
+ tag: "latest",
+ image: "registry.k0.hswaw.net/q3k/factorio:" + cfg.tag,
+ resources: {
+ requests: {
+ cpu: "500m",
+ memory: "500Mi",
+ },
+ limits: {
+ cpu: "1",
+ memory: "1Gi",
+ },
+ },
+
+ mods: [],
+ },
+
+
+ makeName(suffix):: cfg.prefix + suffix,
+
+ metadata:: {
+ namespace: cfg.namespace,
+ labels: {
+ "app.kubernetes.io/name": factorio.makeName("factorio"),
+ "app.kubernetes.io/managed-by": "kubecfg",
+ "app.kubernetes.io/component": "factorio",
+ },
+ },
+
+ volumeClaimMods: kube.PersistentVolumeClaim(factorio.makeName("factorio-mods")) {
+ metadata+: factorio.metadata,
+ spec+: {
+ storageClassName: cfg.storageClassName,
+ accessModes: [ "ReadWriteOnce" ],
+ resources: {
+ requests: {
+ storage: "1Gi",
+ },
+ },
+ },
+ },
+
+ volumeClaimData: kube.PersistentVolumeClaim(factorio.makeName("factorio")) {
+ metadata+: factorio.metadata,
+ spec+: {
+ storageClassName: cfg.storageClassName,
+ accessModes: [ "ReadWriteOnce" ],
+ resources: {
+ requests: {
+ storage: "5Gi",
+ },
+ },
+ },
+ },
+
+ configMap: kube.ConfigMap(factorio.makeName("config")) {
+ metadata+: factorio.metadata,
+ data: {
+ "mods.pb.text": std.join("\n", [
+ "mod { name: \"%s\" version: \"%s\" }" % [m.name, m.version],
+ for m in cfg.mods
+ ]),
+ },
+ },
+
+ deployment: kube.Deployment(factorio.makeName("factorio")) {
+ metadata+: factorio.metadata,
+ spec+: {
+ replicas: 1,
+ template+: {
+ spec+: {
+ volumes_: {
+ data: kube.PersistentVolumeClaimVolume(factorio.volumeClaimData),
+ mods: kube.PersistentVolumeClaimVolume(factorio.volumeClaimMods),
+ config: kube.ConfigMapVolume(factorio.configMap),
+ },
+ initContainers_: {
+ modproxy: kube.Container("modproxy") {
+ image: cfg.proxyImage,
+ command: [
+ "/games/factorio/modproxy/client",
+ "-hspki_disable",
+ "-factorio_path", "/factorio",
+ "-proxy", "proxy.factorio.svc.cluster.local:4200",
+ "-config_path", "/factorio/mods.pb.text",
+ ],
+ volumeMounts_: {
+ mods: { mountPath: "/factorio/mods" },
+ config: { mountPath: "/factorio/mods.pb.text", subPath: "mods.pb.text" },
+ },
+ },
+ },
+ containers_: {
+ factorio: kube.Container(factorio.makeName("factorio")) {
+ image: cfg.image,
+ args: [
+ "/entrypoint.sh",
+ "--rcon-port", std.toString(cfg.rconPort),
+ "--rcon-password", cfg.rconPassword,
+ ],
+ ports_: {
+ client: { containerPort: 34197 },
+ rcon: { containerPort: cfg.rconPort },
+ },
+ volumeMounts_: {
+ data: { mountPath: "/data" },
+ mods: { mountPath: "/factorio/mods" },
+ },
+ resources: cfg.resources,
+ },
+ },
+ },
+ },
+ },
+ },
+ svc: kube.Service(factorio.makeName("factorio")) {
+ metadata+: factorio.metadata {
+ // hack - have to keep existing naming scheme otherwise we'd lose addresses
+ labels: {
+ "app.kubernetes.io/name": cfg.appName,
+ },
+ },
+ target_pod:: factorio.deployment.spec.template,
+ spec+: {
+ ports: [
+ { name: "client", port: 34197, targetPort: 34197, protocol: "UDP" },
+ ],
+ type: "LoadBalancer",
+ },
+ },
+}
diff --git a/games/factorio/kube/prod.jsonnet b/games/factorio/kube/prod.jsonnet
new file mode 100644
index 0000000..d833fc3
--- /dev/null
+++ b/games/factorio/kube/prod.jsonnet
@@ -0,0 +1,87 @@
+local factorio = import "factorio.libsonnet";
+local kube = import "../../../kube/kube.libsonnet";
+
+// This deploys factorio instances and the modproxy in the `factorio`
+// Kubernetes namespace.
+//
+// Available factorio versions:
+// - 0.18.40-1
+// - 1.0.0-1
+// See: //third_party/factorio.
+
+{
+ local prod = self,
+
+ proxyImage:: "registry.k0.hswaw.net/games/factorio/modproxy:1589157915-eafe7be328477e8a6590c4210466ef12901f1b9a",
+
+ namespace: kube.Namespace("factorio"),
+ 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" },
+ ],
+ },
+ },
+ },
+
+ local mod = function(name, version) { name: name, version: version },
+}