Skip to content

Commit

Permalink
feat: add support for world and plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln committed Nov 5, 2022
1 parent a428571 commit e50b0b2
Show file tree
Hide file tree
Showing 19 changed files with 465 additions and 118 deletions.
81 changes: 81 additions & 0 deletions config/crd/bases/shulkermc.io_minecraftserverdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,47 @@ spec:
description: Number of maximum players that can connect
to the MinecraftServer.
type: integer
plugins:
description: List of references to plugins to download.
items:
properties:
url:
description: Direct URL of the resource to download.
type: string
urlFrom:
description: Source of the resource URL. Cannot
be used if value is not empty.
properties:
mavenRef:
description: Reference to a Maven artiact to
use as source.
properties:
artifactId:
description: Artifact ID of the Maven artifact
to download.
type: string
credentialsSecretName:
description: Name of the Kubernetes Secret
containing the repository credentials.
The secret must contains a username and
password keys.
type: string
groupId:
description: Group ID of the Maven artifact
to download.
type: string
repository:
description: URL to the Maven repository
to download the artifact from.
type: string
version:
description: Version of the Maven artifact
to download.
type: string
type: object
type: object
type: object
type: array
proxyForwardingMode:
default: Velocity
description: Type of forwarding the proxies are using
Expand All @@ -113,6 +154,46 @@ spec:
- BungeeCord
- Velocity
type: string
world:
description: Reference to a world to download and extract.
Gzipped tarball only.
properties:
url:
description: Direct URL of the resource to download.
type: string
urlFrom:
description: Source of the resource URL. Cannot be
used if value is not empty.
properties:
mavenRef:
description: Reference to a Maven artiact to use
as source.
properties:
artifactId:
description: Artifact ID of the Maven artifact
to download.
type: string
credentialsSecretName:
description: Name of the Kubernetes Secret
containing the repository credentials. The
secret must contains a username and password
keys.
type: string
groupId:
description: Group ID of the Maven artifact
to download.
type: string
repository:
description: URL to the Maven repository to
download the artifact from.
type: string
version:
description: Version of the Maven artifact
to download.
type: string
type: object
type: object
type: object
type: object
podOverrides:
description: Overrides for values to be injected in the created
Expand Down
74 changes: 74 additions & 0 deletions config/crd/bases/shulkermc.io_minecraftservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,44 @@ spec:
description: Number of maximum players that can connect to the
MinecraftServer.
type: integer
plugins:
description: List of references to plugins to download.
items:
properties:
url:
description: Direct URL of the resource to download.
type: string
urlFrom:
description: Source of the resource URL. Cannot be used
if value is not empty.
properties:
mavenRef:
description: Reference to a Maven artiact to use as
source.
properties:
artifactId:
description: Artifact ID of the Maven artifact to
download.
type: string
credentialsSecretName:
description: Name of the Kubernetes Secret containing
the repository credentials. The secret must contains
a username and password keys.
type: string
groupId:
description: Group ID of the Maven artifact to download.
type: string
repository:
description: URL to the Maven repository to download
the artifact from.
type: string
version:
description: Version of the Maven artifact to download.
type: string
type: object
type: object
type: object
type: array
proxyForwardingMode:
default: Velocity
description: Type of forwarding the proxies are using between
Expand All @@ -88,6 +126,42 @@ spec:
- BungeeCord
- Velocity
type: string
world:
description: Reference to a world to download and extract. Gzipped
tarball only.
properties:
url:
description: Direct URL of the resource to download.
type: string
urlFrom:
description: Source of the resource URL. Cannot be used if
value is not empty.
properties:
mavenRef:
description: Reference to a Maven artiact to use as source.
properties:
artifactId:
description: Artifact ID of the Maven artifact to
download.
type: string
credentialsSecretName:
description: Name of the Kubernetes Secret containing
the repository credentials. The secret must contains
a username and password keys.
type: string
groupId:
description: Group ID of the Maven artifact to download.
type: string
repository:
description: URL to the Maven repository to download
the artifact from.
type: string
version:
description: Version of the Maven artifact to download.
type: string
type: object
type: object
type: object
type: object
podOverrides:
description: Overrides for values to be injected in the created Pod
Expand Down
2 changes: 2 additions & 0 deletions libs/controllers/src/minecraftserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func (r *MinecraftServerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
resourceBuilder := resources.MinecraftServerResourceBuilder{
Instance: minecraftServer,
Scheme: r.Scheme,
Client: r.Client,
Ctx: ctx,
}
builders, dirtyBuilders := resourceBuilder.ResourceBuilders()

Expand Down
5 changes: 2 additions & 3 deletions libs/controllers/src/minecraftserverdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ func (r *MinecraftServerDeploymentReconciler) Reconcile(ctx context.Context, req
minecraftServer.Labels = labels
minecraftServer.Spec = minecraftServerDeployment.Spec.Template.Spec
minecraftServer.Spec.ClusterRef = minecraftServerDeployment.Spec.ClusterRef
minecraftServer.Spec.Configuration = shulkermciov1alpha1.MinecraftServerConfigurationSpec{
ExistingConfigMapName: resourceBuilder.GetConfigMapName(),
}
minecraftServer.Spec.Configuration = minecraftServerDeployment.Spec.Template.Spec.Configuration
minecraftServer.Spec.Configuration.ExistingConfigMapName = resourceBuilder.GetConfigMapName()

if err := controllerutil.SetControllerReference(minecraftServerDeployment, &minecraftServer, r.Scheme); err != nil {
err = fmt.Errorf("failed setting controller reference for MinecraftServer: %v", err)
Expand Down
5 changes: 2 additions & 3 deletions libs/controllers/src/proxydeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ func (r *ProxyDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Requ
proxy.Labels = labels
proxy.Spec = proxyDeployment.Spec.Template.Spec
proxy.Spec.ClusterRef = proxyDeployment.Spec.ClusterRef
proxy.Spec.Configuration = shulkermciov1alpha1.ProxyConfigurationSpec{
ExistingConfigMapName: resourceBuilder.GetConfigMapName(),
}
proxy.Spec.Configuration = proxyDeployment.Spec.Template.Spec.Configuration
proxy.Spec.Configuration.ExistingConfigMapName = resourceBuilder.GetConfigMapName()

if err := controllerutil.SetControllerReference(proxyDeployment, &proxy, r.Scheme); err != nil {
err = fmt.Errorf("failed setting controller reference for Proxy: %v", err)
Expand Down
11 changes: 10 additions & 1 deletion libs/crds/v1alpha1/mincraftserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,18 @@ const (
type MinecraftServerConfigurationSpec struct {
// Name of an optional ConfigMap already containing the server
// configuration.
//+optional
// +optional
ExistingConfigMapName string `json:"existingConfigMapName,omitempty"`

// Reference to a world to download and extract. Gzipped tarball
// only.
//+optional
World *ResourceRef `json:"world,omitempty"`

// List of references to plugins to download.
//+optional
Plugins []ResourceRef `json:"plugins,omitempty"`

// Number of maximum players that can connect to the MinecraftServer.
//+kubebuilder:default=20
MaxPlayers *int16 `json:"maxPlayers,omitempty"`
Expand Down
42 changes: 42 additions & 0 deletions libs/crds/v1alpha1/resourceref_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package v1alpha1

type ResourceRef struct {
// Direct URL of the resource to download.
// +optional
Url string `json:"url,omitempty"`

// Source of the resource URL. Cannot be used if value is not
// empty.
// +optional
UrlFrom *ResourceRefSource `json:"urlFrom,omitempty"`
}

type ResourceRefSource struct {
// Reference to a Maven artiact to use as source.
// +optional
MavenRef *ResourceRefMavenSelector `json:"mavenRef,omitempty"`
}

type ResourceRefMavenSelector struct {
// URL to the Maven repository to download the artifact from.
//+kubebuilder:validation:Required
Repository string `json:"repository,omitempty"`

// Group ID of the Maven artifact to download.
//+kubebuilder:validation:Required
GroupId string `json:"groupId,omitempty"`

// Artifact ID of the Maven artifact to download.
//+kubebuilder:validation:Required
ArtifactId string `json:"artifactId,omitempty"`

// Version of the Maven artifact to download.
//+kubebuilder:validation:Required
Version string `json:"version,omitempty"`

// Name of the Kubernetes Secret containing the repository
// credentials. The secret must contains a username
// and password keys.
//+optional
CredentialsSecretName string `json:"credentialsSecretName,omitempty"`
}
67 changes: 67 additions & 0 deletions libs/crds/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions libs/resources/src/minecraftserver/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ SPDX-License-Identifier: GPL-3.0-or-later
package resources

import (
"context"
"fmt"

shulkermciov1alpha1 "github.com/iamblueslime/shulker/libs/crds/v1alpha1"
common "github.com/iamblueslime/shulker/libs/resources/src"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type MinecraftServerResourceBuilder struct {
Instance *shulkermciov1alpha1.MinecraftServer
Scheme *runtime.Scheme
Client client.Client
Ctx context.Context
}

func (b *MinecraftServerResourceBuilder) ResourceBuilders() ([]common.ResourceBuilder, []common.ResourceBuilder) {
Expand Down
Loading

0 comments on commit e50b0b2

Please sign in to comment.