-
Notifications
You must be signed in to change notification settings - Fork 88
/
web_objects.go
160 lines (150 loc) · 4.59 KB
/
web_objects.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
package kotsadm
import (
"fmt"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func webConfig(deployOptions DeployOptions) *corev1.ConfigMap {
configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kotsadm-web-scripts",
Namespace: deployOptions.Namespace,
},
Data: map[string]string{
"start-kotsadm-web.sh": fmt.Sprintf(`#!/bin/bash
sed -i 's/###_GRAPHQL_ENDPOINT_###/http:\/\/%s\/graphql/g' /usr/share/nginx/html/index.html
sed -i 's/###_REST_ENDPOINT_###/http:\/\/%s\/api/g' /usr/share/nginx/html/index.html
sed -i 's/###_GITHUB_CLIENT_ID_###/not-supported/g' /usr/share/nginx/html/index.html
sed -i 's/###_SHIPDOWNLOAD_ENDPOINT_###/http:\/\/%s\/api\/v1\/download/g' /usr/share/nginx/html/index.html
sed -i 's/###_SHIPINIT_ENDPOINT_###/http:\/\/%s\/api\/v1\/init\//g' /usr/share/nginx/html/index.html
sed -i 's/###_SHIPUPDATE_ENDPOINT_###/http:\/\/%s\/api\/v1\/update\//g' /usr/share/nginx/html/index.html
sed -i 's/###_SHIPEDIT_ENDPOINT_###/http:\/\/%s\/api\/v1\/edit\//g' /usr/share/nginx/html/index.html
sed -i 's/###_GITHUB_REDIRECT_URI_###/http:\/\/%s\/auth\/github\/callback/g' /usr/share/nginx/html/index.html
sed -i 's/###_GITHUB_INSTALL_URL_###/not-supportetd/g' /usr/share/nginx/html/index.html
sed -i 's/###_INSTALL_ENDPOINT_###/http:\/\/%s\/api\/install/g' /usr/share/nginx/html/index.html
nginx -g "daemon off;"`, deployOptions.Hostname, deployOptions.Hostname,
deployOptions.Hostname, deployOptions.Hostname, deployOptions.Hostname,
deployOptions.Hostname, deployOptions.Hostname, deployOptions.Hostname),
},
}
return configMap
}
func webDeployment(namespace string) *appsv1.Deployment {
deployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kotsadm-web",
Namespace: namespace,
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "kotsadm-web",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "kotsadm-web",
},
},
Spec: corev1.PodSpec{
Volumes: []corev1.Volume{
{
Name: "kotsadm-web-scripts",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
DefaultMode: &executableMode,
LocalObjectReference: corev1.LocalObjectReference{
Name: "kotsadm-web-scripts",
},
},
},
},
},
Containers: []corev1.Container{
{
Image: fmt.Sprintf("kotsadm/kotsadm-web:%s", kotsadmTag()),
ImagePullPolicy: corev1.PullAlways,
Name: "kotsadm-web",
Args: []string{
"/scripts/start-kotsadm-web.sh",
},
Ports: []corev1.ContainerPort{
{
Name: "http",
ContainerPort: 3000,
},
},
ReadinessProbe: &corev1.Probe{
FailureThreshold: 3,
InitialDelaySeconds: 2,
PeriodSeconds: 2,
SuccessThreshold: 1,
TimeoutSeconds: 1,
Handler: corev1.Handler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/healthz",
Port: intstr.FromInt(3000),
Scheme: corev1.URISchemeHTTP,
},
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "kotsadm-web-scripts",
MountPath: "/scripts/start-kotsadm-web.sh",
SubPath: "start-kotsadm-web.sh",
},
},
},
},
},
},
},
}
return deployment
}
func webService(deployOptions DeployOptions) *corev1.Service {
port := corev1.ServicePort{
Name: "http",
Port: 3000,
TargetPort: intstr.FromString("http"),
}
serviceType := corev1.ServiceTypeClusterIP
if deployOptions.ServiceType == "NodePort" {
serviceType = corev1.ServiceTypeNodePort
port.NodePort = int32(deployOptions.NodePort)
} else if deployOptions.ServiceType == "LoadBalancer" {
serviceType = corev1.ServiceTypeLoadBalancer
}
service := &corev1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Service",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kotsadm-web",
Namespace: deployOptions.Namespace,
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{
"app": "kotsadm-web",
},
Type: serviceType,
Ports: []corev1.ServicePort{
port,
},
},
}
return service
}