Skip to content

Commit a73ca2e

Browse files
Merge pull request JamesLaverack#109 from JamesLaverack/forge
Rudimentary Forge Support
2 parents 98bc938 + b426028 commit a73ca2e

11 files changed

Lines changed: 407 additions & 12 deletions

‎.github/workflows/test-and-lint.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Install Go
2222
uses: actions/setup-go@v3
2323
with:
24-
go-version: 1.18.x
24+
go-version: 1.19.3
2525

2626
- name: Install goimports
2727
run: go install golang.org/x/tools/cmd/goimports@v0.1.12
@@ -69,7 +69,7 @@ jobs:
6969
- name: Install Go
7070
uses: actions/setup-go@v3
7171
with:
72-
go-version: 1.18.x
72+
go-version: 1.19.3
7373

7474
- name: Install setup-envtest
7575
run: go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

‎api/v1alpha1/minecraftserver.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ const (
2424
EULAAcceptanceNotAccepted EULAAcceptance = "NotAccepted"
2525
)
2626

27+
type ForgeSpec struct {
28+
ForgeVersion string `json:"forgeVersion"`
29+
ForgeInstallerSHA256Sum string `json:"forgeInstallerSha256Sum"`
30+
ModpackZipURL string `json:"modpackZipUrl"`
31+
ModpackZipSHA256Sum string `json:"modpackZipSha256Sum"`
32+
}
33+
2734
// Player is a Minecraft player defined by a username or a UUID
2835
type Player struct {
2936
Name string `json:"name,omitempty"`
3037
UUID string `json:"uuid,omitempty"`
3138
}
3239

3340
type WorldSpec struct {
41+
Seed string `json:"seed,omitempty"`
3442
Overworld *corev1.PersistentVolumeClaimVolumeSource `json:"overworld,omitempty"`
3543
Nether *corev1.PersistentVolumeClaimVolumeSource `json:"nether,omitempty"`
3644
TheEnd *corev1.PersistentVolumeClaimVolumeSource `json:"theEnd,omitempty"`
@@ -91,6 +99,7 @@ type MinecraftServerSpec struct {
9199
VanillaTweaks *VanillaTweaks `json:"vanillaTweaks,omitempty"`
92100
Monitoring *MonitoringSpec `json:"monitoring,omitempty"`
93101
Dynmap *DynmapSpec `json:"dynmap,omitempty"`
102+
Forge *ForgeSpec `json:"forge,omitempty"`
94103
}
95104

96105
// +kubebuilder:validation:Enum=None;ClusterIP;NodePort;LoadBalancer

‎api/v1alpha1/zz_generated.deepcopy.go‎

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎backup-agent.Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.18 as builder
2+
FROM golang:1.19.3 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

‎deploy/crd/minecraft.jameslaverack.com_minecraftservers.yaml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ spec:
8989
- Accepted
9090
- NotAccepted
9191
type: string
92+
forge:
93+
properties:
94+
forgeInstallerSha256Sum:
95+
type: string
96+
forgeVersion:
97+
type: string
98+
modpackZipSha256Sum:
99+
type: string
100+
modpackZipUrl:
101+
type: string
102+
required:
103+
- forgeInstallerSha256Sum
104+
- forgeVersion
105+
- modpackZipSha256Sum
106+
- modpackZipUrl
107+
type: object
92108
gameMode:
93109
enum:
94110
- Survival
@@ -202,6 +218,8 @@ spec:
202218
required:
203219
- claimName
204220
type: object
221+
seed:
222+
type: string
205223
theEnd:
206224
description: PersistentVolumeClaimVolumeSource references the
207225
user's PVC in the same namespace. This volume finds the bound

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/jameslaverack/kubernetes-minecraft-operator
22

3-
go 1.18
3+
go 1.19
44

55
require (
66
github.com/ghodss/yaml v1.0.0

‎operator.Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.18 as builder
2+
FROM golang:1.19.3 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

‎pkg/controller/minecraftserver/config_map.go‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package minecraftserver
22

33
import (
44
"context"
5-
"reflect"
65
"strconv"
76
"strings"
87

@@ -60,11 +59,11 @@ func ConfigMap(ctx context.Context, k8s client.Client, server *minecraftv1alpha1
6059
return true, k8s.Update(ctx, &actualConfigMap)
6160
}
6261

63-
if !reflect.DeepEqual(actualConfigMap.Data, data) {
64-
log.Info("ConfigMap data incorrect, updating")
65-
actualConfigMap.Data = data
66-
return true, k8s.Update(ctx, &actualConfigMap)
67-
}
62+
//if !reflect.DeepEqual(actualConfigMap.Data, data) {
63+
// log.Info("ConfigMap data incorrect, updating")
64+
// actualConfigMap.Data = data
65+
// return true, k8s.Update(ctx, &actualConfigMap)
66+
//}
6867

6968
log.Debug("ConfigMap OK")
7069
return false, nil
@@ -90,6 +89,9 @@ func configMapData(server minecraftv1alpha1.MinecraftServer) (map[string]string,
9089
props["enforce-whitelist"] = "true"
9190
props["white-list"] = "true"
9291
}
92+
if server.Spec.World != nil && server.Spec.World.Seed != "" {
93+
props["level-seed"] = server.Spec.World.Seed
94+
}
9395
config["server.properties"] = propertiesfile.Write(props)
9496

9597
// We always write a eula.txt file, but we *only* put "true" in it if the MinecraftServer object has had the EULA

‎pkg/controller/minecraftserver/replica_set.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package minecraftserver
33
import (
44
"context"
55
"path/filepath"
6+
"strings"
67

78
"github.com/pkg/errors"
89
appsv1 "k8s.io/api/apps/v1"
@@ -124,7 +125,7 @@ func spigetInstallContainer(pluginResourceID, pluginName, pluginsVolumeMountName
124125

125126
func downloadContainer(url, sha256, filename, volumeMountName string) corev1.Container {
126127
return corev1.Container{
127-
Name: "download",
128+
Name: "download-" + strings.Replace(filename, ".", "-", -1),
128129
Image: "ghcr.io/jameslaverack/download:edge",
129130
ImagePullPolicy: corev1.PullAlways,
130131
VolumeMounts: []corev1.VolumeMount{
@@ -162,6 +163,17 @@ func SecurityContext() *corev1.SecurityContext {
162163
}
163164

164165
func rsForServer(ctx context.Context, server *v1alpha1.MinecraftServer) (appsv1.ReplicaSet, error) {
166+
switch server.Spec.Type {
167+
case minecraftv1alpha1.ServerTypePaper:
168+
return rsForServerTypePaper(ctx, server)
169+
case minecraftv1alpha1.ServerTypeForge:
170+
return rsForServerTypeForge(ctx, server)
171+
default:
172+
return appsv1.ReplicaSet{}, errors.New("Unrecognised server type")
173+
}
174+
}
175+
176+
func rsForServerTypePaper(ctx context.Context, server *v1alpha1.MinecraftServer) (appsv1.ReplicaSet, error) {
165177
const paperJarVolumeName = "paper-jar"
166178
const paperWorkingDirVolumeName = "paper-workingdir"
167179
const configVolumeMountName = "config"

0 commit comments

Comments
 (0)