/
manifests.go
169 lines (162 loc) · 3.97 KB
/
manifests.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package main
import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
var (
replicas = int32(3)
quantity1Gi = resource.MustParse("1Gi")
quantity100Mi = resource.MustParse("100Mi")
quantity1 = resource.MustParse("1")
quantity100m = resource.MustParse("100m")
port = intstr.FromInt(8080)
deployment = &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"app": "nginx"},
Name: "nginx",
Namespace: "default",
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "nginx",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "nginx",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Env: []corev1.EnvVar{
{
Name: "VAR",
Value: "abc",
},
{
Name: "VAR_CONFIG",
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "nginx-config",
},
Key: "a",
},
},
},
{
Name: "SECRET_VAR",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "nginx-secret",
},
Key: "secret",
},
},
},
},
Image: "nginx",
Name: "nginx",
Ports: []corev1.ContainerPort{{ContainerPort: 8080}},
Resources: corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: quantity1,
corev1.ResourceMemory: quantity1Gi,
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: quantity100m,
corev1.ResourceMemory: quantity100Mi,
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "config-volume",
MountPath: "/",
SubPath: "nginx.conf",
},
},
},
},
Volumes: []corev1.Volume{
{
Name: "config-volume",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{LocalObjectReference: corev1.LocalObjectReference{
Name: "nginx-config"}},
},
},
},
},
},
},
}
service = &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"app": "nginx"},
Name: "nginx",
Namespace: "default",
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Name: "nginx",
Port: 80,
Protocol: corev1.ProtocolTCP,
TargetPort: port,
},
},
Selector: map[string]string{"app": "nginx"},
Type: corev1.ServiceTypeLoadBalancer,
},
}
nginxConf = `worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}`
configMap = &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"app": "nginx"},
Name: "nginx-config",
Namespace: "default",
},
Data: map[string]string{
"nginx.conf": nginxConf,
},
}
secret = &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"app": "nginx"},
Name: "nginx-secret",
Namespace: "default",
},
StringData: map[string]string{
"secret": "topSecret123",
},
}
)