Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/openvsx-proxy/statefulset.go
2501 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 openvsx_proxy
6
7
import (
8
"fmt"
9
10
appsv1 "k8s.io/api/apps/v1"
11
v1 "k8s.io/api/core/v1"
12
"k8s.io/apimachinery/pkg/api/resource"
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
"k8s.io/apimachinery/pkg/runtime"
15
"k8s.io/apimachinery/pkg/util/intstr"
16
"k8s.io/utils/pointer"
17
18
"github.com/gitpod-io/gitpod/common-go/baseserver"
19
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
20
"github.com/gitpod-io/gitpod/installer/pkg/common"
21
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
22
)
23
24
func statefulset(ctx *common.RenderContext) ([]runtime.Object, error) {
25
labels := common.CustomizeLabel(ctx, Component, common.TypeMetaStatefulSet)
26
// todo(sje): add redis
27
28
configHash, err := common.ObjectHash(configmap(ctx))
29
if err != nil {
30
return nil, err
31
}
32
33
volumeClaimTemplates := []v1.PersistentVolumeClaim{
34
{
35
ObjectMeta: metav1.ObjectMeta{
36
Name: "redis-data",
37
Labels: common.DefaultLabels(Component),
38
},
39
Spec: v1.PersistentVolumeClaimSpec{
40
AccessModes: []v1.PersistentVolumeAccessMode{
41
v1.ReadWriteOnce,
42
},
43
Resources: v1.VolumeResourceRequirements{
44
Requests: v1.ResourceList{
45
"storage": resource.MustParse("8Gi"),
46
},
47
},
48
},
49
},
50
}
51
52
volumes := []v1.Volume{
53
{
54
Name: "config",
55
VolumeSource: v1.VolumeSource{
56
ConfigMap: &v1.ConfigMapVolumeSource{
57
LocalObjectReference: v1.LocalObjectReference{Name: fmt.Sprintf("%s-config", Component)},
58
},
59
},
60
},
61
}
62
63
if ctx.Config.OpenVSX.Proxy != nil && ctx.Config.OpenVSX.Proxy.DisablePVC {
64
volumeClaimTemplates = nil
65
volumes = append(volumes, *common.NewEmptyDirVolume("redis-data"))
66
}
67
68
const redisContainerName = "redis"
69
70
var proxyEnvVars []v1.EnvVar
71
72
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
73
proxyConfig := cfg.WebApp.ProxySettings
74
if proxyConfig != nil {
75
proxyEnvVars = []v1.EnvVar{
76
{
77
Name: "HTTP_PROXY",
78
Value: proxyConfig.HttpProxy,
79
},
80
{
81
Name: "HTTPS_PROXY",
82
Value: proxyConfig.HttpsProxy,
83
},
84
{
85
Name: "NO_PROXY",
86
Value: proxyConfig.NoProxy,
87
},
88
}
89
}
90
return nil
91
})
92
93
return []runtime.Object{&appsv1.StatefulSet{
94
TypeMeta: common.TypeMetaStatefulSet,
95
ObjectMeta: metav1.ObjectMeta{
96
Name: Component,
97
Namespace: ctx.Namespace,
98
Labels: labels,
99
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
100
},
101
Spec: appsv1.StatefulSetSpec{
102
Selector: &metav1.LabelSelector{
103
MatchLabels: common.DefaultLabels(Component),
104
},
105
ServiceName: Component,
106
// todo(sje): receive config value
107
Replicas: common.Replicas(ctx, Component),
108
Template: v1.PodTemplateSpec{
109
ObjectMeta: metav1.ObjectMeta{
110
Name: Component,
111
Namespace: ctx.Namespace,
112
Labels: labels,
113
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap, func() map[string]string {
114
return map[string]string{
115
common.AnnotationConfigChecksum: configHash,
116
}
117
}),
118
},
119
Spec: v1.PodSpec{
120
Affinity: cluster.WithNodeAffinity(cluster.AffinityLabelIDE),
121
ServiceAccountName: Component,
122
EnableServiceLinks: pointer.Bool(false),
123
DNSPolicy: v1.DNSClusterFirst,
124
RestartPolicy: v1.RestartPolicyAlways,
125
TerminationGracePeriodSeconds: pointer.Int64(30),
126
Volumes: volumes,
127
Containers: []v1.Container{{
128
Name: Component,
129
Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.OpenVSXProxy.Version),
130
Args: []string{"/config/config.json"},
131
ReadinessProbe: &v1.Probe{
132
ProbeHandler: v1.ProbeHandler{
133
HTTPGet: &v1.HTTPGetAction{
134
Path: "/openvsx-proxy-status",
135
Port: intstr.IntOrString{IntVal: ContainerPort},
136
},
137
},
138
},
139
SecurityContext: &v1.SecurityContext{
140
AllowPrivilegeEscalation: pointer.Bool(false),
141
},
142
ImagePullPolicy: v1.PullIfNotPresent,
143
Resources: common.ResourceRequirements(ctx, Component, Component, v1.ResourceRequirements{
144
Requests: v1.ResourceList{
145
"cpu": resource.MustParse("1m"),
146
"memory": resource.MustParse("150Mi"),
147
},
148
}),
149
Ports: []v1.ContainerPort{{
150
Name: PortName,
151
ContainerPort: ContainerPort,
152
}, {
153
Name: baseserver.BuiltinMetricsPortName,
154
ContainerPort: baseserver.BuiltinMetricsPort,
155
}},
156
VolumeMounts: []v1.VolumeMount{{
157
Name: "config",
158
MountPath: "/config",
159
}},
160
Env: common.CustomizeEnvvar(ctx, Component, common.MergeEnv(
161
common.DefaultEnv(&ctx.Config),
162
common.ConfigcatEnv(ctx),
163
proxyEnvVars,
164
)),
165
}, {
166
Name: redisContainerName,
167
Image: ctx.ImageName(common.ThirdPartyContainerRepo(ctx.Config.Repository, common.DockerRegistryURL), "library/redis", "6.2"),
168
Command: []string{
169
"redis-server",
170
"/config/redis.conf",
171
},
172
Env: []v1.EnvVar{{
173
Name: "MASTER",
174
Value: "true",
175
}},
176
ImagePullPolicy: "IfNotPresent",
177
Ports: []v1.ContainerPort{{
178
ContainerPort: 6379,
179
}},
180
SecurityContext: &v1.SecurityContext{
181
AllowPrivilegeEscalation: pointer.Bool(false),
182
},
183
Resources: common.ResourceRequirements(ctx, Component, redisContainerName, v1.ResourceRequirements{
184
Requests: v1.ResourceList{
185
"cpu": resource.MustParse("1m"),
186
"memory": resource.MustParse("150Mi"),
187
},
188
}),
189
VolumeMounts: []v1.VolumeMount{{
190
Name: "config",
191
MountPath: "/config",
192
}, {
193
Name: "redis-data",
194
MountPath: "/data",
195
}},
196
}, *common.KubeRBACProxyContainer(ctx),
197
},
198
Tolerations: common.WithTolerationWorkspaceComponentNotReady(ctx),
199
},
200
},
201
VolumeClaimTemplates: volumeClaimTemplates,
202
}},
203
}, nil
204
}
205
206