diff --git a/.idea/modules/packages/google-agones-sdk/bindings/java/shulker.packages.google-agones-sdk-bindings-java.main.iml b/.idea/modules/packages/google-agones-sdk/bindings/java/shulker.packages.google-agones-sdk-bindings-java.main.iml index 6ba82c63..7cee5615 100644 --- a/.idea/modules/packages/google-agones-sdk/bindings/java/shulker.packages.google-agones-sdk-bindings-java.main.iml +++ b/.idea/modules/packages/google-agones-sdk/bindings/java/shulker.packages.google-agones-sdk-bindings-java.main.iml @@ -12,18 +12,18 @@ - - - + + + - - + + - - + + - + @@ -33,7 +33,7 @@ - + diff --git a/.idea/modules/packages/google-agones-sdk/bindings/java/shulker.packages.google-agones-sdk-bindings-java.test.iml b/.idea/modules/packages/google-agones-sdk/bindings/java/shulker.packages.google-agones-sdk-bindings-java.test.iml index 96d32d47..6635d934 100644 --- a/.idea/modules/packages/google-agones-sdk/bindings/java/shulker.packages.google-agones-sdk-bindings-java.test.iml +++ b/.idea/modules/packages/google-agones-sdk/bindings/java/shulker.packages.google-agones-sdk-bindings-java.test.iml @@ -7,17 +7,17 @@ - - - - - + + + + + - - + + - + @@ -27,7 +27,7 @@ - + diff --git a/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.bungeecord.iml b/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.bungeecord.iml index 82817585..a4ac09ca 100644 --- a/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.bungeecord.iml +++ b/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.bungeecord.iml @@ -131,7 +131,7 @@ - + @@ -155,25 +155,25 @@ - + - - - - + + + + - + - - + + - + diff --git a/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.common.iml b/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.common.iml index dff40ad6..db199ad8 100644 --- a/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.common.iml +++ b/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.common.iml @@ -113,7 +113,7 @@ - + @@ -129,20 +129,20 @@ - + - - - - + + + + - + - - + + - + diff --git a/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.velocity.iml b/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.velocity.iml index bb9f00cc..5fd79257 100644 --- a/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.velocity.iml +++ b/.idea/modules/packages/shulker-proxy-agent/shulker.packages.shulker-proxy-agent.velocity.iml @@ -133,7 +133,7 @@ - + @@ -152,20 +152,20 @@ - + - - - - + + + + - + - - + + - + diff --git a/.idea/modules/packages/shulker-sdk/bindings/java/shulker.packages.shulker-sdk-bindings-java.main.iml b/.idea/modules/packages/shulker-sdk/bindings/java/shulker.packages.shulker-sdk-bindings-java.main.iml index bcca47c2..11bb4f41 100644 --- a/.idea/modules/packages/shulker-sdk/bindings/java/shulker.packages.shulker-sdk-bindings-java.main.iml +++ b/.idea/modules/packages/shulker-sdk/bindings/java/shulker.packages.shulker-sdk-bindings-java.main.iml @@ -12,18 +12,18 @@ - - - + + + - - + + - - + + - + @@ -33,7 +33,7 @@ - + diff --git a/.idea/modules/packages/shulker-sdk/bindings/java/shulker.packages.shulker-sdk-bindings-java.test.iml b/.idea/modules/packages/shulker-sdk/bindings/java/shulker.packages.shulker-sdk-bindings-java.test.iml index af6a5f1e..765c9e83 100644 --- a/.idea/modules/packages/shulker-sdk/bindings/java/shulker.packages.shulker-sdk-bindings-java.test.iml +++ b/.idea/modules/packages/shulker-sdk/bindings/java/shulker.packages.shulker-sdk-bindings-java.test.iml @@ -7,17 +7,17 @@ - - - - - + + + + + - - + + - + @@ -27,7 +27,7 @@ - + diff --git a/.idea/modules/packages/shulker-server-agent/shulker.packages.shulker-server-agent.common.iml b/.idea/modules/packages/shulker-server-agent/shulker.packages.shulker-server-agent.common.iml index 9ec02f0c..b30612e8 100644 --- a/.idea/modules/packages/shulker-server-agent/shulker.packages.shulker-server-agent.common.iml +++ b/.idea/modules/packages/shulker-server-agent/shulker.packages.shulker-server-agent.common.iml @@ -60,26 +60,26 @@ - + - - - - - + + + + + - + - - + + - + diff --git a/.idea/modules/packages/shulker-server-agent/shulker.packages.shulker-server-agent.paper.iml b/.idea/modules/packages/shulker-server-agent/shulker.packages.shulker-server-agent.paper.iml index d04f4607..770c0f65 100644 --- a/.idea/modules/packages/shulker-server-agent/shulker.packages.shulker-server-agent.paper.iml +++ b/.idea/modules/packages/shulker-server-agent/shulker.packages.shulker-server-agent.paper.iml @@ -78,7 +78,7 @@ - + @@ -100,23 +100,23 @@ - - - - - + + + + + - + - - - + + + diff --git a/codecov.yml b/codecov.yml index 52985c6d..d140bdbd 100644 --- a/codecov.yml +++ b/codecov.yml @@ -13,18 +13,18 @@ coverage: google-open-match-sdk-bindings-rust: flags: - google-open-match-sdk-bindings-rust - shulker-addon-matchmaking: - flags: - - shulker-addon-matchmaking shulker-sdk-bindings-rust: flags: - shulker-sdk-bindings-rust - google-agones-crds: + shulker-addon-matchmaking: flags: - - google-agones-crds + - shulker-addon-matchmaking shulker-kube-utils: flags: - shulker-kube-utils + google-agones-crds: + flags: + - google-agones-crds shulker-operator: flags: - shulker-operator @@ -39,22 +39,22 @@ flags: paths: - packages/google-open-match-sdk/bindings/rust carryforward: true - shulker-addon-matchmaking: - paths: - - packages/shulker-addon-matchmaking - carryforward: true shulker-sdk-bindings-rust: paths: - packages/shulker-sdk/bindings/rust carryforward: true - google-agones-crds: + shulker-addon-matchmaking: paths: - - packages/google-agones-crds + - packages/shulker-addon-matchmaking carryforward: true shulker-kube-utils: paths: - packages/shulker-kube-utils carryforward: true + google-agones-crds: + paths: + - packages/google-agones-crds + carryforward: true shulker-operator: paths: - packages/shulker-operator diff --git a/packages/shulker-operator/src/reconcilers/redis_ref.rs b/packages/shulker-operator/src/reconcilers/redis_ref.rs index cd09fdbe..069311d0 100644 --- a/packages/shulker-operator/src/reconcilers/redis_ref.rs +++ b/packages/shulker-operator/src/reconcilers/redis_ref.rs @@ -5,6 +5,7 @@ use shulker_kube_utils::reconcilers::builder::ResourceBuilder; use super::minecraft_cluster::redis_service::RedisServiceBuilder; +#[derive(Debug, PartialEq, Clone)] pub struct RedisRef { pub host: String, pub port: u16, @@ -36,3 +37,83 @@ impl RedisRef { } } } + +#[cfg(test)] +mod tests { + use shulker_crds::v1alpha1::minecraft_cluster::{ + MinecraftClusterRedisDeploymentType, MinecraftClusterRedisProvidedSpec, + MinecraftClusterRedisSpec, + }; + + use crate::reconcilers::{minecraft_cluster::fixtures::TEST_CLUSTER, redis_ref::RedisRef}; + + #[test] + fn from_cluster_default() { + // G + let mut cluster = TEST_CLUSTER.clone(); + cluster.spec.redis = None; + + // W + let redis_ref = super::RedisRef::from_cluster(&cluster).unwrap(); + + // T + assert_eq!( + redis_ref, + RedisRef { + host: "my-cluster-redis-managed".to_string(), + port: 6379, + credentials_secret_name: None, + } + ); + } + + #[test] + fn from_cluster_managed() { + // G + let mut cluster = TEST_CLUSTER.clone(); + cluster.spec.redis = Some(MinecraftClusterRedisSpec { + type_: MinecraftClusterRedisDeploymentType::ManagedSingleNode, + provided: None, + }); + + // W + let redis_ref = super::RedisRef::from_cluster(&cluster).unwrap(); + + // T + assert_eq!( + redis_ref, + RedisRef { + host: "my-cluster-redis-managed".to_string(), + port: 6379, + credentials_secret_name: None, + } + ); + } + + #[test] + fn from_cluster_provided() { + // G + let mut cluster = TEST_CLUSTER.clone(); + cluster.spec.redis = Some(MinecraftClusterRedisSpec { + type_: MinecraftClusterRedisDeploymentType::Provided, + provided: Some(MinecraftClusterRedisProvidedSpec { + host: "my-redis-host".to_string(), + port: 1234, + credentials_secret_name: Some("my-redis-credentials".to_string()), + }), + }); + + // W + let redis_ref = super::RedisRef::from_cluster(&cluster).unwrap(); + + // T + assert_eq!( + redis_ref, + RedisRef { + host: "my-redis-host".to_string(), + port: 1234, + credentials_secret_name: Some("my-redis-credentials".to_string()), + } + ); + } +} diff --git a/packages/shulker-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/Configuration.kt b/packages/shulker-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/Configuration.kt index dac3ec8b..67fface3 100644 --- a/packages/shulker-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/Configuration.kt +++ b/packages/shulker-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/Configuration.kt @@ -1,5 +1,6 @@ package io.shulkermc.proxyagent +import java.util.Optional import java.util.UUID object Configuration { @@ -7,9 +8,9 @@ object Configuration { val PROXY_NAME = getStringEnv("SHULKER_PROXY_NAME") val PROXY_TTL_SECONDS = getLongEnv("SHULKER_PROXY_TTL_SECONDS") - val NETWORK_ADMINS = (getOptionalStringEnv("SHULKER_NETWORK_ADMINS") ?: "") - .split(",") - .map(UUID::fromString) + val NETWORK_ADMINS: List = getOptionalStringEnv("SHULKER_NETWORK_ADMINS") + .map { it.split(",").map(UUID::fromString) } + .orElse(emptyList()) val REDIS_HOST = getStringEnv("SHULKER_PROXY_REDIS_HOST") val REDIS_PORT = getIntEnv("SHULKER_PROXY_REDIS_PORT") @@ -17,7 +18,7 @@ object Configuration { val REDIS_PASSWORD = getOptionalStringEnv("SHULKER_PROXY_REDIS_PASSWORD") private fun getStringEnv(name: String): String = requireNotNull(System.getenv(name)) { "Missing $name" } - private fun getOptionalStringEnv(name: String): String? = System.getenv(name) + private fun getOptionalStringEnv(name: String): Optional = Optional.ofNullable(System.getenv(name)) private fun getIntEnv(name: String): Int = getStringEnv(name).toInt() private fun getLongEnv(name: String): Long = getStringEnv(name).toLong() } diff --git a/packages/shulker-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/ShulkerProxyAgentCommon.kt b/packages/shulker-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/ShulkerProxyAgentCommon.kt index 6e739563..7d035fae 100644 --- a/packages/shulker-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/ShulkerProxyAgentCommon.kt +++ b/packages/shulker-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/ShulkerProxyAgentCommon.kt @@ -113,14 +113,15 @@ class ShulkerProxyAgentCommon(val proxyInterface: ProxyInterface, val logger: Lo } private fun createJedisPool(): JedisPool { - if (Configuration.REDIS_USERNAME != null && Configuration.REDIS_PASSWORD != null) { - return JedisPool(Configuration.REDIS_HOST, Configuration.REDIS_PORT) + if (Configuration.REDIS_USERNAME.isPresent && Configuration.REDIS_PASSWORD.isPresent) { + return JedisPool( + Configuration.REDIS_HOST, + Configuration.REDIS_PORT, + Configuration.REDIS_USERNAME.get(), + Configuration.REDIS_PASSWORD.get() + ) } - return JedisPool( - Configuration.REDIS_HOST, - Configuration.REDIS_PORT, - Configuration.REDIS_USERNAME, - Configuration.REDIS_PASSWORD - ) + + return JedisPool(Configuration.REDIS_HOST, Configuration.REDIS_PORT) } } diff --git a/scripts/upload_codecov_files.sh b/scripts/upload_codecov_files.sh index e7bbf56e..c5bcddff 100644 --- a/scripts/upload_codecov_files.sh +++ b/scripts/upload_codecov_files.sh @@ -1,10 +1,10 @@ #!/bin/bash CODECOV="${CODECOV:-codecov}" $CODECOV -t $CODECOV_TOKEN -F google-open-match-sdk-bindings-rust -f ./coverage/rust/google-open-match-sdk-bindings-rust/cobertura.xml -$CODECOV -t $CODECOV_TOKEN -F shulker-addon-matchmaking -f ./coverage/rust/shulker-addon-matchmaking/cobertura.xml $CODECOV -t $CODECOV_TOKEN -F shulker-sdk-bindings-rust -f ./coverage/rust/shulker-sdk-bindings-rust/cobertura.xml -$CODECOV -t $CODECOV_TOKEN -F google-agones-crds -f ./coverage/rust/google-agones-crds/cobertura.xml +$CODECOV -t $CODECOV_TOKEN -F shulker-addon-matchmaking -f ./coverage/rust/shulker-addon-matchmaking/cobertura.xml $CODECOV -t $CODECOV_TOKEN -F shulker-kube-utils -f ./coverage/rust/shulker-kube-utils/cobertura.xml +$CODECOV -t $CODECOV_TOKEN -F google-agones-crds -f ./coverage/rust/google-agones-crds/cobertura.xml $CODECOV -t $CODECOV_TOKEN -F shulker-operator -f ./coverage/rust/shulker-operator/cobertura.xml $CODECOV -t $CODECOV_TOKEN -F shulker-utils -f ./coverage/rust/shulker-utils/cobertura.xml $CODECOV -t $CODECOV_TOKEN -F shulker-crds -f ./coverage/rust/shulker-crds/cobertura.xml