|
| 1 | +/* |
| 2 | +Copyright 2022. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + meta "k8s.io/apimachinery/pkg/api/meta" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | +) |
| 23 | + |
| 24 | +//+kubebuilder:object:root=true |
| 25 | +//+kubebuilder:subresource:status |
| 26 | +//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.conditions[?(@.type==\"Ready\")].status" |
| 27 | +//+kubebuilder:printcolumn:name="Servers",type="number",JSONPath=".status.servers" |
| 28 | +//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" |
| 29 | +//+kubebuilder:resource:shortName={"smc"},categories=all |
| 30 | + |
| 31 | +// MinecraftCluster is the Schema for the MinecraftCluster API |
| 32 | +type MinecraftCluster struct { |
| 33 | + metav1.TypeMeta `json:",inline"` |
| 34 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 35 | + |
| 36 | + Spec MinecraftClusterSpec `json:"spec,omitempty"` |
| 37 | + Status MinecraftClusterStatus `json:"status,omitempty"` |
| 38 | +} |
| 39 | + |
| 40 | +// Defines the defired state of a MinecraftCluster. Most, to not |
| 41 | +// say all, fields configurable in a Minecraft Cluster can be |
| 42 | +// configured in this CRD. |
| 43 | +type MinecraftClusterSpec struct { |
| 44 | + // Short name to use internally to refer to this Minecraft Cluster. |
| 45 | + // Objects referring to this Minecraft Cluster will include this |
| 46 | + // short name as prefix in their own names. |
| 47 | + //+kubebuilder:validation:Required |
| 48 | + ShortName string `json:"shortName,omitempty"` |
| 49 | +} |
| 50 | + |
| 51 | +type MinecraftClusterStatusCondition string |
| 52 | + |
| 53 | +const ( |
| 54 | + ClusterReadyCondition MinecraftClusterStatusCondition = "Ready" |
| 55 | +) |
| 56 | + |
| 57 | +// MinecraftClusterStatus defines the observed state of MinecraftCluster |
| 58 | +type MinecraftClusterStatus struct { |
| 59 | + // Conditions represent the latest available observations of a |
| 60 | + // MinecraftCluster object. |
| 61 | + //+kubebuilder:validation:Required |
| 62 | + Conditions []metav1.Condition `json:"conditions"` |
| 63 | + |
| 64 | + // Number of servers inside the server pool. |
| 65 | + //+kubebuilder:validation:Required |
| 66 | + Servers int `json:"servers"` |
| 67 | + |
| 68 | + // Pool of Minecraft Servers linked to this Minecraft Cluster. |
| 69 | + //+kubebuilder:validation:Required |
| 70 | + ServerPool []MinecraftClusterStatusServerEntry `json:"serverPool"` |
| 71 | +} |
| 72 | + |
| 73 | +type MinecraftClusterStatusServerEntry struct { |
| 74 | + // Name of the Minecraft Server. |
| 75 | + //+kubebuilder:validation:Required |
| 76 | + Name string `json:"name,omitempty"` |
| 77 | + |
| 78 | + // IP of the Minecraft Server. |
| 79 | + //+kubebuilder:validation:Required |
| 80 | + Address string `json:"address,omitempty"` |
| 81 | +} |
| 82 | + |
| 83 | +func (s *MinecraftClusterStatus) SetCondition(condition MinecraftClusterStatusCondition, status metav1.ConditionStatus, reason string, message string) { |
| 84 | + meta.SetStatusCondition(&s.Conditions, metav1.Condition{ |
| 85 | + Type: string(condition), |
| 86 | + Status: status, |
| 87 | + Reason: reason, |
| 88 | + Message: message, |
| 89 | + }) |
| 90 | +} |
| 91 | + |
| 92 | +//+kubebuilder:object:root=true |
| 93 | + |
| 94 | +// MinecraftClusterList contains a list of MinecraftCluster |
| 95 | +type MinecraftClusterList struct { |
| 96 | + metav1.TypeMeta `json:",inline"` |
| 97 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 98 | + Items []MinecraftCluster `json:"items"` |
| 99 | +} |
| 100 | + |
| 101 | +type MinecraftClusterRef struct { |
| 102 | + // Name of the Minecraft Cluster. |
| 103 | + //+kubebuilder:validation:Required |
| 104 | + Name string `json:"name,omitempty"` |
| 105 | +} |
| 106 | + |
| 107 | +func init() { |
| 108 | + SchemeBuilder.Register(&MinecraftCluster{}, &MinecraftClusterList{}) |
| 109 | +} |
0 commit comments