Skip to content

Commit ca5f378

Browse files
committed
CONSOLE-4061: Update console operator to handle new custom logo API
- Update custom logo sync to come before console config and deployment syncs - custom logo sync returns on failure, no need for "ok to mount" conditions when building console config and deployments - Remove extra custom logo related args from deployment and console config sync functions. Use existing console operator config. - Add SyncCustomLogos function to validate and sync configmaps defined by new API - Update SyncCustomLogoConfigMap to remove bool return value - Share UpdateCustomLogoSyncSource between SyncCustomLogos and SyncCustomLogoConfigMap - Remove unused brand_custom_logo.go and brand_custom_logo_test.go files - Update DefaultConfigMap func to handle new API - Update config builder to convert old API to new, and sync either new API or converted old API to console config - Update DefaultDeployment to create appropriate volumes depending on CustomLogoFile or Logos - General code style updates - Update unit and e2e tests
1 parent 04195b5 commit ca5f378

File tree

11 files changed

+720
-527
lines changed

11 files changed

+720
-527
lines changed

pkg/console/operator/sync_v400.go

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact
114114
}
115115
}
116116

117+
// TODO remove deprecated CustomLogoFile API
118+
// TODO: why is this missing a toUpdate change?
119+
customLogoError, customLogoErrReason := co.SyncCustomLogoConfigMap(updatedOperatorConfig)
120+
// If the custom logo sync fails for any reason, we are degraded, not progressing.
121+
// The sync loop may not settle, we are unable to honor it in current state.
122+
statusHandler.AddConditions(status.HandleProgressingOrDegraded("CustomLogoSync", customLogoErrReason, customLogoError))
123+
if customLogoError != nil {
124+
return statusHandler.FlushAndReturn(customLogoError)
125+
}
126+
127+
customLogosErr, customLogosErrReason := co.SyncCustomLogos(updatedOperatorConfig)
128+
statusHandler.AddConditions(status.HandleProgressingOrDegraded("CustomLogosSync", customLogosErrReason, customLogosErr))
129+
if customLogosErr != nil {
130+
return statusHandler.FlushAndReturn(customLogosErr)
131+
}
132+
117133
cm, cmChanged, cmErrReason, cmErr := co.SyncConfigMap(
118134
ctx,
119135
set.Operator,
@@ -146,15 +162,6 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact
146162
return statusHandler.FlushAndReturn(trustedCAErr)
147163
}
148164

