mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-09-13 18:59:25 +00:00
♻️ refactor: migrate to Go Kubernetes operator
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
const (
|
||||
MinecraftImage = "itzg/minecraft-server"
|
||||
ProxyImage = "itzg/mc-proxy:latest"
|
||||
ContainerPort = 25565
|
||||
DefaultHeapPercent = 80
|
||||
)
|
||||
|
||||
@@ -46,8 +46,8 @@ func ProxyService(rp *v1alpha1.ReverseProxyServer) *corev1.Service {
|
||||
|
||||
func proxyEnv(rp *v1alpha1.ReverseProxyServer) []corev1.EnvVar {
|
||||
env := []corev1.EnvVar{
|
||||
{Name: "EULA", Value: "TRUE"},
|
||||
{Name: "TYPE", Value: string(rp.Spec.Type)},
|
||||
{Name: "NETWORKADDRESS_CACHE_TTL", Value: "30"},
|
||||
{Name: "MINIKURA_EXTERNAL_ADDRESS", Value: rp.Spec.ExternalAddress},
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func ProxyDeployment(rp *v1alpha1.ReverseProxyServer) *appsv1.Deployment {
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{{
|
||||
Name: "proxy",
|
||||
Image: MinecraftImage,
|
||||
Image: ProxyImage,
|
||||
Ports: []corev1.ContainerPort{{
|
||||
Name: "minecraft",
|
||||
ContainerPort: rp.Spec.ListenPort,
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
v1alpha1 "github.com/YuzuZensai/Minikura/operator/api/v1alpha1"
|
||||
)
|
||||
|
||||
func testProxy() *v1alpha1.ReverseProxyServer {
|
||||
return &v1alpha1.ReverseProxyServer{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "edge", Namespace: "minikura"},
|
||||
Spec: v1alpha1.ReverseProxyServerSpec{
|
||||
Type: v1alpha1.ProxyVelocity,
|
||||
ExternalAddress: "play.example.com",
|
||||
ExternalPort: 25565,
|
||||
ListenPort: 25577,
|
||||
Resources: v1alpha1.Resources{MemoryLimitMB: 512},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyDeploymentUsesProxyImage(t *testing.T) {
|
||||
container := ProxyDeployment(testProxy()).Spec.Template.Spec.Containers[0]
|
||||
if container.Image != ProxyImage {
|
||||
t.Errorf("image = %q, want %q", container.Image, ProxyImage)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyEnvCarriesRuntimeConfig(t *testing.T) {
|
||||
env := proxyEnv(testProxy())
|
||||
for _, want := range []struct{ key, value string }{
|
||||
{"TYPE", "VELOCITY"},
|
||||
{"NETWORKADDRESS_CACHE_TTL", "30"},
|
||||
{"MINIKURA_EXTERNAL_ADDRESS", "play.example.com"},
|
||||
} {
|
||||
got, ok := envValue(env, want.key)
|
||||
if !ok || got != want.value {
|
||||
t.Errorf("%s = %q, %v; want %q", want.key, got, ok, want.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user