Skip to content

Commit

Permalink
feat: configure limbo for cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln committed Mar 13, 2022
1 parent 127541a commit 9c9dc99
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 58 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha1/minecraftserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ type MinecraftServerWorldSpec struct {
// server.
SchematicUrl string `json:"schematicUrl,omitempty"`

// World spawn coordinates of the schematic world when running
// a Limbo server.
SchematicWorldSpawn string `json:"schematicWorldSpawn,omitempty"`

// Whether to allow the Minecraft Server to generate a Nether world
// and the players to enter it.
//+kubebuilder:default=false
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/shulkermc.io_minecraftservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,10 @@ spec:
description: URL to a downloable schematic to use when running
a Limbo server.
type: string
schematicWorldSpawn:
description: World spawn coordinates of the schematic world when
running a Limbo server.
type: string
url:
description: URL to a downloable world.
type: string
Expand Down
5 changes: 3 additions & 2 deletions internal/resource/cluster/limbo_minecraftserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (b *MinecraftClusterLimboMinecraftServerBuilder) Build() (client.Object, er
func (b *MinecraftClusterLimboMinecraftServerBuilder) Update(object client.Object) error {
minecraftServer := object.(*shulkermciov1alpha1.MinecraftServer)

maxPlayers := int16(300)
maxPlayers := int16(-1)

minecraftServer.Spec = shulkermciov1alpha1.MinecraftServerSpec{
ClusterRef: &shulkermciov1alpha1.MinecraftClusterRef{
Expand All @@ -45,7 +45,8 @@ func (b *MinecraftClusterLimboMinecraftServerBuilder) Update(object client.Objec
},
MaxPlayers: &maxPlayers,
World: &shulkermciov1alpha1.MinecraftServerWorldSpec{
SchematicUrl: "https://i.jeremylvln.fr/shulker/limbo.schematic",
SchematicUrl: "https://i.jeremylvln.fr/shulker/limbo.schematic",
SchematicWorldSpawn: "13.5;3;8.5;0;0",
},
PodOverrides: &shulkermciov1alpha1.MinecraftServerPodOverridesSpec{
LivenessProbe: &shulkermciov1alpha1.MinecraftServerPodProbeSpec{
Expand Down
32 changes: 17 additions & 15 deletions internal/resource/proxy/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,32 @@ func (b *ProxyDeploymentConfigMapBuilder) CanBeUpdated() bool {
}

type configYml struct {
Listeners []configListenerYml `yaml:"listeners"`
Groups map[string]interface{} `yaml:"groups"`
Listeners []configListenerYml `yaml:"listeners"`
Groups map[string]interface{} `yaml:"groups"`
IpForward bool `yaml:"ip_forward"`
PreventProxyConnections bool `yaml:"prevent_proxy_connections"`
}

type configListenerYml struct {
Host string `yaml:"host"`
QueryPort int16 `yaml:"query_port"`
Motd string `yaml:"motd"`
MaxPlayers int64 `yaml:"max_players"`
ForceDefaultServer bool `yaml:"force_default_server"`
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"`
}

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,
ForceDefaultServer: true,
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"},
}},
Groups: map[string]interface{}{},
Groups: map[string]interface{}{},
IpForward: true,
PreventProxyConnections: true,
}

out, err := yaml.Marshal(&configYml)
Expand Down
55 changes: 54 additions & 1 deletion internal/resource/server/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ if [ ! -z "$SHULKER_LIMBO_SCHEMATIC_URL" ]; then wget -O $SHULKER_DATA_DIR/limbo

if b.Instance.Spec.World != nil && b.Instance.Spec.World.SchematicUrl != "" {
configMapData["init-limbo-schematic.sh"] = strings.Trim(`
wget -O $SHULKER_DATA_DIR/limbo.schematic $SHULKER_LIMBO_SCHEMATIC_URL
wget -O $SHULKER_DATA_DIR/limbo.schematic $SHULKER_LIMBO_SCHEMATIC_URL;
echo "bungeecord=true" >> $SHULKER_DATA_DIR/server.properties
echo "default-gamemode=adventure" >> $SHULKER_DATA_DIR/server.properties
echo "world-spawn=world;${SHULKER_LIMBO_WORLD_SPAWN}" >> $SHULKER_DATA_DIR/server.properties
echo "level-dimension=minecraft:the_end" >> $SHULKER_DATA_DIR/server.properties
echo "allow-chat=false" >> $SHULKER_DATA_DIR/server.properties
echo "handshake-verbose=false" >> $SHULKER_DATA_DIR/server.properties
`, "\n ")
}

Expand All @@ -59,6 +65,12 @@ wget -O $SHULKER_DATA_DIR/limbo.schematic $SHULKER_LIMBO_SCHEMATIC_URL
}
configMapData["bukkit.yml"] = bukkitYml

spigotYml, err := b.getSpigotYmlFile()
if err != nil {
return err
}
configMapData["spigot.yml"] = spigotYml

configMap.Data = configMapData

if err := controllerutil.SetControllerReference(b.Instance, configMap, b.Scheme); err != nil {
Expand Down Expand Up @@ -94,3 +106,44 @@ func (b *MinecraftServerConfigMapBuilder) getBukkitYmlFile() (string, error) {

return string(out), nil
}

type spigotYml struct {
Settings spigotSettingsYml `yaml:"settings"`
Advancements spigotSaveableYml `yaml:"advancements"`
Players spigotSaveableYml `yaml:"players"`
Stats spigotSaveableYml `yaml:"stats"`
}

type spigotSettingsYml struct {
BungeeCord bool `yaml:"bungeecord"`
RestartOnCrash bool `yaml:"restart-on-crash"`
}

type spigotSaveableYml struct {
DisableSaving bool `yaml:"disable-saving"`
}

func (b *MinecraftServerConfigMapBuilder) getSpigotYmlFile() (string, error) {
spigotYml := spigotYml{
Settings: spigotSettingsYml{
BungeeCord: true,
RestartOnCrash: false,
},
Advancements: spigotSaveableYml{
DisableSaving: true,
},
Players: spigotSaveableYml{
DisableSaving: true,
},
Stats: spigotSaveableYml{
DisableSaving: true,
},
}

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

return string(out), nil
}
22 changes: 18 additions & 4 deletions internal/resource/server/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func (b *MinecraftServerPodBuilder) getInitContainers() []corev1.Container {
Name: "SHULKER_LIMBO_SCHEMATIC_URL",
Value: b.Instance.Spec.World.SchematicUrl,
},
{
Name: "SHULKER_LIMBO_WORLD_SPAWN",
Value: b.Instance.Spec.World.SchematicWorldSpawn,
},
},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
Expand Down Expand Up @@ -250,6 +254,10 @@ func (b *MinecraftServerPodBuilder) getPodEnv() []corev1.EnvVar {
Name: "ONLINE_MODE",
Value: strconv.FormatBool(b.Instance.Spec.ClusterRef == nil),
},
{
Name: "OVERRIDE_SERVER_PROPERTIES",
Value: "true",
},
}

if b.Instance.Spec.Rcon.Enabled {
Expand Down Expand Up @@ -290,10 +298,16 @@ func (b *MinecraftServerPodBuilder) getPodEnv() []corev1.EnvVar {
}

if b.Instance.Spec.World.SchematicUrl != "" {
env = append(env, corev1.EnvVar{
Name: "LIMBO_SCHEMA_FILENAME",
Value: "limbo.schematic",
})
env = append(env, []corev1.EnvVar{
{
Name: "LIMBO_SCHEMA_FILENAME",
Value: "limbo.schematic",
},
{
Name: "LEVEL",
Value: "world;limbo.schematic",
},
}...)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

public class ServerConnectListener implements Listener {
private static final BaseComponent[] MSG_NO_LIMBO_FOUND = new ComponentBuilder()
.append("◆ Shulker ◆\n")
.color(ChatColor.LIGHT_PURPLE)
.bold(true)
.append("-[ Shulker ]-\n")
.append("No limbo server found, please check your cluster configuration.")
.color(ChatColor.RED)
.bold(false)
.append("No limbo server found, please check your cluster\nconfiguration.")
.create();

private final ShulkerProxyDirectory plugin;
Expand All @@ -32,7 +32,6 @@ public ServerConnectListener(ShulkerProxyDirectory plugin) {

@EventHandler(priority = EventPriority.LOWEST)
public void onServerConnect(ServerConnectEvent event) {
this.plugin.getLogger().info(event.getTarget().getName());
if (!event.getTarget().getName().equals("lobby")) {
return;
}
Expand Down
34 changes: 1 addition & 33 deletions test/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,7 @@ spec:
name: test
version:
channel: Spigot
name: 1.18.1
operators:
- IamBlueSlime
whitelistedPlayers:
- IamBlueSlime
world:
url: https://i.jeremylvln.fr/shulker/hub.tar.gz
disableNether: true
disableEnd: true
rcon:
enabled: true
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
preference:
matchExpressions:
- key: cloud.google.com/gke-preemptible
operator: In
values:
- 'true'

---
apiVersion: shulkermc.io/v1alpha1
kind: MinecraftServer
metadata:
name: hub-2
spec:
minecraftClusterRef:
name: test
version:
channel: Spigot
name: 1.18.1
name: 1.18.2
operators:
- IamBlueSlime
whitelistedPlayers:
Expand Down

0 comments on commit 9c9dc99

Please sign in to comment.