Skip to content

Commit 12256e2

Browse files
committed
[installer] support service type in experimental config
1 parent c36ca91 commit 12256e2

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

install/installer/pkg/components/proxy/service.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,29 @@ import (
1414
"k8s.io/apimachinery/pkg/runtime"
1515
)
1616

17+
var allowedServiceTypes = map[corev1.ServiceType]struct{}{
18+
corev1.ServiceTypeLoadBalancer: {},
19+
corev1.ServiceTypeClusterIP: {},
20+
corev1.ServiceTypeNodePort: {},
21+
corev1.ServiceTypeExternalName: {},
22+
}
23+
1724
func service(ctx *common.RenderContext) ([]runtime.Object, error) {
25+
serviceType := corev1.ServiceTypeLoadBalancer
26+
1827
loadBalancerIP := ""
1928
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
20-
if cfg.WebApp != nil && cfg.WebApp.ProxyConfig != nil && cfg.WebApp.ProxyConfig.StaticIP != "" {
21-
loadBalancerIP = cfg.WebApp.ProxyConfig.StaticIP
29+
if cfg.WebApp != nil && cfg.WebApp.ProxyConfig != nil {
30+
if cfg.WebApp.ProxyConfig.StaticIP != "" {
31+
loadBalancerIP = cfg.WebApp.ProxyConfig.StaticIP
32+
}
33+
st := cfg.WebApp.ProxyConfig.ServiceType
34+
if st != nil {
35+
_, allowed := allowedServiceTypes[corev1.ServiceType(*st)]
36+
if allowed {
37+
serviceType = *st
38+
}
39+
}
2240
}
2341
return nil
2442
})
@@ -57,8 +75,10 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) {
5775
}
5876

5977
return common.GenerateService(Component, ports, func(service *corev1.Service) {
60-
service.Spec.Type = corev1.ServiceTypeLoadBalancer
61-
service.Spec.LoadBalancerIP = loadBalancerIP
78+
service.Spec.Type = serviceType
79+
if serviceType == corev1.ServiceTypeLoadBalancer {
80+
service.Spec.LoadBalancerIP = loadBalancerIP
81+
}
6282

6383
service.Annotations["external-dns.alpha.kubernetes.io/hostname"] = fmt.Sprintf("%s,*.%s,*.ws.%s", ctx.Config.Domain, ctx.Config.Domain, ctx.Config.Domain)
6484
service.Annotations["cloud.google.com/neg"] = `{"exposed_ports": {"80":{},"443": {}}}`

install/installer/pkg/config/v1/experimental/experimental.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ type BlockedRepository struct {
154154
}
155155

156156
type ProxyConfig struct {
157-
StaticIP string `json:"staticIP"`
158-
ServiceAnnotations map[string]string `json:"serviceAnnotations"`
157+
StaticIP string `json:"staticIP"`
158+
ServiceAnnotations map[string]string `json:"serviceAnnotations"`
159+
ServiceType *corev1.ServiceType `json:"serviceType,omitempty" validate:"omitempty,service_config_type"`
159160
}
160161

161162
type PublicAPIConfig struct {

install/installer/pkg/config/v1/experimental/validation.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
package experimental
66

77
import (
8+
corev1 "k8s.io/api/core/v1"
9+
810
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
911
"github.com/go-playground/validator/v10"
1012
)
@@ -16,11 +18,22 @@ var TracingSampleTypeList = map[TracingSampleType]struct{}{
1618
TracingSampleTypeRemote: {},
1719
}
1820

21+
var ServiceTypeList = map[corev1.ServiceType]struct{}{
22+
corev1.ServiceTypeLoadBalancer: {},
23+
corev1.ServiceTypeClusterIP: {},
24+
corev1.ServiceTypeNodePort: {},
25+
corev1.ServiceTypeExternalName: {},
26+
}
27+
1928
var ValidationChecks = map[string]validator.Func{
2029
"tracing_sampler_type": func(fl validator.FieldLevel) bool {
2130
_, ok := TracingSampleTypeList[TracingSampleType(fl.Field().String())]
2231
return ok
2332
},
33+
"service_config_type": func(fl validator.FieldLevel) bool {
34+
_, ok := ServiceTypeList[corev1.ServiceType(fl.Field().String())]
35+
return ok
36+
},
2437
}
2538

2639
func ClusterValidation(cfg *Config) cluster.ValidationChecks {

0 commit comments

Comments
 (0)