Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/config/v1/experimental/validation.go
2501 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package experimental
6
7
import (
8
corev1 "k8s.io/api/core/v1"
9
10
"github.com/gitpod-io/gitpod/installer/pkg/cluster"
11
"github.com/go-playground/validator/v10"
12
)
13
14
var TracingSampleTypeList = map[TracingSampleType]struct{}{
15
TracingSampleTypeConst: {},
16
TracingSampleTypeProbabilistic: {},
17
TracingSampleTypeRateLimiting: {},
18
TracingSampleTypeRemote: {},
19
}
20
21
var ServiceTypeList = map[corev1.ServiceType]struct{}{
22
corev1.ServiceTypeLoadBalancer: {},
23
corev1.ServiceTypeClusterIP: {},
24
corev1.ServiceTypeNodePort: {},
25
corev1.ServiceTypeExternalName: {},
26
}
27
28
var ValidationChecks = map[string]validator.Func{
29
"tracing_sampler_type": func(fl validator.FieldLevel) bool {
30
_, ok := TracingSampleTypeList[TracingSampleType(fl.Field().String())]
31
return ok
32
},
33
"service_config_type": func(fl validator.FieldLevel) bool {
34
_, ok := ServiceTypeList[corev1.ServiceType(fl.Field().String())]
35
return ok
36
},
37
}
38
39
func ClusterValidation(cfg *Config) cluster.ValidationChecks {
40
if cfg == nil {
41
return nil
42
}
43
44
var res cluster.ValidationChecks
45
if cfg.Workspace != nil {
46
if scr := cfg.Workspace.RegistryFacade.RedisCache.PasswordSecret; scr != "" {
47
res = append(res, cluster.CheckSecret(scr, cluster.CheckSecretRequiredData("password")))
48
}
49
50
if cfg.Workspace.WorkspaceCIDR != "" {
51
res = append(res, cluster.CheckWorkspaceCIDR(cfg.Workspace.WorkspaceCIDR))
52
}
53
}
54
55
return res
56
}
57
58