-
Notifications
You must be signed in to change notification settings - Fork 129
/
sync_v400.go
526 lines (465 loc) · 23.6 KB
/
sync_v400.go
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
package operator
import (
"context"
"errors"
"fmt"
"net/url"
"os"
// kube
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
// openshift
configv1 "github.com/openshift/api/config/v1"
v1alpha1 "github.com/openshift/api/console/v1alpha1"
oauthv1 "github.com/openshift/api/oauth/v1"
operatorv1 "github.com/openshift/api/operator/v1"
routev1 "github.com/openshift/api/route/v1"
"github.com/openshift/console-operator/pkg/api"
"github.com/openshift/console-operator/pkg/crypto"
"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
"github.com/openshift/library-go/pkg/operator/resource/resourcemerge"
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
"github.com/openshift/library-go/pkg/route/routeapihelpers"
// operator
customerrors "github.com/openshift/console-operator/pkg/console/errors"
"github.com/openshift/console-operator/pkg/console/metrics"
"github.com/openshift/console-operator/pkg/console/status"
configmapsub "github.com/openshift/console-operator/pkg/console/subresource/configmap"
deploymentsub "github.com/openshift/console-operator/pkg/console/subresource/deployment"
oauthsub "github.com/openshift/console-operator/pkg/console/subresource/oauthclient"
routesub "github.com/openshift/console-operator/pkg/console/subresource/route"
secretsub "github.com/openshift/console-operator/pkg/console/subresource/secret"
)
// The sync loop starts from zero and works its way through the requirements for a running console.
// If at any point something is missing, it creates/updates that piece and immediately dies.
// The next loop will pick up where they previous left off and move the process forward one step.
// This ensures the logic is simpler as we do not have to handle coordination between objects within
// the loop.
func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext factory.SyncContext, updatedOperatorConfig *operatorv1.Console, set configSet) error {
klog.V(4).Infoln("running sync loop 4.0.0")
statusHandler := status.NewStatusHandler(co.operatorClient)
// track changes, may trigger ripples & update operator config or console config status
toUpdate := false
routeName := api.OpenShiftConsoleRouteName
routeConfig := routesub.NewRouteConfig(updatedOperatorConfig, set.Ingress, routeName)
if routeConfig.IsCustomHostnameSet() {
routeName = api.OpenshiftConsoleCustomRouteName
}
route, consoleURL, routeReasoneErr, routeErr := co.GetActiveRouteInfo(ctx, routeName)
// TODO: this controller is no longer responsible for syncing the route.
// however, the route is essential for several of the components below.
// - the loop should exit early and wait until the RouteSyncController creates the route.
// there is nothing new in this flow, other than 2 controllers now look
// at the same resource.
// - RouteSyncController is responsible for updates
// - ConsoleOperatorController (future ConsoleDeploymentController) is responsible for reads only.
statusHandler.AddConditions(status.HandleProgressingOrDegraded("SyncLoopRefresh", routeReasoneErr, routeErr))
if routeErr != nil {
return statusHandler.FlushAndReturn(routeErr)
}
cm, cmChanged, cmErrReason, cmErr := co.SyncConfigMap(ctx, set.Operator, set.Console, set.Infrastructure, set.OAuth, route, controllerContext.Recorder())
toUpdate = toUpdate || cmChanged
statusHandler.AddConditions(status.HandleProgressingOrDegraded("ConfigMapSync", cmErrReason, cmErr))
if cmErr != nil {
return statusHandler.FlushAndReturn(cmErr)
}
serviceCAConfigMap, serviceCAChanged, serviceCAErrReason, serviceCAErr := co.SyncServiceCAConfigMap(ctx, set.Operator)
toUpdate = toUpdate || serviceCAChanged
statusHandler.AddConditions(status.HandleProgressingOrDegraded("ServiceCASync", serviceCAErrReason, serviceCAErr))
if serviceCAErr != nil {
return statusHandler.FlushAndReturn(serviceCAErr)
}
trustedCAConfigMap, trustedCAConfigMapChanged, trustedCAErrReason, trustedCAErr := co.SyncTrustedCAConfigMap(ctx, set.Operator)
toUpdate = toUpdate || trustedCAConfigMapChanged
statusHandler.AddConditions(status.HandleProgressingOrDegraded("TrustedCASync", trustedCAErrReason, trustedCAErr))
if trustedCAErr != nil {
return statusHandler.FlushAndReturn(trustedCAErr)
}
// TODO: why is this missing a toUpdate change?
customLogoCanMount, customLogoErrReason, customLogoError := co.SyncCustomLogoConfigMap(ctx, updatedOperatorConfig)
// If the custom logo sync fails for any reason, we are degraded, not progressing.
// The sync loop may not settle, we are unable to honor it in current state.
statusHandler.AddConditions(status.HandleProgressingOrDegraded("CustomLogoSync", customLogoErrReason, customLogoError))
if customLogoError != nil {
return statusHandler.FlushAndReturn(customLogoError)
}
defaultIngressCertConfigMap, defaultIngressCertErrReason, defaultIngressCertErr := co.ValidateDefaultIngressCertConfigMap(ctx)
statusHandler.AddConditions(status.HandleProgressingOrDegraded("DefaultIngressCertValidation", defaultIngressCertErrReason, defaultIngressCertErr))
if defaultIngressCertErr != nil {
return statusHandler.FlushAndReturn(defaultIngressCertErr)
}
sec, secChanged, secErr := co.SyncSecret(ctx, set.Operator, controllerContext.Recorder())
toUpdate = toUpdate || secChanged
statusHandler.AddConditions(status.HandleProgressingOrDegraded("OAuthClientSecretSync", "FailedApply", secErr))
if secErr != nil {
return statusHandler.FlushAndReturn(secErr)
}
oauthClient, oauthChanged, oauthErrReason, oauthErr := co.SyncOAuthClient(ctx, set.Operator, sec, consoleURL.String())
toUpdate = toUpdate || oauthChanged
statusHandler.AddConditions(status.HandleProgressingOrDegraded("OAuthClientSync", oauthErrReason, oauthErr))
if oauthErr != nil {
return statusHandler.FlushAndReturn(oauthErr)
}
actualDeployment, depChanged, depErrReason, depErr := co.SyncDeployment(ctx, set.Operator, cm, serviceCAConfigMap, defaultIngressCertConfigMap, trustedCAConfigMap, sec, set.Proxy, set.Infrastructure, customLogoCanMount, controllerContext.Recorder())
toUpdate = toUpdate || depChanged
statusHandler.AddConditions(status.HandleProgressingOrDegraded("DeploymentSync", depErrReason, depErr))
if depErr != nil {
return statusHandler.FlushAndReturn(depErr)
}
statusHandler.UpdateDeploymentGeneration(actualDeployment)
statusHandler.UpdateReadyReplicas(actualDeployment.Status.ReadyReplicas)
statusHandler.UpdateObservedGeneration(set.Operator.ObjectMeta.Generation)
klog.V(4).Infoln("-----------------------")
klog.V(4).Infof("sync loop 4.0.0 resources updated: %v", toUpdate)
klog.V(4).Infoln("-----------------------")
statusHandler.AddCondition(status.HandleProgressing("SyncLoopRefresh", "InProgress", func() error {
if toUpdate {
return errors.New("Changes made during sync updates, additional sync expected.")
}
version := os.Getenv("RELEASE_VERSION")
if !deploymentsub.IsAvailableAndUpdated(actualDeployment) {
return errors.New(fmt.Sprintf("Working toward version %s", version))
}
if co.versionGetter.GetVersions()["operator"] != version {
co.versionGetter.SetVersion("operator", version)
}
return nil
}()))
statusHandler.AddCondition(status.HandleAvailable(func() (prefix string, reason string, err error) {
prefix = "Deployment"
if !deploymentsub.IsReady(actualDeployment) {
return prefix, "InsufficientReplicas", errors.New(fmt.Sprintf("%v pods available for console deployment", actualDeployment.Status.ReadyReplicas))
}
if !deploymentsub.IsReadyAndUpdated(actualDeployment) {
return prefix, "FailedUpdate", errors.New(fmt.Sprintf("%v replicas ready at version %s", actualDeployment.Status.ReadyReplicas, os.Getenv("RELEASE_VERSION")))
}
return prefix, "", nil
}()))
// if we survive the gauntlet, we need to update the console config with the
// public hostname so that the world can know the console is ready to roll
klog.V(4).Infoln("sync_v400: updating console status")
_, consoleConfigErr := co.SyncConsoleConfig(ctx, set.Console, consoleURL.String())
statusHandler.AddCondition(status.HandleDegraded("ConsoleConfig", "FailedUpdate", consoleConfigErr))
if consoleConfigErr != nil {
klog.Errorf("could not update console config status: %v", consoleConfigErr)
return statusHandler.FlushAndReturn(consoleConfigErr)
}
_, _, consolePublicConfigErr := co.SyncConsolePublicConfig(consoleURL.String(), controllerContext.Recorder())
statusHandler.AddCondition(status.HandleDegraded("ConsolePublicConfigMap", "FailedApply", consolePublicConfigErr))
if consolePublicConfigErr != nil {
klog.Errorf("could not update public console config status: %v", consolePublicConfigErr)
return statusHandler.FlushAndReturn(consolePublicConfigErr)
}
defer func() {
klog.V(4).Infof("sync loop 4.0.0 complete")
if cmChanged {
klog.V(4).Infof("\t configmap changed: %v", cm.GetResourceVersion())
}
if serviceCAChanged {
klog.V(4).Infof("\t service-ca configmap changed: %v", serviceCAConfigMap.GetResourceVersion())
}
if secChanged {
klog.V(4).Infof("\t secret changed: %v", sec.GetResourceVersion())
}
if oauthChanged {
klog.V(4).Infof("\t oauth changed: %v", oauthClient.GetResourceVersion())
}
if depChanged {
klog.V(4).Infof("\t deployment changed: %v", actualDeployment.GetResourceVersion())
}
}()
return statusHandler.FlushAndReturn(nil)
}
func (co *consoleOperator) GetActiveRouteInfo(ctx context.Context, activeRouteName string) (route *routev1.Route, routeURL *url.URL, reason string, err error) {
route, routeErr := co.routeClient.Routes(api.TargetNamespace).Get(ctx, activeRouteName, metav1.GetOptions{})
if routeErr != nil {
return nil, nil, "FailedGet", routeErr
}
uri, _, uriErr := routeapihelpers.IngressURI(route, route.Spec.Host)
if uriErr != nil {
return nil, nil, "FailedIngress", uriErr
}
return route, uri, "", nil
}
func (co *consoleOperator) SyncConsoleConfig(ctx context.Context, consoleConfig *configv1.Console, consoleURL string) (*configv1.Console, error) {
oldURL := consoleConfig.Status.ConsoleURL
metrics.HandleConsoleURL(oldURL, consoleURL)
if oldURL != consoleURL {
klog.V(4).Infof("updating console.config.openshift.io with url: %v", consoleURL)
updated := consoleConfig.DeepCopy()
updated.Status.ConsoleURL = consoleURL
return co.consoleConfigClient.UpdateStatus(ctx, updated, metav1.UpdateOptions{})
}
return consoleConfig, nil
}
func (co *consoleOperator) SyncConsolePublicConfig(consoleURL string, recorder events.Recorder) (*corev1.ConfigMap, bool, error) {
requiredConfigMap := configmapsub.DefaultPublicConfig(consoleURL)
return resourceapply.ApplyConfigMap(co.configMapClient, recorder, requiredConfigMap)
}
func (co *consoleOperator) SyncDeployment(
ctx context.Context,
operatorConfig *operatorv1.Console,
cm *corev1.ConfigMap,
serviceCAConfigMap *corev1.ConfigMap,
defaultIngressCertConfigMap *corev1.ConfigMap,
trustedCAConfigMap *corev1.ConfigMap,
sec *corev1.Secret,
proxyConfig *configv1.Proxy,
infrastructureConfig *configv1.Infrastructure,
canMountCustomLogo bool,
recorder events.Recorder) (consoleDeployment *appsv1.Deployment, changed bool, reason string, err error) {
updatedOperatorConfig := operatorConfig.DeepCopy()
requiredDeployment := deploymentsub.DefaultDeployment(operatorConfig, cm, serviceCAConfigMap, defaultIngressCertConfigMap, trustedCAConfigMap, sec, proxyConfig, infrastructureConfig, canMountCustomLogo)
genChanged := operatorConfig.ObjectMeta.Generation != operatorConfig.Status.ObservedGeneration
if genChanged {
klog.V(4).Infof("deployment generation changed from %d to %d", operatorConfig.ObjectMeta.Generation, operatorConfig.Status.ObservedGeneration)
}
deploymentsub.LogDeploymentAnnotationChanges(co.deploymentClient, requiredDeployment, ctx)
deployment, deploymentChanged, applyDepErr := resourceapply.ApplyDeployment(
co.deploymentClient,
recorder,
requiredDeployment,
resourcemerge.ExpectedDeploymentGeneration(requiredDeployment, updatedOperatorConfig.Status.Generations),
)
if applyDepErr != nil {
return nil, false, "FailedApply", applyDepErr
}
return deployment, deploymentChanged, "", nil
}
// applies changes to the oauthclient
// should not be called until route & secret dependencies are verified
func (co *consoleOperator) SyncOAuthClient(
ctx context.Context,
operatorConfig *operatorv1.Console,
sec *corev1.Secret,
consoleURL string,
) (consoleoauthclient *oauthv1.OAuthClient, changed bool, reason string, err error) {
oauthClient, err := co.oauthClient.OAuthClients().Get(ctx, oauthsub.Stub().Name, metav1.GetOptions{})
if err != nil {
// at this point we must die & wait for someone to fix the lack of an outhclient. there is nothing we can do.
return nil, false, "FailedGet", errors.New(fmt.Sprintf("oauth client for console does not exist and cannot be created (%v)", err))
}
oauthsub.RegisterConsoleToOAuthClient(oauthClient, consoleURL, secretsub.GetSecretString(sec))
oauthClient, oauthChanged, oauthErr := oauthsub.CustomApplyOAuth(co.oauthClient, oauthClient, ctx)
if oauthErr != nil {
return nil, false, "FailedRegister", oauthErr
}
return oauthClient, oauthChanged, "", nil
}
func (co *consoleOperator) SyncSecret(ctx context.Context, operatorConfig *operatorv1.Console, recorder events.Recorder) (*corev1.Secret, bool, error) {
secret, err := co.secretsClient.Secrets(api.TargetNamespace).Get(ctx, secretsub.Stub().Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) || secretsub.GetSecretString(secret) == "" {
return resourceapply.ApplySecret(co.secretsClient, recorder, secretsub.DefaultSecret(operatorConfig, crypto.Random256BitsString()))
}
// any error should be returned & kill the sync loop
if err != nil {
return nil, false, err
}
return secret, false, nil
}
// apply configmap (needs route)
// by the time we get to the configmap, we can assume the route exits & is configured properly
// therefore no additional error handling is needed here.
func (co *consoleOperator) SyncConfigMap(
ctx context.Context,
operatorConfig *operatorv1.Console,
consoleConfig *configv1.Console,
infrastructureConfig *configv1.Infrastructure,
oauthConfig *configv1.OAuth,
activeConsoleRoute *routev1.Route,
recorder events.Recorder,
) (consoleConfigMap *corev1.ConfigMap, changed bool, reason string, err error) {
managedConfig, mcErr := co.configMapClient.ConfigMaps(api.OpenShiftConfigManagedNamespace).Get(ctx, api.OpenShiftConsoleConfigMapName, metav1.GetOptions{})
if mcErr != nil && !apierrors.IsNotFound(mcErr) {
return nil, false, "FailedGetManagedConfig", mcErr
}
useDefaultCAFile := false
// We are syncing the `default-ingress-cert` configmap from `openshift-config-managed` to `openshift-console`.
// `default-ingress-cert` is only published in `openshift-config-managed` in OpenShift 4.4.0 and newer.
// If the `default-ingress-cert` configmap in `openshift-console` exists, we should mount that to the console container,
// otherwise default to `/var/run/secrets/kubernetes.io/serviceaccount/ca.crt`
_, rcaErr := co.configMapClient.ConfigMaps(api.OpenShiftConsoleNamespace).Get(ctx, api.DefaultIngressCertConfigMapName, metav1.GetOptions{})
if rcaErr != nil && apierrors.IsNotFound(rcaErr) {
useDefaultCAFile = true
}
inactivityTimeoutSeconds := 0
oauthClient, oacErr := co.oauthClient.OAuthClients().Get(ctx, oauthsub.Stub().Name, metav1.GetOptions{})
if oacErr != nil {
return nil, false, "FailedGetOAuthClient", oacErr
}
if oauthClient.AccessTokenInactivityTimeoutSeconds != nil {
inactivityTimeoutSeconds = int(*oauthClient.AccessTokenInactivityTimeoutSeconds)
} else {
if oauthConfig.Spec.TokenConfig.AccessTokenInactivityTimeout != nil {
inactivityTimeoutSeconds = int(oauthConfig.Spec.TokenConfig.AccessTokenInactivityTimeout.Seconds())
}
}
pluginsEndpoingMap := co.GetPluginsEndpointMap(operatorConfig.Spec.Plugins)
defaultConfigmap, _, err := configmapsub.DefaultConfigMap(operatorConfig, consoleConfig, managedConfig, infrastructureConfig, activeConsoleRoute, useDefaultCAFile, inactivityTimeoutSeconds, pluginsEndpoingMap)
if err != nil {
return nil, false, "FailedConsoleConfigBuilder", err
}
cm, cmChanged, cmErr := resourceapply.ApplyConfigMap(co.configMapClient, recorder, defaultConfigmap)
if cmErr != nil {
return nil, false, "FailedApply", cmErr
}
if cmChanged {
klog.V(4).Infoln("new console config yaml:")
klog.V(4).Infof("%s", cm.Data)
}
return cm, cmChanged, "ConsoleConfigBuilder", cmErr
}
// apply service-ca configmap
func (co *consoleOperator) SyncServiceCAConfigMap(ctx context.Context, operatorConfig *operatorv1.Console) (consoleCM *corev1.ConfigMap, changed bool, reason string, err error) {
required := configmapsub.DefaultServiceCAConfigMap(operatorConfig)
// we can't use `resourceapply.ApplyConfigMap` since it compares data, and the service serving cert operator injects the data
existing, err := co.configMapClient.ConfigMaps(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
actual, err := co.configMapClient.ConfigMaps(required.Namespace).Create(ctx, required, metav1.CreateOptions{})
if err == nil {
klog.V(4).Infoln("service-ca configmap created")
return actual, true, "", err
} else {
return actual, true, "FailedCreate", err
}
}
if err != nil {
return nil, false, "FailedGet", err
}
modified := resourcemerge.BoolPtr(false)
resourcemerge.EnsureObjectMeta(modified, &existing.ObjectMeta, required.ObjectMeta)
if !*modified {
klog.V(4).Infoln("service-ca configmap exists and is in the correct state")
return existing, false, "", nil
}
actual, err := co.configMapClient.ConfigMaps(required.Namespace).Update(ctx, existing, metav1.UpdateOptions{})
if err == nil {
klog.V(4).Infoln("service-ca configmap updated")
return actual, true, "", err
} else {
return actual, true, "FailedUpdate", err
}
}
func (co *consoleOperator) SyncTrustedCAConfigMap(ctx context.Context, operatorConfig *operatorv1.Console) (trustedCA *corev1.ConfigMap, changed bool, reason string, err error) {
required := configmapsub.DefaultTrustedCAConfigMap(operatorConfig)
existing, err := co.configMapClient.ConfigMaps(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
actual, err := co.configMapClient.ConfigMaps(required.Namespace).Create(ctx, required, metav1.CreateOptions{})
if err != nil {
return actual, true, "FailedCreate", err
}
klog.V(4).Infoln("trusted-ca-bundle configmap created")
return actual, true, "", err
}
if err != nil {
return nil, false, "FailedGet", err
}
modified := resourcemerge.BoolPtr(false)
resourcemerge.EnsureObjectMeta(modified, &existing.ObjectMeta, required.ObjectMeta)
if !*modified {
klog.V(4).Infoln("trusted-ca-bundle configmap exists and is in the correct state")
return existing, false, "", nil
}
actual, err := co.configMapClient.ConfigMaps(required.Namespace).Update(ctx, existing, metav1.UpdateOptions{})
if err != nil {
return actual, true, "FailedUpdate", err
}
klog.V(4).Infoln("trusted-ca-bundle configmap updated")
return actual, true, "", err
}
func (co *consoleOperator) SyncCustomLogoConfigMap(ctx context.Context, operatorConfig *operatorv1.Console) (okToMount bool, reason string, err error) {
// validate first, to avoid a broken volume mount & a crashlooping console
okToMount, reason, err = co.ValidateCustomLogo(ctx, operatorConfig)
if okToMount || configmapsub.IsRemoved(operatorConfig) {
if err := co.UpdateCustomLogoSyncSource(operatorConfig); err != nil {
return false, "FailedSyncSource", customerrors.NewCustomLogoError("custom logo sync source update error")
}
}
return okToMount, reason, err
}
func (co *consoleOperator) ValidateDefaultIngressCertConfigMap(ctx context.Context) (defaultIngressCert *corev1.ConfigMap, reason string, err error) {
defaultIngressCertConfigMap, err := co.configMapClient.ConfigMaps(api.OpenShiftConsoleNamespace).Get(ctx, api.DefaultIngressCertConfigMapName, metav1.GetOptions{})
if err != nil {
klog.V(4).Infoln("default-ingress-cert configmap not found")
return nil, "FailedGet", fmt.Errorf("default-ingress-cert configmap not found")
}
_, caBundle := defaultIngressCertConfigMap.Data["ca-bundle.crt"]
if !caBundle {
return nil, "MissingDefaultIngressCertBundle", fmt.Errorf("default-ingress-cert configmap is missing ca-bundle.crt data")
}
return defaultIngressCertConfigMap, "", nil
}
// on each pass of the operator sync loop, we need to check the
// operator config for a custom logo. If this has been set, then
// we notify the resourceSyncer that it needs to start watching this
// configmap in its own sync loop. Note that the resourceSyncer's actual
// sync loop will run later. Our operator is waiting to receive
// the copied configmap into the console namespace for a future
// sync loop to mount into the console deployment.
func (c *consoleOperator) UpdateCustomLogoSyncSource(operatorConfig *operatorv1.Console) error {
source := resourcesynccontroller.ResourceLocation{}
logoConfigMapName := operatorConfig.Spec.Customization.CustomLogoFile.Name
if logoConfigMapName != "" {
source.Name = logoConfigMapName
source.Namespace = api.OpenShiftConfigNamespace
}
// if no custom logo provided, sync an empty source to delete
return c.resourceSyncer.SyncConfigMap(
resourcesynccontroller.ResourceLocation{Namespace: api.OpenShiftConsoleNamespace, Name: api.OpenShiftCustomLogoConfigMapName},
source,
)
}
func (co *consoleOperator) ValidateCustomLogo(ctx context.Context, operatorConfig *operatorv1.Console) (okToMount bool, reason string, err error) {
logoConfigMapName := operatorConfig.Spec.Customization.CustomLogoFile.Name
logoImageKey := operatorConfig.Spec.Customization.CustomLogoFile.Key
if configmapsub.FileNameOrKeyInconsistentlySet(operatorConfig) {
klog.V(4).Infoln("custom logo filename or key have not been set")
return false, "KeyOrFilenameInvalid", customerrors.NewCustomLogoError("either custom logo filename or key have not been set")
}
// fine if nothing set, but don't mount it
if configmapsub.FileNameNotSet(operatorConfig) {
klog.V(4).Infoln("no custom logo configured")
return false, "", nil
}
logoConfigMap, err := co.configMapClient.ConfigMaps(api.OpenShiftConfigNamespace).Get(ctx, logoConfigMapName, metav1.GetOptions{})
// If we 404, the logo file may not have been created yet.
if err != nil {
klog.V(4).Infof("custom logo file %v not found", logoConfigMapName)
return false, "FailedGet", customerrors.NewCustomLogoError(fmt.Sprintf("custom logo file %v not found", logoConfigMapName))
}
_, imageDataFound := logoConfigMap.BinaryData[logoImageKey]
if !imageDataFound {
_, imageDataFound = logoConfigMap.Data[logoImageKey]
}
if !imageDataFound {
klog.V(4).Infoln("custom logo file exists but no image provided")
return false, "NoImageProvided", customerrors.NewCustomLogoError("custom logo file exists but no image provided")
}
klog.V(4).Infoln("custom logo ok to mount")
return true, "", nil
}
func (co *consoleOperator) GetPluginsEndpointMap(enabledPluginsNames []string) map[string]string {
pluginsEndpointMap := map[string]string{}
for _, pluginName := range enabledPluginsNames {
plugin, err := co.consolePluginLister.Get(pluginName)
if err != nil {
klog.Errorf("failed to get %q plugin: %v", pluginName, err)
continue
}
pluginsEndpointMap[pluginName] = getServiceHostname(plugin)
}
return pluginsEndpointMap
}
func getServiceHostname(plugin *v1alpha1.ConsolePlugin) string {
pluginURL := &url.URL{
Scheme: "https",
Host: fmt.Sprintf("%s.%s.svc.cluster.local:%d", plugin.Spec.Service.Name, plugin.Spec.Service.Namespace, plugin.Spec.Service.Port),
Path: plugin.Spec.Service.BasePath,
}
return pluginURL.String()
}