Skip to content

Commit

Permalink
fix: set force default server in proxy configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln committed Mar 22, 2022
1 parent f9e1694 commit 51d805c
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 19 deletions.
27 changes: 27 additions & 0 deletions api/v1alpha1/minecraftcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ type MinecraftClusterSpec struct {
// of this Minecraft Cluster.
//+kubebuilder:default={enabled: true, replicas: 1}
LimboSpec MinecraftClusterLimboSpec `json:"limboSpec"`

// Configuration of the proxy synchronization layer using
// Redis and RedisBungee.
//+kubebuilder:default={enabled: false}
RedisSync MinecraftClusterRedisSyncSpec `json:"redisSync"`
}

type MinecraftClusterLimboSpec struct {
Expand Down Expand Up @@ -76,6 +81,28 @@ type MinecraftClusterLimboSpec struct {
Affinity *corev1.Affinity `json:"affinity,omitempty"`
}

type MinecraftClusterRedisSyncSpec struct {
// Whether to enable Redis synchronization for the proxies
// using RedisBungee.
//+kubebuilder:default=false
Enabled bool `json:"enabled"`

// Name of the Kubernetes service allowing connections
// for the proxies.
//+kubebuilder:validation:Required
ServiceName string `json:"serviceName,omitempty"`

// Name of the Kubernetes secret containing the Redis
// credentials to use. Must contains a `username` and a
// `password` keys.
//+kubebuilder:validation:Required
SecretName string `json:"secretName,omitempty"`

// Number of the Redis database to use.
//+kubebuilder:default=0
Database int `json:"database,omitempty"`
}

type MinecraftClusterStatusCondition string

const (
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/minecraftserverdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ type MinecraftServerDeploymentSpec struct {
//+kubebuilder:default={enabled: true}
Rcon *MinecraftServerDeploymentRconSpec `json:"rcon,omitempty"`

// Map of extra files to create when bootstraping the
// Minecraft Server Deployment's pod.
ExtraFiles *map[string]string `json:"extraFiles,omitempty"`

// Overrides configuration for the Minecraft Server pods.
//+kubebuilder:default={livenessProbe: {initialDelaySeconds: 60}, readinessProbe: {initialDelaySeconds: 60}, terminationGracePeriodSeconds: 60}
PodOverrides *MinecraftServerDeploymentPodOverridesSpec `json:"podOverrides,omitempty"`
Expand Down Expand Up @@ -173,9 +177,11 @@ type MinecraftServerDeploymentPodOverridesSpec struct {
Env []corev1.EnvVar `json:"env,omitempty"`

// Overrides for the liveness probe of the Minecraft Server.
//+kubebuilder:default={initialDelaySeconds: 60}
LivenessProbe *MinecraftServerDeploymentPodProbeSpec `json:"livenessProbe,omitempty"`

// Overrides for the readiness probe of the Minecraft Server.
//+kubebuilder:default={initialDelaySeconds: 60}
ReadinessProbe *MinecraftServerDeploymentPodProbeSpec `json:"readinessProbe,omitempty"`

// Number of seconds before force killing the pod after a graceful
Expand Down
27 changes: 27 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions config/crd/bases/shulkermc.io_minecraftclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,36 @@ spec:
- enabled
- replicas
type: object
redisSync:
default:
enabled: false
description: Configuration of the proxy synchronization layer using
Redis and RedisBungee.
properties:
database:
default: 0
description: Number of the Redis database to use.
type: integer
enabled:
default: false
description: Whether to enable Redis synchronization for the proxies
using RedisBungee.
type: boolean
secretName:
description: Name of the Kubernetes secret containing the Redis
credentials to use. Must contains a `username` and a `password`
keys.
type: string
serviceName:
description: Name of the Kubernetes service allowing connections
for the proxies.
type: string
required:
- enabled
type: object
required:
- limboSpec
- redisSync
type: object
status:
description: MinecraftClusterStatus defines the observed state of MinecraftCluster
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/shulkermc.io_minecraftserverdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,12 @@ spec:
type: array
type: object
type: object
extraFiles:
additionalProperties:
type: string
description: Map of extra files to create when bootstraping the Minecraft
Server Deployment's pod.
type: object
maxPlayers:
default: 20
description: Number of maximum players that can connect to the Minecraft
Expand Down Expand Up @@ -1028,6 +1034,8 @@ spec:
description: Additional labels to add to the Minecraft Server.
type: object
livenessProbe:
default:
initialDelaySeconds: 60
description: Overrides for the liveness probe of the Minecraft
Server.
properties:
Expand All @@ -1040,6 +1048,8 @@ spec:
type: integer
type: object
readinessProbe:
default:
initialDelaySeconds: 60
description: Overrides for the readiness probe of the Minecraft
Server.
properties:
Expand Down
58 changes: 47 additions & 11 deletions internal/resource/proxy/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ func (b *ProxyDeploymentConfigMapBuilder) Update(object client.Object) error {
configMapData := make(map[string]string)

configMapData["init-fs.sh"] = strings.Trim(`
cp -H -r $SHULKER_CONFIG_DIR/* $SHULKER_DATA_DIR/;
set -x
cp -H -r $SHULKER_CONFIG_DIR/* $SHULKER_DATA_DIR/
if [ -e "$SHULKER_CONFIG_DIR/server-icon.png" ]; then cat $SHULKER_CONFIG_DIR/server-icon.png | base64 -d > $SHULKER_DATA_DIR/server-icon.png; fi
`, "\n ")

configMapData["init-plugins.sh"] = strings.Trim(`
set -x
mkdir -p $SHULKER_DATA_DIR/plugins
plugins=$(echo "$SHULKER_PLUGINS_URL" | tr ';' ' ')
for plugin in $plugins; do cd $SHULKER_DATA_DIR/plugins && curl -L -O $plugin; done
if [ ! -z "$SHULKER_REDIS_SYNC_ENABLED" ]; then mkdir -p $SHULKER_DATA_DIR/plugins/RedisBungee && cp $SHULKER_CONFIG_DIR/redisbungee-config.yml $SHULKER_DATA_DIR/plugins/RedisBungee/config.yml; fi
`, "\n ")

if b.Instance.Spec.ServerIcon != "" {
Expand All @@ -58,6 +61,14 @@ for plugin in $plugins; do cd $SHULKER_DATA_DIR/plugins && curl -L -O $plugin; d
}
configMapData["config.yml"] = configYml

if b.Cluster.Spec.RedisSync.Enabled {
redisBungeeConfigYml, err := b.getRedisBungeeConfigYmlFile()
if err != nil {
return err
}
configMapData["redisbungee-config.yml"] = redisBungeeConfigYml
}

configMap.Data = configMapData

if err := controllerutil.SetControllerReference(b.Instance, configMap, b.Scheme); err != nil {
Expand All @@ -79,21 +90,23 @@ type configYml struct {
}

type configListenerYml struct {
Host string `yaml:"host"`
QueryPort int16 `yaml:"query_port"`
Motd string `yaml:"motd"`
MaxPlayers int64 `yaml:"max_players"`
Priorities []string `yaml:"priorities"`
Host string `yaml:"host"`
QueryPort int16 `yaml:"query_port"`
Motd string `yaml:"motd"`
MaxPlayers int64 `yaml:"max_players"`
Priorities []string `yaml:"priorities"`
ForceDefaultServer bool `yaml:"force_default_server"`
}

func (b *ProxyDeploymentConfigMapBuilder) getConfigYmlFile() (string, error) {
configYml := configYml{
Listeners: []configListenerYml{{
Host: "0.0.0.0:25577",
QueryPort: int16(25577),
Motd: b.Instance.Spec.Motd,
MaxPlayers: *b.Instance.Spec.MaxPlayers,
Priorities: []string{"lobby"},
Host: "0.0.0.0:25577",
QueryPort: int16(25577),
Motd: b.Instance.Spec.Motd,
MaxPlayers: *b.Instance.Spec.MaxPlayers,
Priorities: []string{"lobby"},
ForceDefaultServer: true,
}},
Groups: map[string]interface{}{},
IpForward: true,
Expand All @@ -107,3 +120,26 @@ func (b *ProxyDeploymentConfigMapBuilder) getConfigYmlFile() (string, error) {

return string(out), nil
}

type redisBungeeConfigYml struct {
RedisServer string `yaml:"redis-server"`
RedisPort string `yaml:"redis-port"`
RedisPassword string `yaml:"redis-password"`
ServerId string `yaml:"server-id"`
}

func (b *ProxyDeploymentConfigMapBuilder) getRedisBungeeConfigYmlFile() (string, error) {
redisBungeeConfigYml := redisBungeeConfigYml{
RedisServer: "${CFG_REDISBUNGEE_REDIS_HOST}",
RedisPort: "${CFG_REDISBUNGEE_REDIS_PORT}",
RedisPassword: "${CFG_REDISBUNGEE_REDIS_PASSWORD}",
ServerId: "${CFG_SERVER_ID}",
}

out, err := yaml.Marshal(&redisBungeeConfigYml)
if err != nil {
return "", err
}

return string(out), nil
}
Loading

0 comments on commit 51d805c

Please sign in to comment.