6
6
"fmt"
7
7
"net/url"
8
8
"os"
9
+ "slices"
9
10
"strings"
10
11
11
12
// kube
@@ -559,30 +560,39 @@ func (co *consoleOperator) SyncCustomLogos(operatorConfig *operatorv1.Console) (
559
560
aggregatedError error
560
561
err error
561
562
reason string
563
+ newSyncedLogos []string
562
564
)
563
565
for _ , logo := range operatorConfig .Spec .Customization .Logos {
564
566
for _ , theme := range logo .Themes {
565
567
logoToSync := theme .Source .ConfigMap
566
- err , reason = co .UpdateCustomLogoSyncSource (logoToSync )
567
- if err != nil {
568
+ if err , reason = co .ValidateCustomLogo (logoToSync ); err != nil {
568
569
if aggregatedError == nil {
569
- aggregatedError = fmt .Errorf ("One or more errors were encountered while syncing custom logos:\n - %v, %s" , logoToSync , err .Error ())
570
+ aggregatedError = fmt .Errorf ("error syncing custom logos: - Invalid config: %v, %s" , logoToSync , err .Error ())
570
571
} else {
571
- aggregatedError = fmt .Errorf ("%s\n - %v, %s" , aggregatedError .Error (), logoToSync , err .Error ())
572
+ aggregatedError = fmt .Errorf ("%s - %v, %s" , aggregatedError .Error (), logoToSync , err .Error ())
572
573
}
574
+ } else {
575
+ newSyncedLogos = append (newSyncedLogos , logoToSync .Name )
573
576
}
574
577
}
575
578
}
576
579
if aggregatedError != nil {
577
580
return aggregatedError , reason
578
581
}
579
- return nil , ""
582
+ slices .Sort (newSyncedLogos )
583
+ return co .UpdateCustomLogoSyncSources (newSyncedLogos )
580
584
}
581
585
582
586
// TODO remove deprecated CustomLogoFile API
583
587
func (co * consoleOperator ) SyncCustomLogoConfigMap (operatorConfig * operatorv1.Console ) (error , string ) {
584
588
var customLogoRef = operatorv1 .ConfigMapFileReference (operatorConfig .Spec .Customization .CustomLogoFile )
585
- return co .UpdateCustomLogoSyncSource (& customLogoRef )
589
+ klog .V (4 ).Infof ("[SyncCustomLogoConfigMap] syncing customLogoFile, Name: %s, Key: %s" , customLogoRef .Name , customLogoRef .Key )
590
+ err , reason := co .ValidateCustomLogo (& customLogoRef )
591
+ if err != nil {
592
+ klog .V (4 ).Infof ("[SyncCustomLogoConfigMap] failed to sync customLogoFile, %v" , err )
593
+ return err , reason
594
+ }
595
+ return co .UpdateCustomLogoSyncSources ([]string {customLogoRef .Name })
586
596
}
587
597
588
598
func (co * consoleOperator ) ValidateOAuthServingCertConfigMap (ctx context.Context ) (oauthServingCert * corev1.ConfigMap , reason string , err error ) {
@@ -600,35 +610,54 @@ func (co *consoleOperator) ValidateOAuthServingCertConfigMap(ctx context.Context
600
610
}
601
611
602
612
// on each pass of the operator sync loop, we need to check the
603
- // operator config for a custom logo . If this has been set, then
604
- // we notify the resourceSyncer that it needs to start watching this
605
- // configmap in its own sync loop. Note that the resourceSyncer's actual
613
+ // operator config for custom logos . If this has been set, then
614
+ // we notify the resourceSyncer that it needs to start watching the associated
615
+ // configmaps in its own sync loop. Note that the resourceSyncer's actual
606
616
// sync loop will run later. Our operator is waiting to receive
607
- // the copied configmap into the console namespace for a future
617
+ // the copied configmaps into the console namespace for a future
608
618
// sync loop to mount into the console deployment.
609
- func (c * consoleOperator ) UpdateCustomLogoSyncSource (cmRef * operatorv1.ConfigMapFileReference ) (error , string ) {
610
- // validate first, to avoid a broken volume mount & a crashlooping console
611
- err , reason := c .ValidateCustomLogo (cmRef )
612
- if err != nil {
613
- return err , reason
619
+ func (co * consoleOperator ) UpdateCustomLogoSyncSources (configMapNames []string ) (error , string ) {
620
+ klog .V (4 ).Info ("[UpdateCustomLogoSyncSources] syncing custom logo configmap resources" )
621
+ klog .V (4 ).Infof ("%#v" , configMapNames )
622
+
623
+ errors := []string {}
624
+ if len (co .trackables .customLogoConfigMaps ) > 0 {
625
+ klog .V (4 ).Info ("[UpdateCustomLogoSyncSources] unsyncing custom logo configmap resources from previous sync loop..." )
626
+ for _ , configMapName := range co .trackables .customLogoConfigMaps {
627
+ err := co .UpdateCustomLogoSyncSource (configMapName , true )
628
+ if err != nil {
629
+ errors = append (errors , err .Error ())
630
+ }
631
+ }
632
+
633
+ if len (errors ) > 0 {
634
+ msg := fmt .Sprintf ("error syncing custom logo configmap resources:\n %v" , errors )
635
+ klog .V (4 ).Infof ("[UpdateCustomLogoSyncSources] %s" , msg )
636
+ return fmt .Errorf (msg ), "FailedResourceSync"
637
+ }
614
638
}
615
639
616
- source := resourcesynccontroller.ResourceLocation {}
617
- logoConfigMapName := cmRef .Name
640
+ if len (configMapNames ) > 0 {
641
+ // If the new list of synced configmaps is different than the last sync, we need to update the
642
+ // resource syncer with the new list, and re
643
+ klog .V (4 ).Infof ("[UpdateCustomLogoSyncSources] syncing new custom logo configmap resources..." )
644
+ for _ , configMapName := range configMapNames {
645
+ err := co .UpdateCustomLogoSyncSource (configMapName , false )
646
+ if err != nil {
647
+ errors = append (errors , err .Error ())
648
+ }
649
+ }
618
650
619
- if logoConfigMapName != "" {
620
- source .Name = logoConfigMapName
621
- source .Namespace = api .OpenShiftConfigNamespace
622
- }
623
- // if no custom logo provided, sync an empty source to delete
624
- err = c .resourceSyncer .SyncConfigMap (
625
- resourcesynccontroller.ResourceLocation {Namespace : api .OpenShiftConsoleNamespace , Name : cmRef .Name },
626
- source ,
627
- )
628
- if err != nil {
629
- return err , "FailedResourceSync"
651
+ if len (errors ) > 0 {
652
+ msg := fmt .Sprintf ("error syncing custom logo configmap resources:\n %v" , errors )
653
+ klog .V (4 ).Infof ("[UpdateCustomLogoSyncSources] %s" , msg )
654
+ return fmt .Errorf (msg ), "FailedResourceSync"
655
+ }
630
656
}
631
657
658
+ co .trackables .customLogoConfigMaps = configMapNames
659
+
660
+ klog .V (4 ).Info ("[UpdateCustomLogoSyncSources] done" )
632
661
return nil , ""
633
662
}
634
663
@@ -637,34 +666,57 @@ func (co *consoleOperator) ValidateCustomLogo(logoFileRef *operatorv1.ConfigMapF
637
666
logoImageKey := logoFileRef .Key
638
667
639
668
if (len (logoConfigMapName ) == 0 ) != (len (logoImageKey ) == 0 ) {
640
- klog .V (4 ).Infoln ("custom logo filename or key have not been set" )
641
- return customerrors .NewCustomLogoError ("either custom logo filename or key have not been set" ), "KeyOrFilenameInvalid"
669
+ msg := "custom logo filename or key have not been set"
670
+ klog .V (4 ).Infof ("[ValidateCustomLogo] %s" , msg )
671
+ return customerrors .NewCustomLogoError (msg ), "KeyOrFilenameInvalid"
642
672
}
643
673
// fine if nothing set, but don't mount it
644
674
if len (logoConfigMapName ) == 0 {
645
- klog .V (4 ).Infoln ("no custom logo configured" )
675
+ klog .V (4 ).Infoln ("[ValidateCustomLogo] no custom logo configured" )
646
676
return nil , ""
647
677
}
648
678
logoConfigMap , err := co .configNSConfigMapLister .ConfigMaps (api .OpenShiftConfigNamespace ).Get (logoConfigMapName )
649
679
// If we 404, the logo file may not have been created yet.
650
680
if err != nil {
651
- klog .V (4 ).Infof ("failed to get ConfigMap %v, %v" , logoConfigMapName , err )
652
- return customerrors .NewCustomLogoError (fmt .Sprintf ("failed to get ConfigMap %v, %v" , logoConfigMapName , err )), "FailedGet"
681
+ msg := fmt .Sprintf ("failed to get ConfigMap %v, %v" , logoConfigMapName , err )
682
+ klog .V (4 ).Infof ("[ValidateCustomLogo] %s" , msg )
683
+ return customerrors .NewCustomLogoError (msg ), "FailedGet"
653
684
}
654
685
655
686
_ , imageDataFound := logoConfigMap .BinaryData [logoImageKey ]
656
687
if ! imageDataFound {
657
688
_ , imageDataFound = logoConfigMap .Data [logoImageKey ]
658
689
}
659
690
if ! imageDataFound {
660
- klog .V (4 ).Infoln ("custom logo file exists but no image provided" )
661
- return customerrors .NewCustomLogoError ("custom logo file exists but no image provided" ), "NoImageProvided"
691
+ msg := "custom logo file exists but no image provided"
692
+ klog .V (4 ).Infof ("[ValidateCustomLogo] %s" , msg )
693
+ return customerrors .NewCustomLogoError (msg ), "NoImageProvided"
662
694
}
663
695
664
- klog .V (4 ).Infof ("custom logo %s ok to mount" , logoConfigMapName )
696
+ klog .V (4 ).Infof ("[ValidateCustomLogo] custom logo %s ok to mount" , logoConfigMapName )
665
697
return nil , ""
666
698
}
667
699
700
+ func (co * consoleOperator ) UpdateCustomLogoSyncSource (targetName string , unsync bool ) error {
701
+ source := resourcesynccontroller.ResourceLocation {}
702
+ if ! unsync {
703
+ source .Name = targetName
704
+ source .Namespace = api .OpenShiftConfigNamespace
705
+ }
706
+
707
+ target := resourcesynccontroller.ResourceLocation {
708
+ Namespace : api .OpenShiftConsoleNamespace ,
709
+ Name : targetName ,
710
+ }
711
+
712
+ if unsync {
713
+ klog .V (4 ).Infof ("[UpdateCustomLogoSyncSource] unsyncing %s" , targetName )
714
+ } else {
715
+ klog .V (4 ).Infof ("[UpdateCustomLogoSyncSource] syncing %s" , targetName )
716
+ }
717
+ return co .resourceSyncer .SyncConfigMap (target , source )
718
+ }
719
+
668
720
func (co * consoleOperator ) GetAvailablePlugins (enabledPluginsNames []string ) []* v1.ConsolePlugin {
669
721
var availablePlugins []* v1.ConsolePlugin
670
722
for _ , pluginName := range utilsub .RemoveDuplicateStr (enabledPluginsNames ) {
0 commit comments