Skip to content

Commit 4e651ec

Browse files
committed
add validation
1 parent f4c8cf3 commit 4e651ec

File tree

4 files changed

+78
-11
lines changed

4 files changed

+78
-11
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/config.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Config defines the v1 version structure of the gitpod config file
99
|`kind`|string|N| `Meta`, `Workspace`, `Full` ||
1010
|`domain`|string|Y| | The domain to deploy to|
1111
|`metadata.region`|string|Y| | Location for your objectStorage provider|
12+
|`metadata.shortname`|string|N| | InstallationShortname establishes the "identity" of the (application) cluster.|
1213
|`repository`|string|Y| ||
1314
|`observability.logLevel`|string|N| `trace`, `debug`, `info`, `warning`, `error`, `fatal`, `panic` |Taken from github.com/gitpod-io/gitpod/components/gitpod-protocol/src/util/logging.ts|
1415
|`observability.tracing.endpoint`|string|N| ||
@@ -25,11 +26,17 @@ Config defines the v1 version structure of the gitpod config file
2526
|`objectStorage.s3.endpoint`|string|Y| ||
2627
|`objectStorage.s3.credentials.kind`|string|N| `secret` ||
2728
|`objectStorage.s3.credentials.name`|string|Y| ||
29+
|`objectStorage.s3.bucket`|string|N| | BucketName sets the name of an existing bucket to enable the "single bucket mode" If no name is configured, the old "one bucket per user" behaviour kicks in.|
2830
|`objectStorage.cloudStorage.serviceAccount.kind`|string|N| `secret` ||
2931
|`objectStorage.cloudStorage.serviceAccount.name`|string|Y| ||
3032
|`objectStorage.cloudStorage.project`|string|Y| ||
3133
|`objectStorage.azure.credentials.kind`|string|N| `secret` ||
3234
|`objectStorage.azure.credentials.name`|string|Y| ||
35+
|`objectStorage.maximumBackupCount`|int|N| ||
36+
|`objectStorage.blobQuota`|int64|N| ||
37+
|`objectStorage.resources.requests`||Y| | todo(sje): add custom validation to corev1.ResourceList|
38+
|`objectStorage.resources.limits`||N| ||
39+
|`objectStorage.resources.dynamicLimits`||N| ||
3340
|`containerRegistry.inCluster`|bool|Y| ||
3441
|`containerRegistry.external.url`|string|Y| ||
3542
|`containerRegistry.external.certificate.kind`|string|N| `secret` ||
@@ -49,10 +56,11 @@ Config defines the v1 version structure of the gitpod config file
4956
|`workspace.resources.dynamicLimits`||N| ||
5057
|`workspace.templates.default`||N| ||
5158
|`workspace.templates.prebuild`||N| ||
52-
|`workspace.templates.ghost`||N| ||
5359
|`workspace.templates.imagebuild`||N| ||
5460
|`workspace.templates.regular`||N| ||
55-
|`workspace.templates.probe`||N| ||
61+
|`workspace.pvc.size`||Y| | Size is a size of persistent volume claim to use|
62+
|`workspace.pvc.storageClass`|string|N| | StorageClass is a storage class of persistent volume claim to use|
63+
|`workspace.pvc.snapshotClass`|string|N| | SnapshotClass is a snapshot class name that is used to create volume snapshot|
5664
|`workspace.maxLifetime`||Y| | MaxLifetime is the maximum time a workspace is allowed to run. After that, the workspace times out despite activity|
5765
|`workspace.timeoutDefault`||N| | TimeoutDefault is the default timeout of a regular workspace|
5866
|`workspace.timeoutExtended`||N| | TimeoutExtended is the workspace timeout that a user can extend to for one workspace|
@@ -67,6 +75,9 @@ Config defines the v1 version structure of the gitpod config file
6775
|`sshGatewayHostKey.kind`|string|N| `secret` ||
6876
|`sshGatewayHostKey.name`|string|Y| ||
6977
|`disableDefinitelyGp`|bool|N| ||
78+
|`customCACert.kind`|string|N| `secret` ||
79+
|`customCACert.name`|string|Y| ||
80+
|`dropImageRepo`|bool|N| ||
7081
|`apiVersion`|string|Y| |API version of the Gitpod config defintion. `v1` in this version of Config|
7182

