Skip to content

Commit

Permalink
Get Dynmap using SPIGET
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesLaverack committed Jul 24, 2022
1 parent c9f93fe commit a4e1520
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/v1alpha1/minecraftserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ type MonitoringSpec struct {
Enabled bool `json:"enabled"`
}

type DynmapSpec struct {
Enabled bool `json:"enabled"`
}

// MinecraftServerSpec defines the desired state of MinecraftServer
type MinecraftServerSpec struct {
EULA EULAAcceptance `json:"eula"`
Expand All @@ -78,6 +82,7 @@ type MinecraftServerSpec struct {
ExternalServiceIP string `json:"externalServiceIP"`
VanillaTweaks *VanillaTweaks `json:"vanillaTweaks,omitempty"`
Monitoring *MonitoringSpec `json:"monitoring,omitempty"`
Dynmap *DynmapSpec `json:"dynmap,omitempty"`
}

// MinecraftServerStatus defines the observed state of MinecraftServer
Expand Down
20 changes: 20 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.

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ spec:
type: string
type: object
type: array
dynmap:
properties:
enabled:
type: boolean
required:
- enabled
type: object
eula:
enum:
- Accepted
Expand Down
30 changes: 30 additions & 0 deletions controllers/minecraftserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,33 @@ func TestReconcilerFixesServiceOwnerReference(t *testing.T) {
require.NoError(t, err)
assertOwnerReference(t, &server, &service)
}

func TestDynmapEnabled(t *testing.T) {
ctx := context.Background()
k8sClient, teardownFunc := setupTestingEnvironment(ctx, t)
defer teardownFunc()

server := generateTestServer()
server.Spec.Dynmap = &minecraftv1alpha1.DynmapSpec{
Enabled: true,
}
err := k8sClient.Create(ctx, &server)
require.NoError(t, err)

// TODO Find a better way to know when the reconciler is done
time.Sleep(reconcilerSyncDelay)

var configMap corev1.ConfigMap
err = k8sClient.Get(ctx, client.ObjectKeyFromObject(&server), &configMap)
require.NoError(t, err)

var pod corev1.Pod
err = k8sClient.Get(ctx, client.ObjectKeyFromObject(&server), &pod)
require.NoError(t, err)
assertOwnerReference(t, &server, &pod)
spec := pod.Spec
require.NotNil(t, spec)
container := pod.Spec.Containers[0]

assertEnv(t, container, "SPIGET_RESOURCES", "274")
}
13 changes: 12 additions & 1 deletion internal/reconcile/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,18 @@ func podForServer(server *v1alpha1.MinecraftServer, configMap *corev1.ConfigMap)
})
}

spigetResources := make([]string, 0)
var spigetResources []string

if server.Spec.Dynmap != nil && server.Spec.Dynmap.Enabled {
// This magic number is the Spigot plugin ID for Dynmap
// https://www.spigotmc.org/resources/dynmap%C2%AE.274/
spigetResources = append(spigetResources, "274")
container.Ports = append(container.Ports,
corev1.ContainerPort{
Name: "http",
ContainerPort: 8123,
})
}

if server.Spec.Monitoring != nil && server.Spec.Monitoring.Enabled {
// This magic number is the Spigot plugin ID for the Prometheus Exporter plugin
Expand Down

0 comments on commit a4e1520

Please sign in to comment.