Skip to content

Commit 7f0a309

Browse files
author
Simon Emms
committed
[installer]: allow Installer to specify licensor type
Defaults to "gitpod" and allows "replicated". This is defined by the secret
1 parent 5d85a2d commit 7f0a309

File tree

3 files changed

+73
-18
lines changed

3 files changed

+73
-18
lines changed

install/installer/pkg/components/server/deployment.go

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/gitpod-io/gitpod/installer/pkg/common"
1414
wsmanager "github.com/gitpod-io/gitpod/installer/pkg/components/ws-manager"
1515
wsmanagerbridge "github.com/gitpod-io/gitpod/installer/pkg/components/ws-manager-bridge"
16+
configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
1617

1718
appsv1 "k8s.io/api/apps/v1"
1819
corev1 "k8s.io/api/core/v1"
@@ -53,7 +54,6 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
5354
Name: "gitpod-license-key",
5455
MountPath: licenseFilePath,
5556
SubPath: "license",
56-
ReadOnly: true,
5757
})
5858
}
5959

@@ -164,22 +164,47 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
164164
common.TracingEnv(ctx),
165165
common.AnalyticsEnv(&ctx.Config),
166166
common.MessageBusEnv(&ctx.Config),
167-
[]corev1.EnvVar{{
168-
Name: "CONFIG_PATH",
169-
Value: "/config/config.json",
170-
}, {
171-
Name: "IDE_CONFIG_PATH",
172-
Value: "/ide-config/config.json",
173-
}, {
174-
Name: "NODE_ENV",
175-
Value: "production", // todo(sje): will we need to change this?
176-
}, {
177-
Name: "SHLVL",
178-
Value: "1",
179-
}, {
180-
Name: "WSMAN_CFG_MANAGERS",
181-
Value: wsmanCfgManager,
182-
}},
167+
[]corev1.EnvVar{
168+
{
169+
Name: "CONFIG_PATH",
170+
Value: "/config/config.json",
171+
},
172+
func() corev1.EnvVar {
173+
envvar := corev1.EnvVar{
174+
Name: "GITPOD_LICENSE_TYPE",
175+
}
176+
177+
if ctx.Config.License == nil {
178+
envvar.Value = string(configv1.LicensorTypeGitpod)
179+
} else {
180+
envvar.ValueFrom = &corev1.EnvVarSource{
181+
SecretKeyRef: &corev1.SecretKeySelector{
182+
LocalObjectReference: corev1.LocalObjectReference{Name: ctx.Config.License.Name},
183+
Key: "type",
184+
Optional: pointer.Bool(true),
185+
},
186+
}
187+
}
188+
189+
return envvar
190+
}(),
191+
{
192+
Name: "IDE_CONFIG_PATH",
193+
Value: "/ide-config/config.json",
194+
},
195+
{
196+
Name: "NODE_ENV",
197+
Value: "production", // todo(sje): will we need to change this?
198+
},
199+
{
200+
Name: "SHLVL",
201+
Value: "1",
202+
},
203+
{
204+
Name: "WSMAN_CFG_MANAGERS",
205+
Value: wsmanCfgManager,
206+
},
207+
},
183208
),
184209
// todo(sje): conditionally add github-app-cert-secret in
185210
// todo(sje): do we need to cater for serverContainer.volumeMounts from values.yaml?

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ type Workspace struct {
229229
Templates *WorkspaceTemplates `json:"templates,omitempty"`
230230
}
231231

232+
type LicensorType string
233+
234+
const (
235+
LicensorTypeGitpod LicensorType = "gitpod"
236+
LicensorTypeReplicated LicensorType = "replicated"
237+
)
238+
232239
type FSShiftMethod string
233240

234241
const (

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ var FSShiftMethodList = map[FSShiftMethod]struct{}{
4141
FSShiftShiftFS: {},
4242
}
4343

44+
var LicensorTypeList = map[LicensorType]struct{}{
45+
LicensorTypeGitpod: {},
46+
LicensorTypeReplicated: {},
47+
}
48+
4449
// LoadValidationFuncs load custom validation functions for this version of the config API
4550
func (v version) LoadValidationFuncs(validate *validator.Validate) error {
4651
funcs := map[string]validator.Func{
@@ -120,7 +125,25 @@ func (v version) ClusterValidation(rcfg interface{}) cluster.ValidationChecks {
120125

121126
if cfg.License != nil {
122127
secretName := cfg.License.Name
123-
res = append(res, cluster.CheckSecret(secretName, cluster.CheckSecretRequiredData("license")))
128+
licensorKey := "type"
129+
res = append(res, cluster.CheckSecret(secretName, cluster.CheckSecretRequiredData("license"), cluster.CheckSecretRecommendedData(licensorKey), cluster.CheckSecretRule(func(s *corev1.Secret) ([]cluster.ValidationError, error) {
130+
errors := make([]cluster.ValidationError, 0)
131+
132+
licensor := LicensorType(s.Data[licensorKey])
133+
if licensor != "" {
134+
// This field is optional, so blank is valid
135+
_, ok := LicensorTypeList[licensor]
136+
137+
if !ok {
138+
errors = append(errors, cluster.ValidationError{
139+
Message: fmt.Sprintf("Secret '%s' has invalid license type '%s'", secretName, licensor),
140+
Type: cluster.ValidationStatusError,
141+
})
142+
}
143+
}
144+
145+
return errors, nil
146+
})))
124147
}
125148

126149
if len(cfg.AuthProviders) > 0 {

0 commit comments

Comments
 (0)