Skip to content

Commit

Permalink
feat: add proxy deployment api
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln committed Mar 4, 2022
1 parent af183f4 commit 1fabf97
Show file tree
Hide file tree
Showing 27 changed files with 2,298 additions and 46 deletions.
8 changes: 8 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ resources:
kind: MinecraftCluster
path: shulkermc.io/m/v2/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: shulkermc.io
kind: ProxyDeployment
path: shulkermc.io/m/v2/api/v1alpha1
version: v1alpha1
version: "3"
13 changes: 5 additions & 8 deletions api/v1alpha1/minecraftcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.conditions[?(@.type==\"Ready\")].status"
//+kubebuilder:printcolumn:name="Proxies",type="number",JSONPath=".status.proxies"
//+kubebuilder:printcolumn:name="Servers",type="number",JSONPath=".status.servers"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:resource:shortName={"smc"},categories=all
Expand All @@ -41,11 +42,6 @@ type MinecraftCluster struct {
// say all, fields configurable in a Minecraft Cluster can be
// configured in this CRD.
type MinecraftClusterSpec struct {
// Short name to use internally to refer to this Minecraft Cluster.
// Objects referring to this Minecraft Cluster will include this
// short name as prefix in their own names.
//+kubebuilder:validation:Required
ShortName string `json:"shortName,omitempty"`
}

type MinecraftClusterStatusCondition string
Expand All @@ -61,12 +57,13 @@ type MinecraftClusterStatus struct {
//+kubebuilder:validation:Required
Conditions []metav1.Condition `json:"conditions"`

// Number of proxies.
Proxies int32 `json:"proxies"`

// Number of servers inside the server pool.
//+kubebuilder:validation:Required
Servers int `json:"servers"`
Servers int32 `json:"servers"`

// Pool of Minecraft Servers linked to this Minecraft Cluster.
//+kubebuilder:validation:Required
ServerPool []MinecraftClusterStatusServerEntry `json:"serverPool"`
}

Expand Down
3 changes: 2 additions & 1 deletion api/v1alpha1/minecraftserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type MinecraftServerSpec struct {
// this Minecraft Server to be part of a Minecraft Cluster.
ClusterRef *MinecraftClusterRef `json:"minecraftClusterRef"`

// Version the Minecraft Server has to run.
//+kubebuilder:validation:Required
Version MinecraftServerVersionSpec `json:"version"`

Expand Down Expand Up @@ -128,7 +129,7 @@ type MinecraftServerVersionSpec struct {
//+kubebuilder:default=Vanilla
Channel MinecraftServerVersionChannel `json:"channel,omitempty"`

// Name of the version to use with a leading "v". Example: v1.18.1.
// Name of the version to use.
//+kubebuilder:validation:Required
Name string `json:"name"`
}
Expand Down
180 changes: 180 additions & 0 deletions api/v1alpha1/proxydeployment_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
Copyright 2022.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.conditions[?(@.type==\"Ready\")].status"
//+kubebuilder:printcolumn:name="Available Replicas",type="date",JSONPath=".status.availableReplicas"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:resource:shortName={"spd"},categories=all

// ProxyDeployment is the Schema for the ProxyDeployment API
type ProxyDeployment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ProxyDeploymentSpec `json:"spec,omitempty"`
Status ProxyDeploymentStatus `json:"status,omitempty"`
}

// ProxyDeploymentSpec defines the desired state of ProxyDeployment
type ProxyDeploymentSpec struct {
// Reference to a Minecraft Cluster. Adding this will enroll
// this Proxy Deployment to be part of a Minecraft Cluster.
ClusterRef *MinecraftClusterRef `json:"minecraftClusterRef"`

// Version the Proxy Deployment has to run.
//+kubebuilder:validation:Required
Version ProxyDeploymentVersionSpec `json:"version,omitempty"`

// Number of replicas the Proxy Deployment should have.
//+kubebuilder:validation:Required
Replicas int32 `json:"replicas,omitempty"`

// The desired state of the Kubernetes Service to create for the
// Proxy Deployment.
//+kubebuilder:default={enabled: true, type: "LoadBalancer"}
Service *ProxyDeploymentServiceSpec `json:"service,omitempty"`

// Overrides configuration for the Proxy Deployment pod.
//+kubebuilder:default={livenessProbe: {initialDelaySeconds: 15}, readinessProbe: {initialDelaySeconds: 15}, terminationGracePeriodSeconds: 3600}
PodOverrides *MinecraftServerPodOverridesSpec `json:"podOverrides,omitempty"`

// The desired compute resource requirements of Pods in the Proxy
// Deployment.
//+kubebuilder:default={limits: {cpu: "2000m", memory: "2Gi"}, requests: {cpu: "1000m", memory: "1Gi"}}
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`

// Affinity scheduling rules to be applied on created Pods.
Affinity *corev1.Affinity `json:"affinity,omitempty"`
}

//+kubebuilder:validation:Enum=BungeeCord;Waterfall;Velocity
type ProxyDeploymentVersionChannel string

const (
ProxyDeploymentVersionBungeeCord ProxyDeploymentVersionChannel = "BungeeCord"
ProxyDeploymentVersionWaterfall ProxyDeploymentVersionChannel = "Waterfall"
ProxyDeploymentVersionVelocity ProxyDeploymentVersionChannel = "Velocity"
)

// Defines the version of Minecraft to run on the server.
// The version can come from a channel which allows the user
// to run a version different from Mojang's Vanilla.
type ProxyDeploymentVersionSpec struct {
// Channel of the version to use. Defaults to BungeeCord.
//+optional
//+kubebuilder:default=BungeeCord
Channel ProxyDeploymentVersionChannel `json:"channel,omitempty"`

// Name of the version to use.
//+kubebuilder:validation:Required
Name string `json:"name"`
}

// Configuration attributes for the Service resource.
type ProxyDeploymentServiceSpec struct {
// Whether to create a Service for the Proxy Deployment. Defaults
// to false.
//+kubebuilder:default=false
Enabled bool `json:"enabled,omitempty"`

// Type of Service to create. Must be one of: ClusterIP, LoadBalancer, NodePort.
// More info: https://pkg.go.dev/k8s.io/api/core/v1#ServiceType
//+kubebuilder:validation:Enum=ClusterIP;LoadBalancer;NodePort
//+kubebuilder:default="ClusterIP"
Type corev1.ServiceType `json:"type,omitempty"`

// Annotations to add to the Service.
Annotations map[string]string `json:"annotations,omitempty"`
}

type ProxyDeploymentPodOverridesSpec struct {
// Additional environment variables to add to the Proxy
// Deployment.
Env []corev1.EnvVar `json:"env,omitempty"`

// Overrides for the liveness probe of the Proxy Deployment.
LivenessProbe *ProxyDeploymentPodProbeSpec `json:"livenessProbe,omitempty"`

// Overrides for the readiness probe of the Proxy Deployment.
ReadinessProbe *ProxyDeploymentPodProbeSpec `json:"readinessProbe,omitempty"`

// Number of seconds before force killing the pod after a graceful
// termination request. Defaults to 1 minute.
//+kubebuilder:default=3600
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
}

type ProxyDeploymentPodProbeSpec struct {
// Number of seconds before starting to perform the probe. Depending
// on the server configuration, one can take more time than another to
// be ready. Defaults to 15 seconds.
//+kubebuilder:default=15
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"`
}

type ProxyDeploymentStatusCondition string

const (
ProxyDeploymentReadyCondition ProxyDeploymentStatusCondition = "Ready"
ProxyDeploymentAvailableCondition ProxyDeploymentStatusCondition = "Available"
ProxyDeploymentProgressingCondition ProxyDeploymentStatusCondition = "Progressing"
)

// ProxyDeploymentStatus defines the observed state of ProxyDeployment
type ProxyDeploymentStatus struct {
// Conditions represent the latest available observations of a
// ProxyDeployment object.
//+kubebuilder:validation:Required
Conditions []metav1.Condition `json:"conditions"`

// Number of total replicas in Proxy Deployment.
Replicas int32 `json:"replicas"`

// Number of available replicas in Proxy Deployment.
AvailableReplicas int32 `json:"availableReplicas"`
}

func (s *ProxyDeploymentStatus) SetCondition(condition ProxyDeploymentStatusCondition, status metav1.ConditionStatus, reason string, message string) {
meta.SetStatusCondition(&s.Conditions, metav1.Condition{
Type: string(condition),
Status: status,
Reason: reason,
Message: message,
})
}

//+kubebuilder:object:root=true

// ProxyDeploymentList contains a list of ProxyDeployment
type ProxyDeploymentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ProxyDeployment `json:"items"`
}

func init() {
SchemeBuilder.Register(&ProxyDeployment{}, &ProxyDeploymentList{})
}
Loading

0 comments on commit 1fabf97

Please sign in to comment.