Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/ide-metrics/deployment.go
2501 views
1
// Copyright (c) 2022 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 ide_metrics
6
7
import (
8
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
9
"github.com/gitpod-io/gitpod/installer/pkg/common"
10
11
appsv1 "k8s.io/api/apps/v1"
12
corev1 "k8s.io/api/core/v1"
13
"k8s.io/apimachinery/pkg/api/resource"
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
configHash, err := common.ObjectHash(configmap(ctx))
24
if err != nil {
25
return nil, err
26
}
27
28
volumes := make([]corev1.Volume, 0)
29
volumeMounts := make([]corev1.VolumeMount, 0)
30
31
volumes = append(volumes, corev1.Volume{
32
Name: VolumeConfig,
33
VolumeSource: corev1.VolumeSource{
34
ConfigMap: &corev1.ConfigMapVolumeSource{
35
LocalObjectReference: corev1.LocalObjectReference{Name: Component},
36
},
37
},
38
})
39
40
volumeMounts = append(volumeMounts, corev1.VolumeMount{
41
Name: VolumeConfig,
42
MountPath: "/config",
43
ReadOnly: true,
44
})
45
46
env := common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
47
common.DefaultEnv(&ctx.Config),
48
))
49
50
if ctx.Config.Components != nil && ctx.Config.Components.IDE != nil && ctx.Config.Components.IDE.Metrics != nil && ctx.Config.Components.IDE.Metrics.ErrorReportingEnabled {
51
env = append(env, corev1.EnvVar{
52
Name: "GITPOD_ENABLED_ERROR_REPORTING",
53
Value: "true",
54
})
55
}
56
57
return []runtime.Object{
58
&appsv1.Deployment{
59
TypeMeta: common.TypeMetaDeployment,
60
ObjectMeta: metav1.ObjectMeta{
61
Name: Component,
62
Namespace: ctx.Namespace,
63
Labels: labels,
64
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
65
},
66
Spec: appsv1.DeploymentSpec{
67
Selector: &metav1.LabelSelector{MatchLabels: common.DefaultLabels(Component)},
68
Replicas: common.Replicas(ctx, Component),
69
Strategy: common.DeploymentStrategy,
70
Template: corev1.PodTemplateSpec{
71
ObjectMeta: metav1.ObjectMeta{
72
Name: Component,
73
Namespace: ctx.Namespace,
74
Labels: labels,
75
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment, func() map[string]string {
76
return map[string]string{
77
common.AnnotationConfigChecksum: configHash,
78
}
79
}),
80
},
81
Spec: corev1.PodSpec{
82
Affinity: cluster.WithNodeAffinityHostnameAntiAffinity(Component, cluster.AffinityLabelMeta),
83
TopologySpreadConstraints: cluster.WithHostnameTopologySpread(Component),
84
ServiceAccountName: Component,
85
EnableServiceLinks: pointer.Bool(false),
86
DNSPolicy: corev1.DNSClusterFirst,
87
RestartPolicy: corev1.RestartPolicyAlways,
88
TerminationGracePeriodSeconds: pointer.Int64(30),
89
Containers: []corev1.Container{{
90
Args: []string{"run", "--config", "/config/config.json"},
91
Name: Component,
92
Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.IDEMetrics.Version),
93
ImagePullPolicy: corev1.PullIfNotPresent,
94
Resources: common.ResourceRequirements(ctx, Component, Component, corev1.ResourceRequirements{
95
Requests: corev1.ResourceList{
96
"cpu": resource.MustParse("100m"),
97
"memory": resource.MustParse("128Mi"),
98
},
99
}),
100
Ports: []corev1.ContainerPort{{
101
ContainerPort: ContainerPort,
102
Name: PortName,
103
}},
104
SecurityContext: &corev1.SecurityContext{
105
Privileged: pointer.Bool(false),
106
AllowPrivilegeEscalation: pointer.Bool(false),
107
},
108
Env: env,
109
VolumeMounts: volumeMounts,
110
ReadinessProbe: &corev1.Probe{
111
ProbeHandler: corev1.ProbeHandler{
112
TCPSocket: &corev1.TCPSocketAction{
113
Port: intstr.IntOrString{IntVal: ReadinessPort},
114
},
115
},
116
FailureThreshold: 3,
117
SuccessThreshold: 1,
118
TimeoutSeconds: 1,
119
},
120
},
121
*common.KubeRBACProxyContainerWithConfig(ctx),
122
},
123
Volumes: volumes,
124
Tolerations: common.WithTolerationWorkspaceComponentNotReady(ctx),
125
},
126
},
127
},
128
},
129
}, nil
130
}
131
132