1
1
/*******************************************************************************
2
2
* Copyright 2019 Dell Inc.
3
3
* Copyright 2023 Intel Corporation
4
- * Copyright 2024 IOTech Ltd
4
+ * Copyright 2024-2025 IOTech Ltd
5
5
*
6
6
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7
7
* in compliance with the License. You may obtain a copy of the License at
@@ -65,8 +65,6 @@ const (
65
65
deviceServicesKey = "device-services"
66
66
67
67
SecurityModeKey = "Mode"
68
-
69
- configProviderTypeKeeper = "keeper"
70
68
)
71
69
72
70
var invalidRemoteHostsError = errors .New ("-rsh/--remoteServiceHosts must contain 3 and only 3 comma seperated host names" )
@@ -270,16 +268,16 @@ func (cp *Processor) Process(
270
268
271
269
// listen for changes on Writable
272
270
if useProvider {
273
- cp .listenForPrivateChanges (serviceConfig , privateConfigClient , utils .BuildBaseKey (configStem , serviceKey ), configProviderInfo . ServiceConfig (). Type )
271
+ cp .listenForPrivateChanges (serviceConfig , privateConfigClient , utils .BuildBaseKey (configStem , serviceKey ))
274
272
cp .lc .Infof ("listening for private config changes" )
275
- cp .listenForCommonChanges (serviceConfig , cp .commonConfigClient , privateConfigClient , utils .BuildBaseKey (configStem , common .CoreCommonConfigServiceKey , allServicesKey ), configProviderInfo . ServiceConfig (). Type )
273
+ cp .listenForCommonChanges (serviceConfig , cp .commonConfigClient , privateConfigClient , utils .BuildBaseKey (configStem , common .CoreCommonConfigServiceKey , allServicesKey ))
276
274
cp .lc .Infof ("listening for all services common config changes" )
277
275
if cp .appConfigClient != nil {
278
- cp .listenForCommonChanges (serviceConfig , cp .appConfigClient , privateConfigClient , utils .BuildBaseKey (configStem , common .CoreCommonConfigServiceKey , appServicesKey ), configProviderInfo . ServiceConfig (). Type )
276
+ cp .listenForCommonChanges (serviceConfig , cp .appConfigClient , privateConfigClient , utils .BuildBaseKey (configStem , common .CoreCommonConfigServiceKey , appServicesKey ))
279
277
cp .lc .Infof ("listening for application service common config changes" )
280
278
}
281
279
if cp .deviceConfigClient != nil {
282
- cp .listenForCommonChanges (serviceConfig , cp .deviceConfigClient , privateConfigClient , utils .BuildBaseKey (configStem , common .CoreCommonConfigServiceKey , deviceServicesKey ), configProviderInfo . ServiceConfig (). Type )
280
+ cp .listenForCommonChanges (serviceConfig , cp .deviceConfigClient , privateConfigClient , utils .BuildBaseKey (configStem , common .CoreCommonConfigServiceKey , deviceServicesKey ))
283
281
cp .lc .Infof ("listening for device service common config changes" )
284
282
}
285
283
}
@@ -652,28 +650,7 @@ func (cp *Processor) ListenForCustomConfigChanges(
652
650
updateStream := make (chan any )
653
651
defer close (updateStream )
654
652
655
- var messageBus messaging.MessageClient
656
- configProviderUrl := cp .flags .ConfigProviderUrl ()
657
- // check if the config provider type is keeper
658
- if strings .HasPrefix (configProviderUrl , configProviderTypeKeeper ) {
659
- // there's no startupTimer for cp created by NewProcessorForCustomConfig
660
- // add a new startupTimer here
661
- if ! cp .startupTimer .HasNotElapsed () {
662
- cp .startupTimer = startup .NewStartUpTimer ("" )
663
- }
664
- for cp .startupTimer .HasNotElapsed () {
665
- if msgClient := container .MessagingClientFrom (cp .dic .Get ); msgClient != nil {
666
- messageBus = msgClient
667
- break
668
- }
669
- cp .startupTimer .SleepForInterval ()
670
- }
671
- if messageBus == nil {
672
- cp .lc .Error ("unable to use MessageClient to watch for custom configuration changes" )
673
- return
674
- }
675
- }
676
- go configClient .WatchForChanges (updateStream , errorStream , configToWatch , sectionName , messageBus )
653
+ go configClient .WatchForChanges (updateStream , errorStream , configToWatch , sectionName , cp .getMessageClient )
677
654
678
655
isFirstUpdate := true
679
656
@@ -772,7 +749,7 @@ func GetConfigFileLocation(lc logger.LoggingClient, flags flags.Common) string {
772
749
// service's configuration writable sub-struct. It's assumed the log level is universally part of the
773
750
// writable struct and this function explicitly updates the loggingClient's log level when new configuration changes
774
751
// are received.
775
- func (cp * Processor ) listenForPrivateChanges (serviceConfig interfaces.Configuration , configClient configuration.Client , baseKey string , configProviderType string ) {
752
+ func (cp * Processor ) listenForPrivateChanges (serviceConfig interfaces.Configuration , configClient configuration.Client , baseKey string ) {
776
753
lc := cp .lc
777
754
isFirstUpdate := true
778
755
@@ -786,22 +763,7 @@ func (cp *Processor) listenForPrivateChanges(serviceConfig interfaces.Configurat
786
763
updateStream := make (chan any )
787
764
defer close (updateStream )
788
765
789
- // get the MessageClient to be used in Keeper WatchForChanges method
790
- var messageBus messaging.MessageClient
791
- if configProviderType == configProviderTypeKeeper {
792
- for cp .startupTimer .HasNotElapsed () {
793
- if msgClient := container .MessagingClientFrom (cp .dic .Get ); msgClient != nil {
794
- messageBus = msgClient
795
- break
796
- }
797
- cp .startupTimer .SleepForInterval ()
798
- }
799
- if messageBus == nil {
800
- lc .Error ("unable to use MessageClient to watch for configuration changes" )
801
- return
802
- }
803
- }
804
- go configClient .WatchForChanges (updateStream , errorStream , serviceConfig .EmptyWritablePtr (), writableKey , messageBus )
766
+ go configClient .WatchForChanges (updateStream , errorStream , serviceConfig .EmptyWritablePtr (), writableKey , cp .getMessageClient )
805
767
806
768
for {
807
769
select {
@@ -844,7 +806,7 @@ func (cp *Processor) listenForPrivateChanges(serviceConfig interfaces.Configurat
844
806
// listenForCommonChanges leverages the Configuration Provider client's WatchForChanges() method to receive changes to and update the
845
807
// service's common configuration writable sub-struct.
846
808
func (cp * Processor ) listenForCommonChanges (fullServiceConfig interfaces.Configuration , configClient configuration.Client ,
847
- privateConfigClient configuration.Client , baseKey string , configProviderType string ) {
809
+ privateConfigClient configuration.Client , baseKey string ) {
848
810
lc := cp .lc
849
811
isFirstUpdate := true
850
812
baseKey = utils .BuildBaseKey (baseKey , writableKey )
@@ -863,22 +825,7 @@ func (cp *Processor) listenForCommonChanges(fullServiceConfig interfaces.Configu
863
825
updateStream := make (chan any )
864
826
defer close (updateStream )
865
827
866
- // get the MessageClient to be used in Keeper WatchForChanges method
867
- var messageBus messaging.MessageClient
868
- if configProviderType == configProviderTypeKeeper {
869
- for cp .startupTimer .HasNotElapsed () {
870
- if msgClient := container .MessagingClientFrom (cp .dic .Get ); msgClient != nil {
871
- messageBus = msgClient
872
- break
873
- }
874
- cp .startupTimer .SleepForInterval ()
875
- }
876
- if messageBus == nil {
877
- lc .Error ("unable to use MessageClient to watch for configuration changes" )
878
- return
879
- }
880
- }
881
- go commonConfigClient .WatchForChanges (updateStream , errorStream , fullServiceConfig .EmptyWritablePtr (), writableKey , messageBus )
828
+ go commonConfigClient .WatchForChanges (updateStream , errorStream , fullServiceConfig .EmptyWritablePtr (), writableKey , cp .getMessageClient )
882
829
883
830
for {
884
831
select {
@@ -1129,6 +1076,26 @@ func (cp *Processor) loadConfigFromProvider(serviceConfig interfaces.Configurati
1129
1076
return nil
1130
1077
}
1131
1078
1079
+ // getMessageClient waits and gets the message client
1080
+ func (cp * Processor ) getMessageClient () (msgClient messaging.MessageClient ) {
1081
+ // there's no startupTimer for cp created by NewProcessorForCustomConfig
1082
+ // add a new startupTimer here
1083
+ if ! cp .startupTimer .HasNotElapsed () {
1084
+ cp .startupTimer = startup .NewStartUpTimer ("" )
1085
+ }
1086
+ for cp .startupTimer .HasNotElapsed () {
1087
+ if msgClient = container .MessagingClientFrom (cp .dic .Get ); msgClient != nil {
1088
+ break
1089
+ }
1090
+ cp .startupTimer .SleepForInterval ()
1091
+ }
1092
+ if msgClient == nil {
1093
+ cp .lc .Error ("unable to use MessageClient to watch for configuration changes" )
1094
+ return nil
1095
+ }
1096
+ return msgClient
1097
+ }
1098
+
1132
1099
// getSecretNamesChanged returns a slice of secretNames that have changed secrets or are new.
1133
1100
func getSecretNamesChanged (prevVals config.InsecureSecrets , curVals config.InsecureSecrets ) []string {
1134
1101
var updatedNames []string
0 commit comments