Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/proxy/service.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 proxy
6
7
import (
8
"fmt"
9
10
"github.com/gitpod-io/gitpod/common-go/baseserver"
11
"github.com/gitpod-io/gitpod/installer/pkg/common"
12
configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
13
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
14
15
corev1 "k8s.io/api/core/v1"
16
"k8s.io/apimachinery/pkg/runtime"
17
)
18
19
var allowedServiceTypes = map[corev1.ServiceType]struct{}{
20
corev1.ServiceTypeLoadBalancer: {},
21
corev1.ServiceTypeClusterIP: {},
22
corev1.ServiceTypeNodePort: {},
23
corev1.ServiceTypeExternalName: {},
24
}
25
26
func service(ctx *common.RenderContext) ([]runtime.Object, error) {
27
28
loadBalancerIP := ""
29
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
30
if cfg.WebApp != nil && cfg.WebApp.ProxyConfig != nil {
31
if cfg.WebApp.ProxyConfig.StaticIP != "" {
32
loadBalancerIP = cfg.WebApp.ProxyConfig.StaticIP
33
}
34
}
35
return nil
36
})
37
38
serviceType := corev1.ServiceTypeLoadBalancer
39
if ctx.Config.Components != nil && ctx.Config.Components.Proxy != nil && ctx.Config.Components.Proxy.Service != nil {
40
st := ctx.Config.Components.Proxy.Service.ServiceType
41
if st != nil {
42
_, allowed := allowedServiceTypes[corev1.ServiceType(*st)]
43
if allowed {
44
serviceType = *st
45
}
46
}
47
}
48
49
var annotations map[string]string
50
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
51
if cfg.WebApp != nil && cfg.WebApp.ProxyConfig != nil {
52
annotations = cfg.WebApp.ProxyConfig.ServiceAnnotations
53
}
54
return nil
55
})
56
57
ports := []common.ServicePort{
58
{
59
Name: ContainerHTTPName,
60
ContainerPort: ContainerHTTPPort,
61
ServicePort: ContainerHTTPPort,
62
},
63
{
64
Name: ContainerHTTPSName,
65
ContainerPort: ContainerHTTPSPort,
66
ServicePort: ContainerHTTPSPort,
67
},
68
{
69
Name: baseserver.BuiltinMetricsPortName,
70
ContainerPort: baseserver.BuiltinMetricsPort,
71
ServicePort: baseserver.BuiltinMetricsPort,
72
},
73
{
74
Name: ContainerAnalyticsName,
75
ContainerPort: ContainerAnalyticsPort,
76
ServicePort: ContainerAnalyticsPort,
77
},
78
{
79
Name: ContainerConfigcatName,
80
ContainerPort: ContainerConfigcatPort,
81
ServicePort: ContainerConfigcatPort,
82
},
83
}
84
if ctx.Config.SSHGatewayHostKey != nil {
85
ports = append(ports, common.ServicePort{
86
Name: ContainerSSHName,
87
ContainerPort: ContainerSSHPort,
88
ServicePort: ContainerSSHPort,
89
})
90
}
91
92
return common.GenerateService(Component, ports, func(service *corev1.Service) {
93
service.Spec.Type = serviceType
94
if serviceType == corev1.ServiceTypeLoadBalancer {
95
service.Spec.LoadBalancerIP = loadBalancerIP
96
97
installationShortNameSuffix := ""
98
if ctx.Config.Metadata.InstallationShortname != "" && ctx.Config.Metadata.InstallationShortname != configv1.InstallationShortNameOldDefault {
99
installationShortNameSuffix = "-" + ctx.Config.Metadata.InstallationShortname
100
}
101
102
service.Annotations["external-dns.alpha.kubernetes.io/hostname"] = fmt.Sprintf("%s,*.%s,*.ws%s.%s", ctx.Config.Domain, ctx.Config.Domain, installationShortNameSuffix, ctx.Config.Domain)
103
service.Annotations["cloud.google.com/neg"] = `{"exposed_ports": {"80":{},"443": {}}}`
104
}
105
106
for k, v := range annotations {
107
service.Annotations[k] = v
108
}
109
})(ctx)
110
}
111
112