From 12256e2e24b0b88c7410c289a1b94d0b57c5f6ba Mon Sep 17 00:00:00 2001 From: Nandaja Varma Date: Wed, 8 Jun 2022 13:34:08 +0000 Subject: [PATCH] [installer] support service type in experimental config --- .../installer/pkg/components/proxy/service.go | 28 ++++++++++++++++--- .../config/v1/experimental/experimental.go | 5 ++-- .../pkg/config/v1/experimental/validation.go | 13 +++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/install/installer/pkg/components/proxy/service.go b/install/installer/pkg/components/proxy/service.go index 452ad2855bb7af..8c3145a054f309 100644 --- a/install/installer/pkg/components/proxy/service.go +++ b/install/installer/pkg/components/proxy/service.go @@ -14,11 +14,29 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) +var allowedServiceTypes = map[corev1.ServiceType]struct{}{ + corev1.ServiceTypeLoadBalancer: {}, + corev1.ServiceTypeClusterIP: {}, + corev1.ServiceTypeNodePort: {}, + corev1.ServiceTypeExternalName: {}, +} + func service(ctx *common.RenderContext) ([]runtime.Object, error) { + serviceType := corev1.ServiceTypeLoadBalancer + loadBalancerIP := "" _ = ctx.WithExperimental(func(cfg *experimental.Config) error { - if cfg.WebApp != nil && cfg.WebApp.ProxyConfig != nil && cfg.WebApp.ProxyConfig.StaticIP != "" { - loadBalancerIP = cfg.WebApp.ProxyConfig.StaticIP + if cfg.WebApp != nil && cfg.WebApp.ProxyConfig != nil { + if cfg.WebApp.ProxyConfig.StaticIP != "" { + loadBalancerIP = cfg.WebApp.ProxyConfig.StaticIP + } + st := cfg.WebApp.ProxyConfig.ServiceType + if st != nil { + _, allowed := allowedServiceTypes[corev1.ServiceType(*st)] + if allowed { + serviceType = *st + } + } } return nil }) @@ -57,8 +75,10 @@ func service(ctx *common.RenderContext) ([]runtime.Object, error) { } return common.GenerateService(Component, ports, func(service *corev1.Service) { - service.Spec.Type = corev1.ServiceTypeLoadBalancer - service.Spec.LoadBalancerIP = loadBalancerIP + service.Spec.Type = serviceType + if serviceType == corev1.ServiceTypeLoadBalancer { + service.Spec.LoadBalancerIP = loadBalancerIP + } service.Annotations["external-dns.alpha.kubernetes.io/hostname"] = fmt.Sprintf("%s,*.%s,*.ws.%s", ctx.Config.Domain, ctx.Config.Domain, ctx.Config.Domain) service.Annotations["cloud.google.com/neg"] = `{"exposed_ports": {"80":{},"443": {}}}` diff --git a/install/installer/pkg/config/v1/experimental/experimental.go b/install/installer/pkg/config/v1/experimental/experimental.go index fe13f73128b449..38d87c766d7514 100644 --- a/install/installer/pkg/config/v1/experimental/experimental.go +++ b/install/installer/pkg/config/v1/experimental/experimental.go @@ -154,8 +154,9 @@ type BlockedRepository struct { } type ProxyConfig struct { - StaticIP string `json:"staticIP"` - ServiceAnnotations map[string]string `json:"serviceAnnotations"` + StaticIP string `json:"staticIP"` + ServiceAnnotations map[string]string `json:"serviceAnnotations"` + ServiceType *corev1.ServiceType `json:"serviceType,omitempty" validate:"omitempty,service_config_type"` } type PublicAPIConfig struct { diff --git a/install/installer/pkg/config/v1/experimental/validation.go b/install/installer/pkg/config/v1/experimental/validation.go index ec2528c770a0da..cfbaa4fbba2d71 100644 --- a/install/installer/pkg/config/v1/experimental/validation.go +++ b/install/installer/pkg/config/v1/experimental/validation.go @@ -5,6 +5,8 @@ package experimental import ( + corev1 "k8s.io/api/core/v1" + "github.com/gitpod-io/gitpod/installer/pkg/cluster" "github.com/go-playground/validator/v10" ) @@ -16,11 +18,22 @@ var TracingSampleTypeList = map[TracingSampleType]struct{}{ TracingSampleTypeRemote: {}, } +var ServiceTypeList = map[corev1.ServiceType]struct{}{ + corev1.ServiceTypeLoadBalancer: {}, + corev1.ServiceTypeClusterIP: {}, + corev1.ServiceTypeNodePort: {}, + corev1.ServiceTypeExternalName: {}, +} + var ValidationChecks = map[string]validator.Func{ "tracing_sampler_type": func(fl validator.FieldLevel) bool { _, ok := TracingSampleTypeList[TracingSampleType(fl.Field().String())] return ok }, + "service_config_type": func(fl validator.FieldLevel) bool { + _, ok := ServiceTypeList[corev1.ServiceType(fl.Field().String())] + return ok + }, } func ClusterValidation(cfg *Config) cluster.ValidationChecks {