{{- define "custom.custom.configuration.header" -}}
## Custom configuration
{{- end -}}

{{- define "custom.custom.configuration" -}}
{{ template "custom.custom.configuration.header" . }}

### Cart credits

This chart is partially inspired by [https://github.com/SQLJames/factorio-server-charts](https://github.com/SQLJames/factorio-server-charts) and the yaml for the server settings defaults is sourced from here.  Many thanks to @SQLJames for his work on that chart and the inspiration.

### Keeping server up to date

By default, this helm chart will follow `Factoriotools/Factorio:stable`.  Game servers need to be kept up to date regularly, but you might not want it updating during gameplay with traffic being forwarded from your router through open ports
The author recommends a approach of setting a `tag:` in your values.yaml to pin a specific version, and using a solution like [Renovate-bot](https://github.com/renovatebot/renovate) to control updates.
This can be best achieved to pinning to a specific sha release, which allows you to set the tag to follow.

Note that by default renovate follows latest which can sometimes be undesirable for this image.  The author notes that `stable` follows the version declared stable on [Factorio.com[(https://Factorio.com)] and on Steam, and `latest` can at times diverge into testing/beta releases (which require a Steam opt-in for downloading with traffic being forwarded from your router through open ports

### Pinning to one node

Whilst not best practice in k8s, it may be desirable to pin a game server to a node, so it is getting a paticular CPU (i.e. targeting best core performance).

```yaml
# Prefer higher single core speed node
affinity:
    nodeAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
        - weight: 1
        preference:
            matchExpressions:
            - key: kubernetes.io/hostname
                operator: In
                values:
                - <yourhostname>

```

### Map generation

This chart has yaml to allow you to pick map gen settings for first load.  One way that *may* be eaiser to get a map howver, is to generate the map in your local game with the UI, ensure you are happy with it.  You can run this helm once with default settings (to generate the folder structure in a PVC), spin it back down and mount the pvc in a test pod.  You can then copy your generated `map.zip` to the container and spin it back up - the server will load the 'latest' save and run your map.

### Networking

Networking may be a challenge as Factorio uses UDP.  One approach can be to use a load balancer in front of the service, with traffic being forwarded from your router through open ports pointed at the load balancer.  A load balancer could be set in this chart, for example with this addition (using metallb for load-balancing):

```yaml
service:
  main:
    ports:
      http:
        server:
            enabled: true
            type: LoadBalancer # Setting Ip external to cluster for easy port forward
            externalTrafficPolicy: Cluster
            loadBalancerIP: "192.168.2.100" # Set a IP here to ensure the game server is given a static internal IP
            annotations:
                metallb.universe.tf/allow-shared-ip: factorio
            ports:
                factorio-game:
                port: 34201
                protocol: UDP
                targetPort: 34197
        rcon:
            enabled: false
            type: LoadBalancer # Setting Ip external to cluster for easy port forward
            externalTrafficPolicy: Cluster
            loadBalancerIP: "192.168.2.100" # Set a IP here to ensure the game server is given a static internal IP
            annotations:
                metallb.universe.tf/allow-shared-ip: factorio
            ports:
                factorio-rcon:
                enabled: true
                port: 27015
                protocol: TCP
                targetPort: 27015
```

{{- end -}}
