Skip to content

Commit

Permalink
feat(shulker-proxy-agent): use proxy capacities as max slots in ping …
Browse files Browse the repository at this point in the history
…requests (#394)

* feat(shulker-proxy-agent): use proxy capacities as max slots in ping requests

* chore: bump server and proxy images
  • Loading branch information
jeremylvln committed Feb 6, 2024
1 parent 4d86d34 commit 235e6ba
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 62 deletions.
4 changes: 2 additions & 2 deletions examples/getting-started/proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ spec:
name: getting-started
replicas: 1
service:
type: ClusterIP
# externalTrafficPolicy: Local
type: LoadBalancer
externalTrafficPolicy: Local
template:
spec:
version:
Expand Down
2 changes: 1 addition & 1 deletion packages/shulker-operator/assets/proxy-probe-readiness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ if [ -f "/tmp/drain-lock" ]; then
echo "Drain lock found" && exit 1
fi

bash /health.sh
bash /usr/bin/health.sh
3 changes: 3 additions & 0 deletions packages/shulker-operator/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ pub const SHULKER_PLUGIN_VERSION: &str =
const_format::concatcp!(env!("CARGO_PKG_VERSION"), "-SNAPSHOT");
#[cfg(not(debug_assertions))]
pub const SHULKER_PLUGIN_VERSION: &str = env!("CARGO_PKG_VERSION");

pub const PROXY_IMAGE: &str = "itzg/bungeecord:java17-2023.11.0";
pub const MINECRAFT_SERVER_IMAGE: &str = "itzg/minecraft-server:2024.2.1-java17";
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use shulker_crds::v1alpha1::minecraft_server::MinecraftServerVersion;
use url::Url;

use crate::agent::AgentConfig;
use crate::constants;
use crate::reconcilers::agent::get_agent_plugin_url;
use crate::reconcilers::agent::AgentSide;
use crate::resources::resourceref_resolver::ResourceRefResolver;
Expand All @@ -37,7 +38,6 @@ use shulker_kube_utils::reconcilers::builder::ResourceBuilder;
use super::config_map::ConfigMapBuilder;
use super::MinecraftServerReconciler;

const MINECRAFT_SERVER_IMAGE: &str = "itzg/minecraft-server:2023.10.1-java17";
const MINECRAFT_SERVER_SHULKER_CONFIG_DIR: &str = "/mnt/shulker/config";
const MINECRAFT_SERVER_CONFIG_DIR: &str = "/config";
const MINECRAFT_SERVER_DATA_DIR: &str = "/data";
Expand Down Expand Up @@ -185,7 +185,7 @@ impl<'a> GameServerBuilder {
..Container::default()
}]),
containers: vec![Container {
image: Some(MINECRAFT_SERVER_IMAGE.to_string()),
image: Some(constants::MINECRAFT_SERVER_IMAGE.to_string()),
name: "minecraft-server".to_string(),
ports: Some(vec![ContainerPort {
name: Some("minecraft".to_string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec:
value: 1.20.1
- name: EXTRA_ENV
value: my_value
image: "itzg/minecraft-server:2023.10.1-java17"
image: "itzg/minecraft-server:2024.2.1-java17"
imagePullPolicy: IfNotPresent
name: minecraft-server
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ spec:
value: 1.20.1
- name: EXTRA_ENV
value: my_value
image: "itzg/minecraft-server:2023.10.1-java17"
image: "itzg/minecraft-server:2024.2.1-java17"
imagePullPolicy: IfNotPresent
name: minecraft-server
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use shulker_crds::v1alpha1::proxy_fleet::ProxyFleetTemplateVersion;
use url::Url;

use crate::agent::AgentConfig;
use crate::constants;
use crate::reconcilers::agent::get_agent_plugin_url;
use crate::reconcilers::agent::AgentSide;
use crate::reconcilers::redis_ref::RedisRef;
Expand All @@ -47,7 +48,6 @@ use shulker_kube_utils::reconcilers::builder::ResourceBuilder;
use super::config_map::ConfigMapBuilder;
use super::ProxyFleetReconciler;

const PROXY_IMAGE: &str = "itzg/bungeecord:java17-2022.4.1";
const PROXY_SHULKER_CONFIG_DIR: &str = "/mnt/shulker/config";
const PROXY_SHULKER_FORWARDING_SECRET_DIR: &str = "/mnt/shulker/forwarding-secret";
const PROXY_DATA_DIR: &str = "/server";
Expand Down Expand Up @@ -205,7 +205,7 @@ impl<'a> FleetBuilder {
..Container::default()
}]),
containers: vec![Container {
image: Some(PROXY_IMAGE.to_string()),
image: Some(constants::PROXY_IMAGE.to_string()),
name: "proxy".to_string(),
ports: Some(vec![ContainerPort {
name: Some("minecraft".to_string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ apiVersion: v1
kind: ConfigMap
data:
init-fs.sh: "#!/bin/sh\nset -euo pipefail\nset -o xtrace\n\ncp \"${SHULKER_CONFIG_DIR}/probe-readiness.sh\" \"${SHULKER_PROXY_DATA_DIR}/probe-readiness.sh\"\ncat \"${SHULKER_CONFIG_DIR}/server-icon.png\" | base64 -d > \"${SHULKER_PROXY_DATA_DIR}/server-icon.png\"\n\nif [ \"${SHULKER_VERSION_CHANNEL}\" == \"Velocity\" ]; then\n cp \"${SHULKER_CONFIG_DIR}/velocity-config.toml\" \"${SHULKER_PROXY_DATA_DIR}/velocity.toml\"\n echo \"dummy\" > \"${SHULKER_PROXY_DATA_DIR}/forwarding.secret\"\nelse\n cp \"${SHULKER_CONFIG_DIR}/bungeecord-config.yml\" \"${SHULKER_PROXY_DATA_DIR}/config.yml\"\nfi\n\nif [ ! -z \"${SHULKER_PROXY_PLUGIN_URLS+x}\" ]; then\n mkdir -p \"${SHULKER_PROXY_DATA_DIR}/plugins\"\n for plugin_url in ${SHULKER_PROXY_PLUGIN_URLS//;/ }; do\n (cd \"${SHULKER_PROXY_DATA_DIR}/plugins\" && wget \"${plugin_url}\")\n done\nfi\n\nif [ ! -z \"${SHULKER_PROXY_PATCH_URLS+x}\" ]; then\n for patch_url in ${SHULKER_PROXY_PATCH_URLS//;/ }; do\n (cd \"${SHULKER_PROXY_DATA_DIR}\" && wget \"${patch_url}\" -O - | tar -xzv)\n done\nfi\n"
probe-readiness.sh: "#!/bin/sh\nset -euo pipefail\nset -o xtrace\n\nif [ -f \"/tmp/drain-lock\" ]; then\n echo \"Drain lock found\" && exit 1\nfi\n\nbash /health.sh\n"
probe-readiness.sh: "#!/bin/sh\nset -euo pipefail\nset -o xtrace\n\nif [ -f \"/tmp/drain-lock\" ]; then\n echo \"Drain lock found\" && exit 1\nfi\n\nbash /usr/bin/health.sh\n"
server-icon.png: abc==
velocity-config.toml: "config-version = \"2.6\"\nbind = \"0.0.0.0:25577\"\nmotd = \"A Motd\"\nshow-max-players = 1000\nonline-mode = true\nforce-key-authentication = true\nprevent-client-proxy-connections = true\nforwarding-secret-file = \"/mnt/shulker/forwarding-secret/key\"\nplayer-info-forwarding-mode = \"modern\"\n\n[servers]\nlobby = \"localhost:30000\"\nlimbo = \"localhost:30001\"\ntry = [\"lobby\", \"limbo\"]\n\n[forced-hosts]\n\n[advanced]\nhaproxy-protocol = true\ntcp-fast-open = true\n\n"
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ spec:
value: "true"
- name: EXTRA_ENV
value: my_value
image: "itzg/bungeecord:java17-2022.4.1"
image: "itzg/bungeecord:java17-2023.11.0"
imagePullPolicy: IfNotPresent
name: proxy
ports:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.shulkermc.proxyagent.platform.ServerPreConnectHook
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer
import net.md_5.bungee.api.ProxyServer
import net.md_5.bungee.api.chat.TextComponent
import net.md_5.bungee.api.connection.ProxiedPlayer
import net.md_5.bungee.api.event.PermissionCheckEvent
import net.md_5.bungee.api.event.PlayerDisconnectEvent
Expand Down Expand Up @@ -56,7 +57,8 @@ class ProxyInterfaceBungeeCord(
@EventHandler(priority = EventPriority.LOWEST)
fun onPreLogin(event: ProxyPingEvent) {
val result = hook()
event.response.players.online = result.playerCount
event.response.players.online = result.onlinePlayerCount
event.response.players.max = result.maxPlayerCount
}
}
)
Expand All @@ -73,8 +75,9 @@ class ProxyInterfaceBungeeCord(
val result = hook()

if (!result.allowed) {
@Suppress("UnsafeCallOnNullableType")
event.setCancelReason(*BungeeComponentSerializer.get().serialize(result.rejectComponent!!))
event.reason = TextComponent.fromArray(
*BungeeComponentSerializer.get().serialize(result.rejectComponent!!)
)
}
}
}
Expand Down Expand Up @@ -166,6 +169,10 @@ class ProxyInterfaceBungeeCord(
return this.proxy.players.size
}

override fun getPlayerCapacity(): Int {
return this.proxy.config.playerLimit
}

override fun scheduleDelayedTask(
delay: Long,
timeUnit: TimeUnit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface ProxyInterface {
fun prepareNetworkAdminsPermissions(playerIds: List<UUID>)
fun teleportPlayerOnServer(playerName: String, serverName: String)
fun getPlayerCount(): Int
fun getPlayerCapacity(): Int

fun scheduleDelayedTask(delay: Long, timeUnit: TimeUnit, runnable: Runnable): ScheduledTask
fun scheduleRepeatingTask(delay: Long, interval: Long, timeUnit: TimeUnit, runnable: Runnable): ScheduledTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ShulkerProxyAgentCommon(val proxyInterface: ProxyInterface, val logger: Lo
)
}

this.cache.registerProxy(Configuration.PROXY_NAME)
this.cache.registerProxy(Configuration.PROXY_NAME, this.proxyInterface.getPlayerCapacity())
this.agonesGateway.setAllocated()
} catch (@Suppress("TooGenericExceptionCaught") e: Exception) {
this.logger.log(Level.SEVERE, "Shulker Agent crashed, stopping proxy", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.util.Optional
import java.util.UUID

interface CacheAdapter {
fun registerProxy(proxyName: String)
fun registerProxy(proxyName: String, proxyCapacity: Int)
fun unregisterProxy(proxyName: String)
fun updateProxyLastSeen(proxyName: String)
fun listRegisteredProxies(): List<RegisteredProxy>
Expand All @@ -25,8 +25,9 @@ interface CacheAdapter {
fun getPlayerNamesFromIds(playerIds: List<UUID>): Map<UUID, String>

fun countOnlinePlayers(): Int
fun countPlayerCapacity(): Int

data class RegisteredProxy(val proxyName: String, val lastSeenMillis: Long)
data class RegisteredProxy(val proxyName: String, val proxyCapacity: Int, val lastSeenMillis: Long)

interface Lock : AutoCloseable
}
Loading

0 comments on commit 235e6ba

Please sign in to comment.