feat: support newline and comma-whitespace external host lists for auto-discovery (#468)

This commit is contained in:
Supratim Ghose
2025-10-25 03:18:34 +05:30
committed by GitHub
parent 4b5cb125e4
commit 22ec39b805
6 changed files with 113 additions and 10 deletions
+15 -3
View File
@@ -161,7 +161,7 @@ When using in Docker, make sure to volume mount the Docker socket into the conta
These are the labels scanned:
- `mc-router.host`: Used to configure the hostname the Minecraft clients would use to connect to the server. The container/service endpoint will be used as the routed backend. You can use more than one hostname by splitting it with a comma.
- `mc-router.host`: Used to configure the hostname the Minecraft clients would use to connect to the server. The container/service endpoint will be used as the routed backend. You can use more than one hostname by splitting it with a comma or newline. Whitespace around commas is automatically trimmed. For example: `"host1.com,host2.com"`, `"host1.com, host2.com"`, or `"host1.com\nhost2.com"`.
- `mc-router.port`: This value must be set to the port the Minecraft server is listening on. The default value is 25565.
- `mc-router.default`: Set this to a truthy value to make this server the default backend. Please note that `mc-router.host` is still required to be set.
- `mc-router.network`: Specify the network you are using for the router if multiple are present in the container/service. You can either use the network ID, it's full name or an alias.
@@ -234,7 +234,7 @@ For more information on the allow/deny list configuration, see the [json schema]
### Using Kubernetes Service auto-discovery
When running `mc-router` as a Kubernetes Pod and you pass the `--in-kube-cluster` command-line argument, then it will automatically watch for any services annotated with
- `mc-router.itzg.me/externalServerName` : The value of the annotation will be registered as the external hostname Minecraft clients would used to connect to the routed service. The service is used as the routed backend. You can use more hostnames by splitting them with comma.
- `mc-router.itzg.me/externalServerName` : The value of the annotation will be registered as the external hostname Minecraft clients would used to connect to the routed service. The service is used as the routed backend. You can use more hostnames by splitting them with comma or newline. Whitespace around commas is automatically trimmed. For example: `"host1.com,host2.com"`, `"host1.com, host2.com"`, or multi-line values.
- `mc-router.itzg.me/defaultServer` : When set to "true", the service is used as the default if no other `externalServiceName` annotations applies.
By default, the router will watch all namespaces for those services; however, a specific namespace can be specified using the `KUBE_NAMESPACE` environment variable. The pod's own namespace could be set using:
@@ -275,6 +275,18 @@ metadata:
annotations:
"mc-router.itzg.me/externalServerName": "external.host.name,other.host.name"
```
or with newlines and optional whitespace:
```yaml
apiVersion: v1
kind: Service
metadata:
name: mc-forge
annotations:
"mc-router.itzg.me/externalServerName": |
external.host.name
other.host.name
```
The `Role` or `ClusterRole` bound to the service account should have the rules:
@@ -625,4 +637,4 @@ docker run -it --rm \
## Related Projects
* https://github.com/haveachin/infrared
* https://github.com/haveachin/infrared