@@ -18,6 +18,8 @@ import (
1818 "time"
1919
2020 aperLogger "github.com/omec-project/aper/logger"
21+ grpcClient "github.com/omec-project/config5g/proto/client"
22+ protos "github.com/omec-project/config5g/proto/sdcoreConfig"
2123 nasLogger "github.com/omec-project/nas/logger"
2224 ngapLogger "github.com/omec-project/ngap/logger"
2325 openapiLogger "github.com/omec-project/openapi/logger"
@@ -139,9 +141,65 @@ func (smf *SMF) Initialize(c *cli.Context) error {
139141 }()
140142 }
141143
144+ if os .Getenv ("MANAGED_BY_CONFIG_POD" ) == "true" {
145+ logger .InitLog .Infoln ("MANAGED_BY_CONFIG_POD is true" )
146+ go manageGrpcClient (factory .SmfConfig .Configuration .WebuiUri )
147+ }
142148 return nil
143149}
144150
151+ // manageGrpcClient connects the config pod GRPC server and subscribes the config changes.
152+ // Then it updates SMF configuration.
153+ func manageGrpcClient (webuiUri string ) {
154+ var configChannel chan * protos.NetworkSliceResponse
155+ var client grpcClient.ConfClient
156+ var stream protos.ConfigService_NetworkSliceSubscribeClient
157+ var err error
158+ count := 0
159+ for {
160+ if client != nil {
161+ if client .CheckGrpcConnectivity () != "ready" {
162+ time .Sleep (time .Second * 30 )
163+ count ++
164+ if count > 5 {
165+ err = client .GetConfigClientConn ().Close ()
166+ if err != nil {
167+ logger .InitLog .Infof ("failing ConfigClient is not closed properly: %+v" , err )
168+ }
169+ client = nil
170+ count = 0
171+ }
172+ logger .InitLog .Infoln ("checking the connectivity readiness" )
173+ continue
174+ }
175+
176+ if stream == nil {
177+ stream , err = client .SubscribeToConfigServer ()
178+ if err != nil {
179+ logger .InitLog .Infof ("failing SubscribeToConfigServer: %+v" , err )
180+ continue
181+ }
182+ }
183+
184+ if configChannel == nil {
185+ configChannel = client .PublishOnConfigChange (true , stream )
186+ logger .InitLog .Infoln ("PublishOnConfigChange is triggered" )
187+ go factory .SmfConfig .UpdateConfig (configChannel )
188+ logger .InitLog .Infoln ("SMF updateConfig is triggered" )
189+ }
190+ } else {
191+ client , err = grpcClient .ConnectToConfigServer (webuiUri )
192+ stream = nil
193+ configChannel = nil
194+ logger .InitLog .Infoln ("connecting to config server" )
195+ if err != nil {
196+ logger .InitLog .Errorf ("%+v" , err )
197+ }
198+ continue
199+ }
200+ }
201+ }
202+
145203func (smf * SMF ) setLogLevel () {
146204 if factory .SmfConfig .Logger == nil {
147205 logger .InitLog .Warnln ("SMF config without log level setting" )
@@ -263,10 +321,9 @@ func (smf *SMF) Start() {
263321 context .InitSMFUERouting (& factory .UERoutingConfig )
264322
265323 // Wait for additional/updated config from config pod
266- roc := os .Getenv ("MANAGED_BY_CONFIG_POD" )
267- if roc == "true" {
268- logger .InitLog .Infoln ("configuration is managed by Config Pod" )
269- logger .InitLog .Infoln ("waiting for initial configuration from config pod" )
324+ if os .Getenv ("MANAGED_BY_CONFIG_POD" ) == "true" {
325+ logger .InitLog .Infof ("configuration is managed by Config Pod" )
326+ logger .InitLog .Infof ("waiting for initial configuration from config pod" )
270327
271328 // Main thread should be blocked for config update from ROC
272329 // Future config update from ROC can be handled via background go-routine.
0 commit comments