7283

@@ -81,8 +92,42 @@ Additional config parameters that are in experimental state
8192
|`experimental.workspace.tracing.samplerParam`|float64|N| ||
8293
|`experimental.workspace.stage`|string|N| ||
8394
|`experimental.workspace.stage`|string|N| ||
95+
|`experimental.workspace.ioLimits`||N| ||
8496
|`experimental.workspace.registryFacade`||N| ||
85-
|`experimental.webapp`|WebAppConfig|N| ||
86-
|`experimental.ide`|IDEConfig|N| ||
87-
88-
97+
|`experimental.workspace.classes`||N| ||
98+
|`experimental.webapp.publicApi.enabled`|bool|N| ||
99+
|`experimental.webapp.server.workspaceDefaults.workspaceImage`|string|N| ||
100+
|`experimental.webapp.server.oauthServer.jwtSecret`|string|N| ||
101+
|`experimental.webapp.server.session.secret`|string|N| ||
102+
|`experimental.webapp.server.githubApp.appId`|int32|N| ||
103+
|`experimental.webapp.server.githubApp.authProviderId`|string|N| ||
104+
|`experimental.webapp.server.githubApp.baseUrl`|string|N| ||
105+
|`experimental.webapp.server.githubApp.certPath`|string|N| ||
106+
|`experimental.webapp.server.githubApp.enabled`|bool|N| ||
107+
|`experimental.webapp.server.githubApp.logLevel`|string|N| ||
108+
|`experimental.webapp.server.githubApp.marketplaceName`|string|N| ||
109+
|`experimental.webapp.server.githubApp.webhookSecret`|string|N| ||
110+
|`experimental.webapp.server.githubApp.certSecretName`|string|N| ||
111+
|`experimental.webapp.server.chargebeeSecret`|string|N| ||
112+
|`experimental.webapp.server.stripeSecret`|string|N| ||
113+
|`experimental.webapp.server.disableDynamicAuthProviderLogin`|bool|N| ||
114+
|`experimental.webapp.server.enableLocalApp`|bool|N| ||
115+
|`experimental.webapp.server.runDbDeleter`|bool|N| ||
116+
|`experimental.webapp.server.defaultBaseImageRegistryWhitelist[ ]`|[]string|N| ||
117+
|`experimental.webapp.server.disableWorkspaceGarbageCollection`|bool|N| ||
118+
|`experimental.webapp.server.blockedRepositories[ ].urlRegExp`|string|N| ||
119+
|`experimental.webapp.server.blockedRepositories[ ].blockUser`|bool|N| ||
120+
|`experimental.webapp.proxy.staticIP`|string|N| ||
121+
|`experimental.webapp.proxy.serviceAnnotations`||N| ||
122+
|`experimental.webapp.wsManagerBridge.skipSelf`|bool|N| ||
123+
|`experimental.webapp.tracing.samplerType`|string|N| `const`, `probabilistic`, `rateLimiting`, `remote` |Values taken from https://github.com/jaegertracing/jaeger-client-go/blob/967f9c36f0fa5a2617c9a0993b03f9a3279fadc8/config/config.go#L71|
124+
|`experimental.webapp.tracing.samplerParam`|float64|N| ||
125+
|`experimental.webapp.usePodAntiAffinity`|bool|N| ||
126+
|`experimental.webapp.disableMigration`|bool|N| ||
127+
|`experimental.webapp.usage.enabled`|bool|N| ||
128+
|`experimental.ide.resolveLatest`|bool|N| | Disable resolution of latest images and use bundled latest versions instead|
129+
|`experimental.ide.ideProxy.serviceAnnotations`||N| ||
130+
|`experimental.ide.openvsxProxy.serviceAnnotations`||N| ||
131+
|`experimental.common.podConfig`||N| ||
132+
|`experimental.common.serviceConfig`||N| | ServiceConfig is only supported for "proxy" service at the moment|
133+
|`experimental.common.staticMessagebusPassword`|string|N| ||

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)