@@ -18,6 +18,8 @@ import (
1818 "syscall"
1919 "time"
2020
21+ grpcClient "github.com/omec-project/config5g/proto/client"
22+ protos "github.com/omec-project/config5g/proto/sdcoreConfig"
2123 "github.com/omec-project/openapi/models"
2224 "github.com/omec-project/udr/consumer"
2325 "github.com/omec-project/udr/context"
@@ -85,9 +87,71 @@ func (udr *UDR) Initialize(c *cli.Context) error {
8587 return err
8688 }
8789
90+ if os .Getenv ("MANAGED_BY_CONFIG_POD" ) == "true" {
91+ logger .InitLog .Infoln ("MANAGED_BY_CONFIG_POD is true" )
92+ go manageGrpcClient (factory .UdrConfig .Configuration .WebuiUri )
93+ } else {
94+ go func () {
95+ logger .InitLog .Infoln ("use helm chart config" )
96+ factory .ConfigPodTrigger <- true
97+ }()
98+ }
99+
88100 return nil
89101}
90102
103+ // manageGrpcClient connects the config pod GRPC server and subscribes the config changes.
104+ // Then it updates UDR configuration.
105+ func manageGrpcClient (webuiUri string ) {
106+ var configChannel chan * protos.NetworkSliceResponse
107+ var client grpcClient.ConfClient
108+ var stream protos.ConfigService_NetworkSliceSubscribeClient
109+ var err error
110+ count := 0
111+ for {
112+ if client != nil {
113+ if client .CheckGrpcConnectivity () != "ready" {
114+ time .Sleep (time .Second * 30 )
115+ count ++
116+ if count > 5 {
117+ err = client .GetConfigClientConn ().Close ()
118+ if err != nil {
119+ logger .InitLog .Infof ("failing ConfigClient is not closed properly: %+v" , err )
120+ }
121+ client = nil
122+ count = 0
123+ }
124+ logger .InitLog .Infoln ("checking the connectivity readiness" )
125+ continue
126+ }
127+
128+ if stream == nil {
129+ stream , err = client .SubscribeToConfigServer ()
130+ if err != nil {
131+ logger .InitLog .Infof ("failing SubscribeToConfigServer: %+v" , err )
132+ continue
133+ }
134+ }
135+
136+ if configChannel == nil {
137+ configChannel = client .PublishOnConfigChange (true , stream )
138+ logger .InitLog .Infoln ("PublishOnConfigChange is triggered" )
139+ go factory .UdrConfig .UpdateConfig (configChannel , factory .ConfigUpdateDbTrigger )
140+ logger .InitLog .Infoln ("UDR updateConfig is triggered" )
141+ }
142+ } else {
143+ client , err = grpcClient .ConnectToConfigServer (webuiUri )
144+ stream = nil
145+ configChannel = nil
146+ logger .InitLog .Infoln ("connecting to config server" )
147+ if err != nil {
148+ logger .InitLog .Errorf ("%+v" , err )
149+ }
150+ continue
151+ }
152+ }
153+ }
154+
91155func (udr * UDR ) setLogLevel () {
92156 if factory .UdrConfig .Logger == nil {
93157 logger .InitLog .Warnln ("UDR config without log level setting" )
0 commit comments