@@ -17,7 +17,7 @@ import (
17
17
"syscall"
18
18
"time"
19
19
20
- "github.com/omec-project/config5g/proto/client"
20
+ grpcClient "github.com/omec-project/config5g/proto/client"
21
21
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
22
22
"github.com/omec-project/openapi/models"
23
23
nrfCache "github.com/omec-project/openapi/nrfcache"
@@ -101,21 +101,71 @@ func (udm *UDM) Initialize(c *cli.Context) error {
101
101
return err
102
102
}
103
103
104
- roc := os .Getenv ("MANAGED_BY_CONFIG_POD" )
105
- if roc == "true" {
104
+ if os .Getenv ("MANAGED_BY_CONFIG_POD" ) == "true" {
106
105
logger .InitLog .Infoln ("MANAGED_BY_CONFIG_POD is true" )
107
- commChannel := client .ConfigWatcher (factory .UdmConfig .Configuration .WebuiUri )
108
- go udm .updateConfig (commChannel )
106
+ go manageGrpcClient (factory .UdmConfig .Configuration .WebuiUri , udm )
109
107
} else {
110
108
go func () {
111
- logger .InitLog .Infoln ("use helm chart config" )
109
+ logger .InitLog .Infoln ("use helm chart config " )
112
110
ConfigPodTrigger <- true
113
111
}()
114
112
}
115
113
116
114
return nil
117
115
}
118
116
117
+ // manageGrpcClient connects the config pod GRPC server and subscribes the config changes.
118
+ // Then it updates UDM configuration.
119
+ func manageGrpcClient (webuiUri string , udm * UDM ) {
120
+ var configChannel chan * protos.NetworkSliceResponse
121
+ var client grpcClient.ConfClient
122
+ var stream protos.ConfigService_NetworkSliceSubscribeClient
123
+ var err error
124
+ count := 0
125
+ for {
126
+ if client != nil {
127
+ if client .CheckGrpcConnectivity () != "ready" {
128
+ time .Sleep (time .Second * 30 )
129
+ count ++
130
+ if count > 5 {
131
+ err = client .GetConfigClientConn ().Close ()
132
+ if err != nil {
133
+ logger .InitLog .Infof ("failing ConfigClient is not closed properly: %+v" , err )
134
+ }
135
+ client = nil
136
+ count = 0
137
+ }
138
+ logger .InitLog .Infoln ("checking the connectivity readiness" )
139
+ continue
140
+ }
141
+
142
+ if stream == nil {
143
+ stream , err = client .SubscribeToConfigServer ()
144
+ if err != nil {
145
+ logger .InitLog .Infof ("failing SubscribeToConfigServer: %+v" , err )
146
+ continue
147
+ }
148
+ }
149
+
150
+ if configChannel == nil {
151
+ configChannel = client .PublishOnConfigChange (true , stream )
152
+ logger .InitLog .Infoln ("PublishOnConfigChange is triggered" )
153
+ go udm .updateConfig (configChannel )
154
+ logger .InitLog .Infoln ("UDM updateConfig is triggered" )
155
+ }
156
+ } else {
157
+ client , err = grpcClient .ConnectToConfigServer (webuiUri )
158
+ stream = nil
159
+ configChannel = nil
160
+ logger .InitLog .Infoln ("connecting to config server" )
161
+ if err != nil {
162
+ logger .InitLog .Errorf ("%+v" , err )
163
+ }
164
+ continue
165
+ }
166
+ }
167
+ }
168
+
119
169
func (udm * UDM ) setLogLevel () {
120
170
if factory .UdmConfig .Logger == nil {
121
171
logger .InitLog .Warnln ("UDM config without log level setting" )
0 commit comments