diff --git a/Makefile b/Makefile index 78c1f4e..028bebb 100644 --- a/Makefile +++ b/Makefile @@ -95,3 +95,8 @@ test: .coverage -v \ ./ ./... +fmt: + @go fmt ./... + +golint: + @docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:latest golangci-lint run -v --config /app/.golangci.yml diff --git a/VERSION b/VERSION index 06bb452..9c6d629 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.1-dev +1.6.1 diff --git a/factory/config.go b/factory/config.go index 638901f..9b4c3e5 100644 --- a/factory/config.go +++ b/factory/config.go @@ -80,6 +80,7 @@ var ( func init() { ConfigPodTrigger = make(chan bool) + ConfigUpdateDbTrigger = make(chan *UpdateDb, 10) } func (c *Config) GetVersion() string { @@ -106,7 +107,7 @@ func (c *Config) addSmPolicyInfo(nwSlice *protos.NetworkSlice, dbUpdateChannel c return nil } -func (c *Config) updateConfig(commChannel chan *protos.NetworkSliceResponse, dbUpdateChannel chan *UpdateDb) bool { +func (c *Config) UpdateConfig(commChannel chan *protos.NetworkSliceResponse, dbUpdateChannel chan *UpdateDb) bool { var minConfig bool for rsp := range commChannel { logger.GrpcLog.Infoln("received updateConfig in the udr app:", rsp) diff --git a/factory/factory.go b/factory/factory.go index 3d94b97..2678ea8 100644 --- a/factory/factory.go +++ b/factory/factory.go @@ -14,7 +14,6 @@ import ( "fmt" "os" - "github.com/omec-project/config5g/proto/client" protos "github.com/omec-project/config5g/proto/sdcoreConfig" "github.com/omec-project/udr/logger" "gopkg.in/yaml.v2" @@ -52,18 +51,6 @@ func InitConfigFactory(f string) error { if UdrConfig.Configuration.WebuiUri == "" { UdrConfig.Configuration.WebuiUri = "webui:9876" } - roc := os.Getenv("MANAGED_BY_CONFIG_POD") - if roc == "true" { - logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true") - commChannel := client.ConfigWatcher(UdrConfig.Configuration.WebuiUri) - ConfigUpdateDbTrigger = make(chan *UpdateDb, 10) - go UdrConfig.updateConfig(commChannel, ConfigUpdateDbTrigger) - } else { - go func() { - logger.InitLog.Infoln("use helm chart config") - ConfigPodTrigger <- true - }() - } } return nil diff --git a/go.mod b/go.mod index 40fd5b5..f44f4f2 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 github.com/mitchellh/mapstructure v1.5.0 - github.com/omec-project/config5g v1.5.1 + github.com/omec-project/config5g v1.5.4 github.com/omec-project/openapi v1.3.1 github.com/omec-project/util v1.2.3 github.com/prometheus/client_golang v1.20.5 @@ -70,7 +70,7 @@ require ( golang.org/x/text v0.19.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/grpc v1.67.1 // indirect - google.golang.org/protobuf v1.34.2 // indirect + google.golang.org/protobuf v1.35.1 // indirect gopkg.in/h2non/gock.v1 v1.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 0ef5662..2b98089 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/omec-project/config5g v1.5.1 h1:JaVgr76tnjJIb7Uoesv5a9GI72NdOXtCvfukj0/ONio= -github.com/omec-project/config5g v1.5.1/go.mod h1:o04ZdwGcM7tbGjuT5t/WzYSKLXOSnFl6vH7b6BGAspU= +github.com/omec-project/config5g v1.5.4 h1:5JMw5Fsr5qyLZpQi3IZQaQPj78QJMFQXDVS3QDMOY9Y= +github.com/omec-project/config5g v1.5.4/go.mod h1:HOvQtmi79f8cw35AiFHWHDoCTuZbXfMjeFJWgtPbwaI= github.com/omec-project/openapi v1.3.1 h1:NCteMRdMtWnMhf1CXYduuLgeu8fEhc/7XO1CiE7fN3Y= github.com/omec-project/openapi v1.3.1/go.mod h1:cR6Iharp2TLOzEmskQ/EdCVFZnpKh0zTvUSSuyXAYLE= github.com/omec-project/util v1.2.3 h1:h32ZYFT99+fB9VPp1CQUIKwrSP6RtX+PbFDcqmEHmn0= @@ -183,8 +183,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/service/init.go b/service/init.go index 3a90f77..146abc2 100644 --- a/service/init.go +++ b/service/init.go @@ -18,6 +18,8 @@ import ( "syscall" "time" + grpcClient "github.com/omec-project/config5g/proto/client" + protos "github.com/omec-project/config5g/proto/sdcoreConfig" "github.com/omec-project/openapi/models" "github.com/omec-project/udr/consumer" "github.com/omec-project/udr/context" @@ -85,9 +87,71 @@ func (udr *UDR) Initialize(c *cli.Context) error { return err } + if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" { + logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true") + go manageGrpcClient(factory.UdrConfig.Configuration.WebuiUri) + } else { + go func() { + logger.InitLog.Infoln("use helm chart config") + factory.ConfigPodTrigger <- true + }() + } + return nil } +// manageGrpcClient connects the config pod GRPC server and subscribes the config changes. +// Then it updates UDR configuration. +func manageGrpcClient(webuiUri string) { + var configChannel chan *protos.NetworkSliceResponse + var client grpcClient.ConfClient + var stream protos.ConfigService_NetworkSliceSubscribeClient + var err error + count := 0 + for { + if client != nil { + if client.CheckGrpcConnectivity() != "ready" { + time.Sleep(time.Second * 30) + count++ + if count > 5 { + err = client.GetConfigClientConn().Close() + if err != nil { + logger.InitLog.Infof("failing ConfigClient is not closed properly: %+v", err) + } + client = nil + count = 0 + } + logger.InitLog.Infoln("checking the connectivity readiness") + continue + } + + if stream == nil { + stream, err = client.SubscribeToConfigServer() + if err != nil { + logger.InitLog.Infof("failing SubscribeToConfigServer: %+v", err) + continue + } + } + + if configChannel == nil { + configChannel = client.PublishOnConfigChange(true, stream) + logger.InitLog.Infoln("PublishOnConfigChange is triggered") + go factory.UdrConfig.UpdateConfig(configChannel, factory.ConfigUpdateDbTrigger) + logger.InitLog.Infoln("UDR updateConfig is triggered") + } + } else { + client, err = grpcClient.ConnectToConfigServer(webuiUri) + stream = nil + configChannel = nil + logger.InitLog.Infoln("connecting to config server") + if err != nil { + logger.InitLog.Errorf("%+v", err) + } + continue + } + } +} + func (udr *UDR) setLogLevel() { if factory.UdrConfig.Logger == nil { logger.InitLog.Warnln("UDR config without log level setting")