Skip to content

Commit 8a4e416

Browse files
committed
add validation
1 parent f4c8cf3 commit 8a4e416

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package proxy
66

77
import (
88
"fmt"
9-
"strings"
109

1110
"github.com/gitpod-io/gitpod/installer/pkg/common"
1211
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
@@ -15,14 +14,22 @@ import (
1514
"k8s.io/apimachinery/pkg/runtime"
1615
)
1716

17+
var allowedServiceTypes = map[corev1.ServiceType]struct{}{
18+
corev1.ServiceTypeLoadBalancer: {},
19+
corev1.ServiceTypeClusterIP: {},
20+
corev1.ServiceTypeNodePort: {},
21+
corev1.ServiceTypeExternalName: {},
22+
}
23+
1824
func service(ctx *common.RenderContext) ([]runtime.Object, error) {
1925
serviceType := corev1.ServiceTypeLoadBalancer
2026
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
2127
if cfg.Common != nil && cfg.Common.ServiceConfig != nil {
2228
st, ok := cfg.Common.ServiceConfig["proxy"]
2329
if ok {
24-
if strings.ToLower(st.ServiceType) == "clusterip" {
25-
serviceType = corev1.ServiceTypeClusterIP
30+
_, allowed := allowedServiceTypes[corev1.ServiceType(*st.ServiceType)]
31+
if allowed {
32+
serviceType = *st.ServiceType
2633
}
2734
}
2835
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ type Config struct {
2424
}
2525

2626
type CommonConfig struct {
27-
PodConfig map[string]*PodConfig `json:"podConfig,omitempty"`
27+
PodConfig map[string]*PodConfig `json:"podConfig,omitempty"`
28+
// ServiceConfig is only supported for "proxy" service at the moment
2829
ServiceConfig map[string]*ServiceConfig `json:"serviceConfig,omitempty"`
2930
StaticMessagebusPassword string `json:"staticMessagebusPassword"`
3031
}
3132

3233
// ServiceConfig enables modification of type of service to `ClusterIP` if needed,
3334
// currently supported only for `proxy` service
3435
type ServiceConfig struct {
35-
ServiceType string `json:"serviceType,omitempty"`
36+
// Allowed values are: "ClusterIP", "LoadBalancer", "NodePort", "ExternalName"
37+
ServiceType *corev1.ServiceType `json:"serviceType,omitempty" validate:"omitempty,service_config_type"`
3638
}
3739

3840
type PodConfig 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)