-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.go
80 lines (72 loc) · 2.11 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package deployments
import (
"github.com/Quinn-5/GHost/ghost/configs/servconf"
appsv1 "k8s.io/api/apps/v1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// An empty example of a functional deployment. For use in testing or creating new deployments
func EmptyDeployment(config *servconf.ServerConfig) *appsv1.Deployment {
deployment := &appsv1.Deployment{
ObjectMeta: stdMeta(config),
Spec: appsv1.DeploymentSpec{
Replicas: int32Ptr(1),
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": config.ServerName,
},
},
Template: apiv1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": config.ServerName,
},
},
// Pod spec should be the only thing that needs to change between deployments
Spec: apiv1.PodSpec{
Containers: []apiv1.Container{
{
Name: config.ServerName,
// The container image for this game server
Image: "nginx",
Resources: apiv1.ResourceRequirements{
Limits: apiv1.ResourceList{
apiv1.ResourceCPU: config.CPU,
apiv1.ResourceMemory: config.RAM,
},
Requests: apiv1.ResourceList{
apiv1.ResourceCPU: resource.MustParse("0"),
apiv1.ResourceMemory: resource.MustParse("0"),
},
},
VolumeMounts: []apiv1.VolumeMount{
{
// Container's internal mount point for persistent data
MountPath: "/app/config",
Name: config.ServerName,
},
},
},
},
// Only necessary if you need persistent storage, but you probably do
Volumes: []apiv1.Volume{
{
Name: config.ServerName,
VolumeSource: apiv1.VolumeSource{
PersistentVolumeClaim: &apiv1.PersistentVolumeClaimVolumeSource{
ClaimName: config.ServerName,
},
},
},
},
},
},
},
}
// Set accordingly
config.InternalPort = 80
// Game protocol is almost always TCP, but some implementations differ.
config.Protocol = apiv1.ProtocolTCP
return deployment
}