Skip to content

[installer] support service type ClusterIP for proxy #10537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions install/installer/pkg/components/proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -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": {}}}`
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/config/v1/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions install/installer/pkg/config/v1/experimental/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand Down