Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/database/cloudsql/deployment.go
3604 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cloudsql
6
7
import (
8
"fmt"
9
10
"github.com/gitpod-io/gitpod/installer/pkg/common"
11
12
appsv1 "k8s.io/api/apps/v1"
13
corev1 "k8s.io/api/core/v1"
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
"k8s.io/apimachinery/pkg/runtime"
16
"k8s.io/apimachinery/pkg/util/intstr"
17
"k8s.io/utils/pointer"
18
)
19
20
func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
21
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaDeployment)
22
23
return []runtime.Object{
24
&appsv1.Deployment{
25
TypeMeta: common.TypeMetaDeployment,
26
ObjectMeta: metav1.ObjectMeta{
27
Name: fmt.Sprintf("%s-cloud-sql-proxy", Component),
28
Namespace: ctx.Namespace,
29
Labels: labels,
30
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
31
},
32
Spec: appsv1.DeploymentSpec{
33
Strategy: appsv1.DeploymentStrategy{
34
Type: appsv1.RollingUpdateDeploymentStrategyType,
35
RollingUpdate: &appsv1.RollingUpdateDeployment{
36
MaxUnavailable: &intstr.IntOrString{IntVal: 0},
37
MaxSurge: &intstr.IntOrString{IntVal: 1},
38
},
39
},
40
Selector: &metav1.LabelSelector{MatchLabels: common.DefaultLabels(Component)},
41
Replicas: common.Replicas(ctx, Component),
42
Template: corev1.PodTemplateSpec{
43
ObjectMeta: metav1.ObjectMeta{
44
Name: Component,
45
Namespace: ctx.Namespace,
46
Labels: labels,
47
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
48
},
49
Spec: corev1.PodSpec{
50
ServiceAccountName: Component,
51
EnableServiceLinks: pointer.Bool(false),
52
DNSPolicy: corev1.DNSClusterFirst,
53
RestartPolicy: corev1.RestartPolicyAlways,
54
TerminationGracePeriodSeconds: pointer.Int64(30),
55
Volumes: []corev1.Volume{{
56
Name: "cloudsql",
57
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
58
}, {
59
Name: "gcloud-sql-token",
60
VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{
61
SecretName: ctx.Config.Database.CloudSQL.ServiceAccount.Name,
62
}},
63
}},
64
Containers: []corev1.Container{{
65
Name: "cloud-sql-proxy",
66
SecurityContext: &corev1.SecurityContext{
67
Privileged: pointer.Bool(false),
68
RunAsNonRoot: pointer.Bool(false),
69
AllowPrivilegeEscalation: pointer.Bool(false),
70
},
71
Image: ctx.ImageName(ImageRepo, ImageName, ImageVersion),
72
Command: []string{
73
"/cloud_sql_proxy",
74
"-dir=/cloudsql",
75
fmt.Sprintf("-instances=%s=tcp:0.0.0.0:%d", ctx.Config.Database.CloudSQL.Instance, Port),
76
"-credential_file=/credentials/credentials.json",
77
},
78
Ports: []corev1.ContainerPort{{
79
ContainerPort: Port,
80
}},
81
VolumeMounts: []corev1.VolumeMount{{
82
MountPath: "/cloudsql",
83
Name: "cloudsql",
84
}, {
85
MountPath: "/credentials",
86
Name: "gcloud-sql-token",
87
}},
88
Env: common.CustomizeEnvvar(ctx, Component, []corev1.EnvVar{}),
89
}},
90
},
91
},
92
},
93
},
94
}, nil
95
}
96
97