149-
// TODO: why is this missing a toUpdate change?
150-
customLogoCanMount, customLogoErrReason, customLogoError := co.SyncCustomLogoConfigMap(ctx, updatedOperatorConfig)
151-
// If the custom logo sync fails for any reason, we are degraded, not progressing.
152-
// The sync loop may not settle, we are unable to honor it in current state.
153-
statusHandler.AddConditions(status.HandleProgressingOrDegraded("CustomLogoSync", customLogoErrReason, customLogoError))
154-
if customLogoError != nil {
155-
return statusHandler.FlushAndReturn(customLogoError)
156-
}
157-
158165
var oauthServingCertConfigMap *corev1.ConfigMap
159166
switch authnConfig.Spec.Type {
160167
// We don't disable auth since the internal OAuth server is not disabled even with auth type 'None'.
@@ -187,7 +194,6 @@ func (co *consoleOperator) sync_v400(ctx context.Context, controllerContext fact
187194
sessionSecret,
188195
set.Proxy,
189196
set.Infrastructure,
190-
customLogoCanMount,
191197
controllerContext.Recorder(),
192198
)
193199
toUpdate = toUpdate || depChanged
@@ -291,7 +297,6 @@ func (co *consoleOperator) SyncDeployment(
291297
sessionSecret *corev1.Secret,
292298
proxyConfig *configv1.Proxy,
293299
infrastructureConfig *configv1.Infrastructure,
294-
canMountCustomLogo bool,
295300
recorder events.Recorder,
296301
) (consoleDeployment *appsv1.Deployment, changed bool, reason string, err error) {
297302
updatedOperatorConfig := operatorConfig.DeepCopy()
@@ -306,7 +311,6 @@ func (co *consoleOperator) SyncDeployment(
306311
sessionSecret,
307312
proxyConfig,
308313
infrastructureConfig,
309-
canMountCustomLogo,
310314
)
311315
genChanged := operatorConfig.ObjectMeta.Generation != operatorConfig.Status.ObservedGeneration
312316

@@ -554,16 +558,35 @@ func (co *consoleOperator) SyncTrustedCAConfigMap(ctx context.Context, operatorC
554558
return actual, true, "", err
555559
}
556560

557-
func (co *consoleOperator) SyncCustomLogoConfigMap(ctx context.Context, operatorConfig *operatorv1.Console) (okToMount bool, reason string, err error) {
558-
// validate first, to avoid a broken volume mount & a crashlooping console
559-
okToMount, reason, err = co.ValidateCustomLogo(ctx, operatorConfig)
560-
561-
if okToMount || configmapsub.IsRemoved(operatorConfig) {
562-
if err := co.UpdateCustomLogoSyncSource(operatorConfig); err != nil {
563-
return false, "FailedSyncSource", customerrors.NewCustomLogoError("custom logo sync source update error")
561+
func (co *consoleOperator) SyncCustomLogos(operatorConfig *operatorv1.Console) (error, string) {
562+
var (
563+
aggregatedError error
564+
err error
565+
reason string
566+
)
567+
for _, logo := range operatorConfig.Spec.Customization.Logos {
568+
for _, theme := range logo.Themes {
569+
logoToSync := theme.Source.ConfigMap
570+
err, reason = co.UpdateCustomLogoSyncSource(logoToSync)
571+
if err != nil {
572+
if aggregatedError == nil {
573+
aggregatedError = fmt.Errorf("One or more errors were encountered while syncing custom logos:\n - %v, %s", logoToSync, err.Error())
574+
} else {
575+
aggregatedError = fmt.Errorf("%s\n - %v, %s", aggregatedError.Error(), logoToSync, err.Error())
576+
}
577+
}
564578
}
565579
}
566-
return okToMount, reason, err
580+
if aggregatedError != nil {
581+
return aggregatedError, reason
582+
}
583+
return nil, ""
584+
}
585+
586+
// TODO remove deprecated CustomLogoFile API
587+
func (co *consoleOperator) SyncCustomLogoConfigMap(operatorConfig *operatorv1.Console) (error, string) {
588+
var customLogoRef = operatorv1.ConfigMapFileReference(operatorConfig.Spec.Customization.CustomLogoFile)
589+
return co.UpdateCustomLogoSyncSource(&customLogoRef)
567590
}
568591

569592
func (co *consoleOperator) ValidateOAuthServingCertConfigMap(ctx context.Context) (oauthServingCert *corev1.ConfigMap, reason string, err error) {
@@ -587,39 +610,52 @@ func (co *consoleOperator) ValidateOAuthServingCertConfigMap(ctx context.Context
587610
// sync loop will run later. Our operator is waiting to receive
588611
// the copied configmap into the console namespace for a future
589612
// sync loop to mount into the console deployment.
590-
func (c *consoleOperator) UpdateCustomLogoSyncSource(operatorConfig *operatorv1.Console) error {
613+
func (c *consoleOperator) UpdateCustomLogoSyncSource(cmRef *operatorv1.ConfigMapFileReference) (error, string) {
614+
// validate first, to avoid a broken volume mount & a crashlooping console
615+
err, reason := c.ValidateCustomLogo(cmRef)
616+
if err != nil {
617+
return err, reason
618+
}
619+
591620
source := resourcesynccontroller.ResourceLocation{}
592-
logoConfigMapName := operatorConfig.Spec.Customization.CustomLogoFile.Name
621+
logoConfigMapName := cmRef.Name
593622

594623
if logoConfigMapName != "" {
595624
source.Name = logoConfigMapName
596625
source.Namespace = api.OpenShiftConfigNamespace
597626
}
598627
// if no custom logo provided, sync an empty source to delete
599-
return c.resourceSyncer.SyncConfigMap(
600-
resourcesynccontroller.ResourceLocation{Namespace: api.OpenShiftConsoleNamespace, Name: api.OpenShiftCustomLogoConfigMapName},
628+
err = c.resourceSyncer.SyncConfigMap(
629+
resourcesynccontroller.ResourceLocation{Namespace: api.OpenShiftConsoleNamespace, Name: cmRef.Name},
601630
source,
602631
)
632+
if err != nil {
633+
return err, "FailedResourceSync"
634+
}
635+
636+
return nil, ""
603637
}
604638

605-
func (co *consoleOperator) ValidateCustomLogo(ctx context.Context, operatorConfig *operatorv1.Console) (okToMount bool, reason string, err error) {
606-
logoConfigMapName := operatorConfig.Spec.Customization.CustomLogoFile.Name
607-
logoImageKey := operatorConfig.Spec.Customization.CustomLogoFile.Key
639+
func (co *consoleOperator) ValidateCustomLogo(logoFileRef *operatorv1.ConfigMapFileReference) (err error, reason string) {
640+
logoConfigMapName := logoFileRef.Name
641+
logoImageKey := logoFileRef.Key
608642

609-
if configmapsub.FileNameOrKeyInconsistentlySet(operatorConfig) {
643+
if (len(logoConfigMapName) == 0) != (len(logoImageKey) == 0) {
610644
klog.V(4).Infoln("custom logo filename or key have not been set")
611-
return false, "KeyOrFilenameInvalid", customerrors.NewCustomLogoError("either custom logo filename or key have not been set")
645+
return customerrors.NewCustomLogoError("either custom logo filename or key have not been set"), "KeyOrFilenameInvalid"
612646
}
647+
613648
// fine if nothing set, but don't mount it
614-
if configmapsub.FileNameNotSet(operatorConfig) {
649+
if len(logoConfigMapName) == 0 {
615650
klog.V(4).Infoln("no custom logo configured")
616-
return false, "", nil
651+
return nil, ""
617652
}
653+
618654
logoConfigMap, err := co.configNSConfigMapLister.ConfigMaps(api.OpenShiftConfigNamespace).Get(logoConfigMapName)
619655
// If we 404, the logo file may not have been created yet.
620656
if err != nil {
621-
klog.V(4).Infof("custom logo file %v not found", logoConfigMapName)
622-
return false, "FailedGet", customerrors.NewCustomLogoError(fmt.Sprintf("custom logo file %v not found", logoConfigMapName))
657+
klog.V(4).Infof("failed to get ConfigMap %v, %v", logoConfigMapName, err)
658+
return customerrors.NewCustomLogoError(fmt.Sprintf("failed to get ConfigMap %v, %v", logoConfigMapName, err)), "FailedGet"
623659
}
624660

625661
_, imageDataFound := logoConfigMap.BinaryData[logoImageKey]
@@ -628,11 +664,11 @@ func (co *consoleOperator) ValidateCustomLogo(ctx context.Context, operatorConfi
628664
}
629665
if !imageDataFound {
630666
klog.V(4).Infoln("custom logo file exists but no image provided")
631-
return false, "NoImageProvided", customerrors.NewCustomLogoError("custom logo file exists but no image provided")
667+
return customerrors.NewCustomLogoError("custom logo file exists but no image provided"), "NoImageProvided"
632668
}
633669

634-
klog.V(4).Infoln("custom logo ok to mount")
635-
return true, "", nil
670+
klog.V(4).Infof("custom logo %s ok to mount", logoConfigMapName)
671+
return nil, ""
636672
}
637673

638674
func (co *consoleOperator) GetAvailablePlugins(enabledPluginsNames []string) []*v1.ConsolePlugin {

pkg/console/subresource/configmap/brand_custom_logo.go

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)