forked from openshift/console-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_builder.go
More file actions
665 lines (592 loc) · 21.1 KB
/
config_builder.go
File metadata and controls
665 lines (592 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
package consoleserver
import (
"os"
"path"
"strings"
configv1 "github.com/openshift/api/config/v1"
v1 "github.com/openshift/api/console/v1"
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/console-operator/pkg/api"
authconfigsub "github.com/openshift/console-operator/pkg/console/subresource/authentication"
"github.com/openshift/console-operator/pkg/console/subresource/util"
"gopkg.in/yaml.v2"
authorizationv1 "k8s.io/api/authorization/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"
)
const (
clientSecretFilePath = "/var/oauth-config/clientSecret"
oauthServingCertFilePath = "/var/oauth-serving-cert/ca-bundle.crt"
// serving info
certFilePath = "/var/serving-cert/tls.crt"
keyFilePath = "/var/serving-cert/tls.key"
)
// SupportedLightspeedArchitectures defines the list of architectures that support Lightspeed.
// Currently only amd64 is supported, but this can be expanded in the future.
var SupportedLightspeedArchitectures = []string{"amd64"}
// ConsoleServerCLIConfigBuilder
// Director will be DefaultConfigMap()
//
// b := ConsoleYamlConfigBuilder{}
// return the default config value immediately:
//
// b.Config()
// b.ConfigYAML()
//
// set all the values:
//
// b.Host(host).LogoutURL("").Brand("").DocURL("").APIServerURL("").Config()
//
// set only some values:
//
// b.Host().Brand("").Config()
type ConsoleServerCLIConfigBuilder struct {
host string
logoutRedirectURL string
brand operatorv1.Brand
docURL string
apiServerURL string
controlPlaneToplogy configv1.TopologyMode
statusPageID string
customProductName string
devCatalogCustomization operatorv1.DeveloperConsoleCatalogCustomization
projectAccess operatorv1.ProjectAccess
quickStarts operatorv1.QuickStarts
addPage operatorv1.AddPage
perspectives []operatorv1.Perspective
CAFile string
monitoring map[string]string
customHostnameRedirectPort int
inactivityTimeoutSeconds int
pluginsList map[string]string
pluginsOrder []string
i18nNamespaceList []string
proxyServices []ProxyService
telemetry map[string]string
releaseVersion string
nodeArchitectures []string
nodeOperatingSystems []string
copiedCSVsDisabled bool
oauthClientID string
oidcExtraScopes []string
oidcIssuerURL string
oidcOCLoginCommand string
authType string
sessionEncryptionFile string
sessionAuthenticationFile string
capabilities []operatorv1.Capability
contentSecurityPolicyList map[v1.DirectiveType][]string
logos []operatorv1.Logo
techPreviewEnabled bool
}
func (b *ConsoleServerCLIConfigBuilder) Host(host string) *ConsoleServerCLIConfigBuilder {
b.host = host
return b
}
func (b *ConsoleServerCLIConfigBuilder) LogoutURL(logoutRedirectURL string) *ConsoleServerCLIConfigBuilder {
b.logoutRedirectURL = logoutRedirectURL
return b
}
func (b *ConsoleServerCLIConfigBuilder) Brand(brand operatorv1.Brand) *ConsoleServerCLIConfigBuilder {
b.brand = brand
return b
}
func (b *ConsoleServerCLIConfigBuilder) DocURL(docURL string) *ConsoleServerCLIConfigBuilder {
b.docURL = docURL
return b
}
func (b *ConsoleServerCLIConfigBuilder) APIServerURL(apiServerURL string) *ConsoleServerCLIConfigBuilder {
b.apiServerURL = apiServerURL
return b
}
func (b *ConsoleServerCLIConfigBuilder) TopologyMode(topologyMode configv1.TopologyMode) *ConsoleServerCLIConfigBuilder {
b.controlPlaneToplogy = topologyMode
return b
}
func (b *ConsoleServerCLIConfigBuilder) CustomProductName(customProductName string) *ConsoleServerCLIConfigBuilder {
b.customProductName = customProductName
return b
}
func (b *ConsoleServerCLIConfigBuilder) CustomDeveloperCatalog(devCatalogCustomization operatorv1.DeveloperConsoleCatalogCustomization) *ConsoleServerCLIConfigBuilder {
b.devCatalogCustomization = devCatalogCustomization
return b
}
func (b *ConsoleServerCLIConfigBuilder) ProjectAccess(projectAccess operatorv1.ProjectAccess) *ConsoleServerCLIConfigBuilder {
b.projectAccess = projectAccess
return b
}
func (b *ConsoleServerCLIConfigBuilder) QuickStarts(quickStarts operatorv1.QuickStarts) *ConsoleServerCLIConfigBuilder {
b.quickStarts = quickStarts
return b
}
func (b *ConsoleServerCLIConfigBuilder) AddPage(addPage operatorv1.AddPage) *ConsoleServerCLIConfigBuilder {
b.addPage = addPage
return b
}
func (b *ConsoleServerCLIConfigBuilder) Perspectives(perspectives []operatorv1.Perspective) *ConsoleServerCLIConfigBuilder {
b.perspectives = perspectives
return b
}
// TODO Remove deprecated CustomLogoFile API.
func (b *ConsoleServerCLIConfigBuilder) CustomLogoFile(customLogoFile configv1.ConfigMapFileReference) *ConsoleServerCLIConfigBuilder {
if customLogoFile.Key != "" && customLogoFile.Name != "" {
configMapReference := operatorv1.ConfigMapFileReference(customLogoFile)
b.logos = []operatorv1.Logo{
{
Type: operatorv1.LogoTypeMasthead,
Themes: []operatorv1.Theme{
{
Mode: operatorv1.ThemeModeDark,
Source: operatorv1.FileReferenceSource{
From: "ConfigMap",
ConfigMap: &configMapReference,
},
},
{
Mode: operatorv1.ThemeModeLight,
Source: operatorv1.FileReferenceSource{
From: "ConfigMap",
ConfigMap: &configMapReference,
},
},
},
},
}
}
return b
}
// Update/replace this function
func (b *ConsoleServerCLIConfigBuilder) CustomLogos(customLogos []operatorv1.Logo) *ConsoleServerCLIConfigBuilder {
if len(customLogos) > 0 {
b.logos = customLogos
}
return b
}
func (b *ConsoleServerCLIConfigBuilder) CustomHostnameRedirectPort(redirect bool) *ConsoleServerCLIConfigBuilder {
// If custom hostname is set on the console operator config,
// set the port under which the console backend will listen
// for redirect.
if redirect {
b.customHostnameRedirectPort = api.RedirectContainerTargetPort
}
return b
}
func (b *ConsoleServerCLIConfigBuilder) StatusPageID(id string) *ConsoleServerCLIConfigBuilder {
b.statusPageID = id
return b
}
func (b *ConsoleServerCLIConfigBuilder) Capabilities(capabilities []operatorv1.Capability) *ConsoleServerCLIConfigBuilder {
b.capabilities = capabilities
return b
}
func (b *ConsoleServerCLIConfigBuilder) AuthConfig(authnConfig *configv1.Authentication, apiServerURL string) *ConsoleServerCLIConfigBuilder {
switch authnConfig.Spec.Type {
// We don't disable auth since the internal OAuth server is not disabled even with auth type 'None'.
case "", configv1.AuthenticationTypeIntegratedOAuth, configv1.AuthenticationTypeNone:
b.authType = "openshift"
b.oauthClientID = api.OAuthClientName
b.CAFile = oauthServingCertFilePath
return b
case configv1.AuthenticationTypeOIDC:
if len(authnConfig.Spec.OIDCProviders) == 0 {
b.authType = "disabled"
return b
}
oidcProvider, oidcConfig := authconfigsub.GetOIDCClientConfig(authnConfig, api.TargetNamespace, api.OpenShiftConsoleName)
if oidcConfig == nil {
b.authType = "disabled"
return b
}
b.authType = "oidc"
b.oidcIssuerURL = oidcProvider.Issuer.URL
b.oauthClientID = oidcConfig.ClientID
b.oidcExtraScopes = oidcConfig.ExtraScopes
b.oidcOCLoginCommand = authconfigsub.GetOIDCOCLoginCommand(authnConfig, apiServerURL)
b.sessionAuthenticationFile = "/var/session-secret/sessionAuthenticationKey"
b.sessionEncryptionFile = "/var/session-secret/sessionEncryptionKey"
if len(oidcProvider.Issuer.CertificateAuthority.Name) > 0 {
b.CAFile = path.Join(api.AuthServerCAMountDir, api.AuthServerCAFileName)
}
}
return b
}
func (b *ConsoleServerCLIConfigBuilder) Monitoring(monitoringConfig *corev1.ConfigMap) *ConsoleServerCLIConfigBuilder {
if monitoringConfig != nil {
b.monitoring = monitoringConfig.Data
}
return b
}
func (b *ConsoleServerCLIConfigBuilder) InactivityTimeout(timeout int) *ConsoleServerCLIConfigBuilder {
b.inactivityTimeoutSeconds = timeout
return b
}
func (b *ConsoleServerCLIConfigBuilder) Plugins(plugins map[string]string) *ConsoleServerCLIConfigBuilder {
b.pluginsList = plugins
return b
}
func (b *ConsoleServerCLIConfigBuilder) PluginsOrder(availablePlugins []*v1.ConsolePlugin, consoleConfig *operatorv1.Console) *ConsoleServerCLIConfigBuilder {
// Build a fast lookup set of available plugin names
availableSet := map[string]struct{}{}
for _, plugin := range availablePlugins {
if plugin == nil {
continue
}
availableSet[plugin.ObjectMeta.Name] = struct{}{}
}
// Preserve the order from consoleConfig.Spec.Plugins, but include only those
// plugins that are actually available on the cluster.
ordered := []string{}
for _, name := range consoleConfig.Spec.Plugins {
if _, ok := availableSet[name]; ok {
ordered = append(ordered, name)
}
}
b.pluginsOrder = ordered
return b
}
func (b *ConsoleServerCLIConfigBuilder) ContentSecurityPolicies(cspList map[v1.DirectiveType][]string) *ConsoleServerCLIConfigBuilder {
b.contentSecurityPolicyList = cspList
return b
}
func (b *ConsoleServerCLIConfigBuilder) I18nNamespaces(i18nNamespaces []string) *ConsoleServerCLIConfigBuilder {
b.i18nNamespaceList = i18nNamespaces
return b
}
func (b *ConsoleServerCLIConfigBuilder) Proxy(proxyServices []ProxyService) *ConsoleServerCLIConfigBuilder {
b.proxyServices = proxyServices
return b
}
func (b *ConsoleServerCLIConfigBuilder) TelemetryConfiguration(telemetry map[string]string) *ConsoleServerCLIConfigBuilder {
b.telemetry = telemetry
return b
}
func (b *ConsoleServerCLIConfigBuilder) ReleaseVersion() *ConsoleServerCLIConfigBuilder {
b.releaseVersion = os.Getenv("OPERATOR_IMAGE_VERSION")
return b
}
func (b *ConsoleServerCLIConfigBuilder) NodeArchitectures(architectures []string) *ConsoleServerCLIConfigBuilder {
b.nodeArchitectures = architectures
return b
}
func (b *ConsoleServerCLIConfigBuilder) NodeOperatingSystems(operatingSystems []string) *ConsoleServerCLIConfigBuilder {
b.nodeOperatingSystems = operatingSystems
return b
}
func (b *ConsoleServerCLIConfigBuilder) CopiedCSVsDisabled(copiedCSVsDisabled bool) *ConsoleServerCLIConfigBuilder {
b.copiedCSVsDisabled = copiedCSVsDisabled
return b
}
func (b *ConsoleServerCLIConfigBuilder) TechPreviewEnabled(techPreviewEnabled bool) *ConsoleServerCLIConfigBuilder {
b.techPreviewEnabled = techPreviewEnabled
return b
}
func (b *ConsoleServerCLIConfigBuilder) Config() Config {
return Config{
Kind: "ConsoleConfig",
APIVersion: "console.openshift.io/v1",
Auth: b.auth(),
Session: b.session(),
ClusterInfo: b.clusterInfo(),
Customization: b.customization(),
ServingInfo: b.servingInfo(),
Providers: b.providers(),
MonitoringInfo: b.monitoringInfo(),
Plugins: b.plugins(),
PluginsOrder: b.getPluginsOrder(),
I18nNamespaces: b.i18nNamespaces(),
Proxy: b.proxy(),
ContentSecurityPolicy: b.contentSecurityPolicy(),
Telemetry: b.telemetry,
}
}
func (b *ConsoleServerCLIConfigBuilder) ConfigYAML() (consoleConfigYAML []byte, marshallError error) {
conf := b.Config()
yml, err := yaml.Marshal(conf)
if err != nil {
klog.V(4).Infof("could not create config yaml %v", err)
return nil, err
}
return yml, nil
}
func (b *ConsoleServerCLIConfigBuilder) servingInfo() ServingInfo {
conf := ServingInfo{
BindAddress: "https://[::]:8443",
CertFile: certFilePath,
KeyFile: keyFilePath,
}
if b.customHostnameRedirectPort != 0 {
conf.RedirectPort = b.customHostnameRedirectPort
}
return conf
}
func (b *ConsoleServerCLIConfigBuilder) clusterInfo() ClusterInfo {
conf := ClusterInfo{
ConsoleBasePath: "",
}
if len(b.apiServerURL) > 0 {
conf.MasterPublicURL = b.apiServerURL
}
if len(b.host) > 0 {
conf.ConsoleBaseAddress = util.HTTPS(b.host)
}
if len(b.controlPlaneToplogy) > 0 {
conf.ControlPlaneToplogy = b.controlPlaneToplogy
}
if len(b.releaseVersion) > 0 {
conf.ReleaseVersion = b.releaseVersion
}
if len(b.nodeArchitectures) > 0 {
conf.NodeArchitectures = b.nodeArchitectures
}
if len(b.nodeOperatingSystems) > 0 {
conf.NodeOperatingSystems = b.nodeOperatingSystems
}
conf.CopiedCSVsDisabled = b.copiedCSVsDisabled
conf.TechPreviewEnabled = b.techPreviewEnabled
return conf
}
func (b *ConsoleServerCLIConfigBuilder) monitoringInfo() MonitoringInfo {
conf := MonitoringInfo{}
if len(b.monitoring) == 0 {
return conf
}
m, err := yaml.Marshal(b.monitoring)
if err != nil {
return conf
}
var monitoringInfo MonitoringInfo
err = yaml.Unmarshal(m, &monitoringInfo)
if err != nil {
return conf
}
if len(monitoringInfo.AlertmanagerUserWorkloadHost) > 0 {
conf.AlertmanagerUserWorkloadHost = monitoringInfo.AlertmanagerUserWorkloadHost
}
if len(monitoringInfo.AlertmanagerTenancyHost) > 0 {
conf.AlertmanagerTenancyHost = monitoringInfo.AlertmanagerTenancyHost
}
return conf
}
func (b *ConsoleServerCLIConfigBuilder) auth() Auth {
clientID := api.OAuthClientName
if clientIDOverride := b.oauthClientID; len(clientIDOverride) > 0 {
clientID = clientIDOverride
}
conf := Auth{
AuthType: b.authType,
OIDCIssuer: b.oidcIssuerURL,
ClientID: clientID,
ClientSecretFile: clientSecretFilePath,
OAuthEndpointCAFile: b.CAFile,
InactivityTimeoutSeconds: b.inactivityTimeoutSeconds,
OIDCExtraScopes: b.oidcExtraScopes,
OIDCOCLoginCommand: b.oidcOCLoginCommand,
}
if len(b.logoutRedirectURL) > 0 {
conf.LogoutRedirect = b.logoutRedirectURL
}
return conf
}
func (b *ConsoleServerCLIConfigBuilder) session() Session {
conf := Session{
CookieAuthenticationKeyFile: b.sessionAuthenticationFile,
CookieEncryptionKeyFile: b.sessionEncryptionFile,
}
return conf
}
func (b *ConsoleServerCLIConfigBuilder) customization() Customization {
conf := Customization{}
if len(b.brand) > 0 {
// lowercase all the brands to match the original/legacy
// branding names which are lowercased. Check:
// https://github.com/openshift/api/pull/1494
conf.Branding = strings.ToLower(string(b.brand))
}
if len(b.docURL) > 0 {
conf.DocumentationBaseURL = b.docURL
}
if len(b.customProductName) > 0 {
conf.CustomProductName = b.customProductName
}
if len(b.logos) > 0 {
conf.Logos = b.logos
}
if b.devCatalogCustomization.Categories != nil {
if conf.DeveloperCatalog == nil {
conf.DeveloperCatalog = &DeveloperConsoleCatalogCustomization{}
}
categories := make([]DeveloperConsoleCatalogCategory, len(b.devCatalogCustomization.Categories))
mapMeta := func(meta operatorv1.DeveloperConsoleCatalogCategoryMeta) DeveloperConsoleCatalogCategoryMeta {
return DeveloperConsoleCatalogCategoryMeta{
ID: meta.ID,
Label: meta.Label,
Tags: meta.Tags,
}
}
for categoryIndex, category := range b.devCatalogCustomization.Categories {
var subcategories []DeveloperConsoleCatalogCategoryMeta = nil
if category.Subcategories != nil {
subcategories = make([]DeveloperConsoleCatalogCategoryMeta, len(category.Subcategories))
for subcategoryIndex, subcategory := range category.Subcategories {
subcategories[subcategoryIndex] = mapMeta(subcategory)
}
}
categories[categoryIndex] = DeveloperConsoleCatalogCategory{
DeveloperConsoleCatalogCategoryMeta: mapMeta(category.DeveloperConsoleCatalogCategoryMeta),
Subcategories: subcategories,
}
}
conf.DeveloperCatalog.Categories = &categories
}
if (b.devCatalogCustomization.Types != operatorv1.DeveloperConsoleCatalogTypes{} && b.devCatalogCustomization.Types.State != "") {
if conf.DeveloperCatalog == nil {
conf.DeveloperCatalog = &DeveloperConsoleCatalogCustomization{}
}
conf.DeveloperCatalog.Types = DeveloperConsoleCatalogTypes{
State: CatalogTypesState(b.devCatalogCustomization.Types.State),
Enabled: b.devCatalogCustomization.Types.Enabled,
Disabled: b.devCatalogCustomization.Types.Disabled,
}
}
if len(b.projectAccess.AvailableClusterRoles) > 0 {
conf.ProjectAccess = ProjectAccess{
AvailableClusterRoles: b.projectAccess.AvailableClusterRoles,
}
}
if len(b.quickStarts.Disabled) > 0 {
conf.QuickStarts = QuickStarts{
Disabled: b.quickStarts.Disabled,
}
}
conf.AddPage = AddPage{
DisabledActions: b.addPage.DisabledActions,
}
if b.perspectives != nil {
accessReviewMap := func(accessReview authorizationv1.ResourceAttributes) authorizationv1.ResourceAttributes {
return authorizationv1.ResourceAttributes{
Resource: accessReview.Resource,
Verb: accessReview.Verb,
Group: accessReview.Group,
}
}
perspectives := make([]Perspective, len(b.perspectives))
for perspectiveIndex, perspective := range b.perspectives {
var perspectiveVisibility PerspectiveVisibility
var accessReview *ResourceAttributesAccessReview
if (perspective.Visibility != operatorv1.PerspectiveVisibility{}) {
if perspective.Visibility.State == operatorv1.PerspectiveAccessReview && (perspective.Visibility.AccessReview != &operatorv1.ResourceAttributesAccessReview{}) {
var requiredAccessReviews []authorizationv1.ResourceAttributes = nil
var missingAccessReviews []authorizationv1.ResourceAttributes = nil
if perspective.Visibility.AccessReview.Required != nil {
requiredAccessReviews = make([]authorizationv1.ResourceAttributes, len(perspective.Visibility.AccessReview.Required))
for requiredAccessReviewIndex, requiredAccessReview := range perspective.Visibility.AccessReview.Required {
requiredAccessReviews[requiredAccessReviewIndex] = accessReviewMap(requiredAccessReview)
}
}
if perspective.Visibility.AccessReview.Missing != nil {
missingAccessReviews = make([]authorizationv1.ResourceAttributes, len(perspective.Visibility.AccessReview.Missing))
for missingAccessReviewIndex, missingAccessReview := range perspective.Visibility.AccessReview.Missing {
missingAccessReviews[missingAccessReviewIndex] = accessReviewMap(missingAccessReview)
}
}
accessReview = &ResourceAttributesAccessReview{
Required: requiredAccessReviews,
Missing: missingAccessReviews,
}
perspectiveVisibility = PerspectiveVisibility{
State: PerspectiveState(perspective.Visibility.State),
AccessReview: accessReview,
}
} else {
perspectiveVisibility = PerspectiveVisibility{
State: PerspectiveState(perspective.Visibility.State),
}
}
}
perspectives[perspectiveIndex] = Perspective{
ID: perspective.ID,
Visibility: perspectiveVisibility,
PinnedResources: perspective.PinnedResources,
}
}
conf.Perspectives = perspectives
} else {
// Disable the developer perspective by default
perspectives := make([]Perspective, 1)
perspectives[0] = Perspective{
ID: string(PerspectiveIDDev),
Visibility: PerspectiveVisibility{
State: PerspectiveDisabled,
},
}
conf.Perspectives = perspectives
}
// Apply capabilities configuration. This will configure the capability based on the cluster architecture.
conf.Capabilities = b.buildCapabilities()
return conf
}
func (b *ConsoleServerCLIConfigBuilder) providers() Providers {
if len(b.statusPageID) > 0 {
return Providers{
StatuspageID: b.statusPageID,
}
}
return Providers{}
}
func (b *ConsoleServerCLIConfigBuilder) plugins() map[string]string {
return b.pluginsList
}
func (b *ConsoleServerCLIConfigBuilder) getPluginsOrder() []string {
return b.pluginsOrder
}
func (b *ConsoleServerCLIConfigBuilder) i18nNamespaces() []string {
return b.i18nNamespaceList
}
func (b *ConsoleServerCLIConfigBuilder) contentSecurityPolicy() map[v1.DirectiveType][]string {
return b.contentSecurityPolicyList
}
func (b *ConsoleServerCLIConfigBuilder) proxy() Proxy {
return Proxy{
Services: b.proxyServices,
}
}
func (b *ConsoleServerCLIConfigBuilder) Telemetry() map[string]string {
return b.telemetry
}
// buildCapabilities will configure the capabilities based on the cluster architecture.
func (b *ConsoleServerCLIConfigBuilder) buildCapabilities() []operatorv1.Capability {
capabilities := b.capabilities
// Find and configure the LightspeedButton capability
for i := range capabilities {
if capabilities[i].Name == "LightspeedButton" {
if capabilities[i].Visibility.State == operatorv1.CapabilityEnabled && !b.isLightspeedSupportedArchitecture() {
capabilities[i].Visibility.State = operatorv1.CapabilityDisabled
klog.V(4).Infof("disabling LightspeedButton capability - unsupported or mixed architectures: %v", b.nodeArchitectures)
}
break
}
}
return capabilities
}
// isLightspeedSupportedArchitecture checks if all cluster architectures support Lightspeed.
func (b *ConsoleServerCLIConfigBuilder) isLightspeedSupportedArchitecture() bool {
// No architectures means disabled
if len(b.nodeArchitectures) == 0 {
return false
}
// Check if all architectures are supported
isSupported := true
for _, clusterArch := range b.nodeArchitectures {
isSupported = false
for _, supportedArch := range SupportedLightspeedArchitectures {
if clusterArch == supportedArch {
isSupported = true
break
}
}
if !isSupported {
return false
}
}
return isSupported
}