From: DenisGNoonan Date: Fri, 19 Apr 2024 17:22:31 +0000 (+0100) Subject: NONRTRIC-946: Servicemanager - add Kong data plane and control plane X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=fdb05902d0e3234446ac0cfd8ffed0743cfd20e5;p=nonrtric%2Fplt%2Fsme.git NONRTRIC-946: Servicemanager - add Kong data plane and control plane Issue-ID: NONRTRIC-946 Change-Id: Icb28b525b0bd49135b03657b3ac7bb41f1ec79f4 Signed-off-by: DenisGNoonan --- diff --git a/servicemanager/.env.example b/servicemanager/.env.example index 5f7bfe1..1d3c4ef 100644 --- a/servicemanager/.env.example +++ b/servicemanager/.env.example @@ -1,12 +1,16 @@ +# The Kong Data plane provides the endpoint that Service Manager gives to the rApp so that the rApp can invoke the CAPIF published API. +# In a Kubernetes environment, we need to use the Kong NodePort IP and nodePort if the rApp needs access from outside the Kong cluster. +# From inside the Kong cluster, we can use the Kubernetes cluster DNS entry, kong-nonrtric-kong-proxy.nonrtric.svc.cluster.local. KONG_DOMAIN= KONG_PROTOCOL= -KONG_IPV4= -KONG_DATA_PLANE_PORT= +KONG_CONTROL_PLANE_IPV4= KONG_CONTROL_PLANE_PORT= +KONG_DATA_PLANE_IPV4= +KONG_DATA_PLANE_PORT= CAPIF_PROTOCOL= CAPIF_IPV4= CAPIF_PORT= LOG_LEVEL= SERVICE_MANAGER_PORT= TEST_SERVICE_IPV4= -TEST_SERVICE_PORT= \ No newline at end of file +TEST_SERVICE_PORT= diff --git a/servicemanager/container-tag.yaml b/servicemanager/container-tag.yaml index 8f5dc8d..ced992f 100644 --- a/servicemanager/container-tag.yaml +++ b/servicemanager/container-tag.yaml @@ -19,4 +19,4 @@ # By default this file is in the docker build directory, # but the location can configured in the JJB template. --- -tag: 0.1.1 +tag: 0.1.2 diff --git a/servicemanager/deploy/manifests/capifcore.yaml b/servicemanager/deploy/manifests/capifcore.yaml index 0c98592..a4f252f 100644 --- a/servicemanager/deploy/manifests/capifcore.yaml +++ b/servicemanager/deploy/manifests/capifcore.yaml @@ -36,7 +36,7 @@ spec: spec: containers: - name: capifcore - image: "nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-capifcore:1.3.1" + image: "nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-capifcore:CAPIF_VERSION" imagePullPolicy: IfNotPresent ports: - containerPort: 8090 @@ -59,7 +59,7 @@ spec: app: capifcore ports: - protocol: TCP - port: 80 + port: 8090 targetPort: 8090 nodePort: 31570 type: NodePort diff --git a/servicemanager/deploy/manifests/servicemanager.yaml b/servicemanager/deploy/manifests/servicemanager.yaml index c49a9a6..a8e99ce 100644 --- a/servicemanager/deploy/manifests/servicemanager.yaml +++ b/servicemanager/deploy/manifests/servicemanager.yaml @@ -36,7 +36,7 @@ spec: spec: containers: - name: servicemanager - image: "nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-servicemanager:0.1.1" + image: "nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-servicemanager:SERVICEMANAGER_VERSION" imagePullPolicy: IfNotPresent env: - name: SERVICE_MANAGER_ENV @@ -69,7 +69,7 @@ spec: app: servicemanager ports: - protocol: TCP - port: 80 + port: 8095 targetPort: 8095 nodePort: 31575 type: NodePort diff --git a/servicemanager/deploy/src/deploy-to-k8s.sh b/servicemanager/deploy/src/deploy-to-k8s.sh index be890dd..18a0583 100755 --- a/servicemanager/deploy/src/deploy-to-k8s.sh +++ b/servicemanager/deploy/src/deploy-to-k8s.sh @@ -24,12 +24,13 @@ create_env_from_template(){ cp -v ../../.env.example ../../.env sed -i 's/KONG_DOMAIN=/KONG_DOMAIN=kong/' ../../.env sed -i 's/KONG_PROTOCOL=/KONG_PROTOCOL=http/' ../../.env - sed -i 's/KONG_IPV4=/KONG_IPV4=10.101.1.101/' ../../.env - sed -i 's/KONG_DATA_PLANE_PORT=/KONG_DATA_PLANE_PORT=32080/' ../../.env - sed -i 's/KONG_CONTROL_PLANE_PORT=/KONG_CONTROL_PLANE_PORT=32081/' ../../.env + sed -i 's/KONG_CONTROL_PLANE_IPV4=/KONG_CONTROL_PLANE_IPV4=kong-kong-admin.kong.svc.cluster.local/' ../../.env + sed -i 's/KONG_CONTROL_PLANE_PORT=/KONG_CONTROL_PLANE_PORT=8001/' ../../.env + sed -i 's/KONG_DATA_PLANE_IPV4=/KONG_DATA_PLANE_IPV4=kong-kong-proxy.kong.svc.cluster.local/' ../../.env + sed -i 's/KONG_DATA_PLANE_PORT=/KONG_DATA_PLANE_PORT=80/' ../../.env sed -i 's/CAPIF_PROTOCOL=/CAPIF_PROTOCOL=http/' ../../.env - sed -i 's/CAPIF_IPV4=/CAPIF_IPV4=10.101.1.101/' ../../.env - sed -i 's/CAPIF_PORT=/CAPIF_PORT=31570/' ../../.env + sed -i 's/CAPIF_IPV4=/CAPIF_IPV4=capifcore.servicemanager.svc.cluster.local/' ../../.env + sed -i 's/CAPIF_PORT=/CAPIF_PORT=8090/' ../../.env sed -i 's/LOG_LEVEL=/LOG_LEVEL=Info/' ../../.env sed -i 's/SERVICE_MANAGER_PORT=/SERVICE_MANAGER_PORT=8095/' ../../.env sed -i 's/TEST_SERVICE_IPV4=/TEST_SERVICE_IPV4=10.101.1.101/' ../../.env @@ -40,15 +41,25 @@ create_env_from_template(){ fi } -substitute_repo(){ - echo "substitute_repo" +substitute_repos(){ + echo "substitute_repos" docker_repo=$1 # Use our own Capificore and ServiceManager images - sed -i "s/image: o-ran-sc.org\/nonrtric\/plt\/capifcore/image: $docker_repo\/capifcore:latest/" ../manifests/capifcore.yaml - sed -i 's/imagePullPolicy: IfNotPresent/imagePullPolicy: Always/' ../manifests/capifcore.yaml - sed -i "s/image: o-ran-sc.org\/nonrtric\/plt\/servicemanager/image: $docker_repo\/servicemanager:latest/" ../manifests/servicemanager.yaml - sed -i 's/imagePullPolicy: IfNotPresent/imagePullPolicy: Always/' ../manifests/servicemanager.yaml + sed -i "s*nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-capifcore:CAPIF_VERSION*$docker_repo/capifcore:latest*" ../manifests/capifcore.yaml + sed -i "s*nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-servicemanager:SERVICEMANAGER_VERSION*$docker_repo/servicemanager:latest*" ../manifests/servicemanager.yaml + + sed -i 's*imagePullPolicy: IfNotPresent*imagePullPolicy: Always*' ../manifests/capifcore.yaml + sed -i 's*imagePullPolicy: IfNotPresent*imagePullPolicy: Always*' ../manifests/servicemanager.yaml +} + +substitute_repo_versions(){ + echo "substitute_repo_versions" + servicemanager_version=$(awk '/tag:/{print $2}' ../../container-tag.yaml) + capif_version=$(awk '/tag:/{print $2}' ../../../capifcore/container-tag.yaml) + # Set the Capificore and ServiceManager image versions + sed -i "s*nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-capifcore:CAPIF_VERSION*nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-capifcore:$capif_version*" ../manifests/capifcore.yaml + sed -i "s*nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-servicemanager:SERVICEMANAGER_VERSION*nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-servicemanager:$servicemanager_version*" ../manifests/servicemanager.yaml } add_env(){ @@ -140,7 +151,9 @@ create_env_from_template # Check if the development switch is enabled if [ "$USE_OWN_REPO" = true ]; then - substitute_repo $DOCKER_REPO + substitute_repos $DOCKER_REPO +else + substitute_repo_versions fi kubectl create ns servicemanager diff --git a/servicemanager/internal/discoverservice/discoverservice_test.go b/servicemanager/internal/discoverservice/discoverservice_test.go index 7c4b9f8..ab6ae85 100644 --- a/servicemanager/internal/discoverservice/discoverservice_test.go +++ b/servicemanager/internal/discoverservice/discoverservice_test.go @@ -54,17 +54,17 @@ import ( "oransc.org/nonrtric/servicemanager/internal/publishservice" "oransc.org/nonrtric/capifcore" - "oransc.org/nonrtric/servicemanager/mockkong" + mockKong "oransc.org/nonrtric/servicemanager/mockkong" ) var ( - eServiceManager *echo.Echo - eCapifWeb *echo.Echo - eKong *echo.Echo - mockConfigReader *envreader.MockConfigReader + eServiceManager *echo.Echo + eCapifWeb *echo.Echo + eKong *echo.Echo + mockConfigReader *envreader.MockConfigReader serviceManagerServer *httptest.Server - capifServer *httptest.Server - mockKongServer *httptest.Server + capifServer *httptest.Server + mockKongServer *httptest.Server ) func TestMain(m *testing.M) { @@ -117,9 +117,10 @@ func setupTest() error { MockedConfig: map[string]string{ "KONG_DOMAIN": "kong", "KONG_PROTOCOL": "http", - "KONG_IPV4": mockKongHost, - "KONG_DATA_PLANE_PORT": "32080", + "KONG_CONTROL_PLANE_IPV4": mockKongHost, "KONG_CONTROL_PLANE_PORT": mockKongControlPlanePort, + "KONG_DATA_PLANE_IPV4": "10.101.1.101", + "KONG_DATA_PLANE_PORT": "32080", "CAPIF_PROTOCOL": "http", "CAPIF_IPV4": capifHost, "CAPIF_PORT": capifPort, @@ -178,8 +179,7 @@ func getProvider() provapi.APIProviderEnrolmentDetails { } } - -func capifCleanUp() { +func capifCleanUp() { t := new(testing.T) // Create a new testing.T instance for capifCleanUp // Delete the invoker @@ -277,7 +277,7 @@ func TestPublishUnpublishService(t *testing.T) { // Check if the parsed array is empty assert.Zero(t, len(resultServices)) - assert.True (t, len(resultServices) == 0) + assert.True(t, len(resultServices) == 0) aefId := "AEF_id_rApp_Kong_as_AEF" namespace := "namespace" @@ -322,13 +322,13 @@ func TestPublishUnpublishService(t *testing.T) { resultServiceIpv4 := *interfaceDescription.Ipv4Addr resultServicePort := *interfaceDescription.Port - kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"]) + kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"]) kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) - assert.NotEmpty(t, kongIPv4, "KONG_IPV4 is required in .env file for unit testing") + assert.NotEmpty(t, kongDataPlaneIPv4, "KONG_DATA_PLANE_IPV4 is required in .env file for unit testing") assert.NotZero(t, kongDataPlanePort, "KONG_DATA_PLANE_PORT is required in .env file for unit testing") - assert.Equal(t, kongIPv4, resultServiceIpv4) + assert.Equal(t, kongDataPlaneIPv4, resultServiceIpv4) assert.Equal(t, kongDataPlanePort, resultServicePort) // Check one service published @@ -340,7 +340,7 @@ func TestPublishUnpublishService(t *testing.T) { assert.NoError(t, err, "error unmarshaling response") // Check if the parsed array has one item - assert.True (t, len(resultServices) == 1) + assert.True(t, len(resultServices) == 1) // Publish a second service for provider apiName2 := "apiName2" @@ -373,7 +373,7 @@ func TestPublishUnpublishService(t *testing.T) { assert.NoError(t, err, "error unmarshaling response") // Check if the parsed array has two items - assert.True (t, len(resultServices) == 2) + assert.True(t, len(resultServices) == 2) } func TestOnboardInvoker(t *testing.T) { @@ -653,9 +653,10 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string] capifPort := common29122.Port(myPorts["CAPIF_PORT"]) kongDomain := myEnv["KONG_DOMAIN"] kongProtocol := myEnv["KONG_PROTOCOL"] - kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"]) - kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) + kongControlPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_CONTROL_PLANE_IPV4"]) kongControlPlanePort := common29122.Port(myPorts["KONG_CONTROL_PLANE_PORT"]) + kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"]) + kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) // Register ProviderManagement providerManagerSwagger, err := provapi.GetSwagger() @@ -681,7 +682,11 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string] publishServiceSwagger.Servers = nil - ps := publishservice.NewPublishService(kongDomain, kongProtocol, kongIPv4, kongDataPlanePort, kongControlPlanePort, capifProtocol, capifIPv4, capifPort) + ps := publishservice.NewPublishService( + kongDomain, kongProtocol, + kongControlPlaneIPv4, kongControlPlanePort, + kongDataPlaneIPv4, kongDataPlanePort, + capifProtocol, capifIPv4, capifPort) group = e.Group("/published-apis/v1") group.Use(echomiddleware.Logger()) diff --git a/servicemanager/internal/envreader/envreader.go b/servicemanager/internal/envreader/envreader.go index 0bdbee7..f08b1d7 100644 --- a/servicemanager/internal/envreader/envreader.go +++ b/servicemanager/internal/envreader/envreader.go @@ -97,9 +97,10 @@ func logConfig(myEnv map[string]string, envFile string) { log.Infof("KONG_DOMAIN %s", myEnv["KONG_DOMAIN"]) log.Infof("KONG_PROTOCOL %s", myEnv["KONG_PROTOCOL"]) - log.Infof("KONG_IPV4 %s", myEnv["KONG_IPV4"]) - log.Infof("KONG_DATA_PLANE_PORT %s", myEnv["KONG_DATA_PLANE_PORT"]) + log.Infof("KONG_CONTROL_PLANE_IPV4 %s", myEnv["KONG_CONTROL_PLANE_IPV4"]) log.Infof("KONG_CONTROL_PLANE_PORT %s", myEnv["KONG_CONTROL_PLANE_PORT"]) + log.Infof("KONG_DATA_PLANE_IPV4 %s", myEnv["KONG_DATA_PLANE_IPV4"]) + log.Infof("KONG_DATA_PLANE_PORT %s", myEnv["KONG_DATA_PLANE_PORT"]) log.Infof("CAPIF_PROTOCOL %s", myEnv["CAPIF_PROTOCOL"]) log.Infof("CAPIF_IPV4 %s", myEnv["CAPIF_IPV4"]) log.Infof("CAPIF_PORT %s", myEnv["CAPIF_PORT"]) diff --git a/servicemanager/internal/invokermanagement/invokermanagement_test.go b/servicemanager/internal/invokermanagement/invokermanagement_test.go index 0096c49..eae25dd 100644 --- a/servicemanager/internal/invokermanagement/invokermanagement_test.go +++ b/servicemanager/internal/invokermanagement/invokermanagement_test.go @@ -46,17 +46,17 @@ import ( "github.com/stretchr/testify/assert" "oransc.org/nonrtric/capifcore" - "oransc.org/nonrtric/servicemanager/mockkong" + mockKong "oransc.org/nonrtric/servicemanager/mockkong" ) var ( - eServiceManager *echo.Echo - eCapifWeb *echo.Echo - eKong *echo.Echo - mockConfigReader *envreader.MockConfigReader + eServiceManager *echo.Echo + eCapifWeb *echo.Echo + eKong *echo.Echo + mockConfigReader *envreader.MockConfigReader serviceManagerServer *httptest.Server - capifServer *httptest.Server - mockKongServer *httptest.Server + capifServer *httptest.Server + mockKongServer *httptest.Server ) func TestMain(m *testing.M) { @@ -109,9 +109,10 @@ func setupTest() error { MockedConfig: map[string]string{ "KONG_DOMAIN": "kong", "KONG_PROTOCOL": "http", - "KONG_IPV4": mockKongHost, - "KONG_DATA_PLANE_PORT": "32080", + "KONG_CONTROL_PLANE_IPV4": mockKongHost, "KONG_CONTROL_PLANE_PORT": mockKongControlPlanePort, + "KONG_DATA_PLANE_IPV4": "10.101.1.101", + "KONG_DATA_PLANE_PORT": "32080", "CAPIF_PROTOCOL": "http", "CAPIF_IPV4": capifHost, "CAPIF_PORT": capifPort, @@ -170,7 +171,7 @@ func getProvider() provapi.APIProviderEnrolmentDetails { } } -func capifCleanUp() { +func capifCleanUp() { t := new(testing.T) // Create a new testing.T instance for capifCleanUp // Delete the invoker @@ -309,13 +310,13 @@ func TestPublishUnpublishService(t *testing.T) { resultServiceIpv4 := *interfaceDescription.Ipv4Addr resultServicePort := *interfaceDescription.Port - kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"]) + kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"]) kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) - assert.NotEmpty(t, kongIPv4, "KONG_IPV4 is required in .env file for unit testing") + assert.NotEmpty(t, kongDataPlaneIPv4, "KONG_DATA_PLANE_IPV4 is required in .env file for unit testing") assert.NotZero(t, kongDataPlanePort, "KONG_DATA_PLANE_PORT is required in .env file for unit testing") - assert.Equal(t, kongIPv4, resultServiceIpv4) + assert.Equal(t, kongDataPlaneIPv4, resultServiceIpv4) assert.Equal(t, kongDataPlanePort, resultServicePort) } @@ -489,9 +490,10 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string] capifPort := common29122.Port(myPorts["CAPIF_PORT"]) kongDomain := myEnv["KONG_DOMAIN"] kongProtocol := myEnv["KONG_PROTOCOL"] - kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"]) - kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) + kongControlPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_CONTROL_PLANE_IPV4"]) kongControlPlanePort := common29122.Port(myPorts["KONG_CONTROL_PLANE_PORT"]) + kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"]) + kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) // Register ProviderManagement providerManagerSwagger, err := provapi.GetSwagger() @@ -516,7 +518,11 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string] publishServiceSwagger.Servers = nil - ps := publishservice.NewPublishService(kongDomain, kongProtocol, kongIPv4, kongDataPlanePort, kongControlPlanePort, capifProtocol, capifIPv4, capifPort) + ps := publishservice.NewPublishService( + kongDomain, kongProtocol, + kongControlPlaneIPv4, kongControlPlanePort, + kongDataPlaneIPv4, kongDataPlanePort, + capifProtocol, capifIPv4, capifPort) group = e.Group("/published-apis/v1") group.Use(echomiddleware.Logger()) diff --git a/servicemanager/internal/kongclear/kongclear.go b/servicemanager/internal/kongclear/kongclear.go index 6ec3f08..60aa160 100644 --- a/servicemanager/internal/kongclear/kongclear.go +++ b/servicemanager/internal/kongclear/kongclear.go @@ -66,7 +66,7 @@ type Service struct { func KongClear(myEnv map[string]string, myPorts map[string]int) error { log.Info("delete only ServiceManager Kong routes and services") - kongAdminApiUrl := fmt.Sprintf("%s://%s:%d/", myEnv["KONG_PROTOCOL"], myEnv["KONG_IPV4"], myPorts["KONG_CONTROL_PLANE_PORT"]) + kongAdminApiUrl := fmt.Sprintf("%s://%s:%d/", myEnv["KONG_PROTOCOL"], myEnv["KONG_CONTROL_PLANE_IPV4"], myPorts["KONG_CONTROL_PLANE_PORT"]) err := deleteRoutes(kongAdminApiUrl) if err != nil { diff --git a/servicemanager/internal/providermanagement/providermanagement_test.go b/servicemanager/internal/providermanagement/providermanagement_test.go index 3d07f90..9b8d1b9 100644 --- a/servicemanager/internal/providermanagement/providermanagement_test.go +++ b/servicemanager/internal/providermanagement/providermanagement_test.go @@ -116,9 +116,10 @@ func setupTest() error { MockedConfig: map[string]string{ "KONG_DOMAIN": "kong", "KONG_PROTOCOL": "http", - "KONG_IPV4": mockKongHost, + "KONG_CONTROL_PLANE_IPV4": mockKongHost, + "KONG_CONTROL_PLANE_PORT": mockKongControlPlanePort, + "KONG_DATA_PLANE_IPV4": "10.101.1.101", "KONG_DATA_PLANE_PORT": "32080", - "KONG_CONTROL_PLANE_PORT": mockKongControlPlanePort, "CAPIF_PROTOCOL": "http", "CAPIF_IPV4": capifHost, "CAPIF_PORT": capifPort, diff --git a/servicemanager/internal/publishservice/publishservice.go b/servicemanager/internal/publishservice/publishservice.go index 84d2bab..4031827 100644 --- a/servicemanager/internal/publishservice/publishservice.go +++ b/servicemanager/internal/publishservice/publishservice.go @@ -36,22 +36,33 @@ import ( type PublishService struct { KongDomain string; KongProtocol string; - KongIPv4 common29122.Ipv4Addr; - KongDataPlanePort common29122.Port; KongControlPlanePort common29122.Port; + KongControlPlaneIPv4 common29122.Ipv4Addr; + KongDataPlaneIPv4 common29122.Ipv4Addr; + KongDataPlanePort common29122.Port; CapifProtocol string; CapifIPv4 common29122.Ipv4Addr; CapifPort common29122.Port; } // Creates a service that implements both the PublishRegister and the publishserviceapi.ServerInterface interfaces. -func NewPublishService(kongDomain string, kongProtocol string, kongIPv4 common29122.Ipv4Addr, kongDataPlanePort common29122.Port, kongControlPlanePort common29122.Port, capifProtocol string, capifIPv4 common29122.Ipv4Addr, capifPort common29122.Port) *PublishService { +func NewPublishService( + kongDomain string, + kongProtocol string, + kongControlPlaneIPv4 common29122.Ipv4Addr, + kongControlPlanePort common29122.Port, + kongDataPlaneIPv4 common29122.Ipv4Addr, + kongDataPlanePort common29122.Port, + capifProtocol string, + capifIPv4 common29122.Ipv4Addr, + capifPort common29122.Port) *PublishService { return &PublishService{ KongDomain : kongDomain, KongProtocol : kongProtocol, - KongIPv4 : kongIPv4, - KongDataPlanePort : kongDataPlanePort, + KongControlPlaneIPv4 : kongControlPlaneIPv4, KongControlPlanePort : kongControlPlanePort, + KongDataPlaneIPv4 : kongDataPlaneIPv4, + KongDataPlanePort : kongDataPlanePort, CapifProtocol : capifProtocol, CapifIPv4 : capifIPv4, CapifPort : capifPort, @@ -61,6 +72,8 @@ func NewPublishService(kongDomain string, kongProtocol string, kongIPv4 common29 // Publish a new API. func (ps *PublishService) PostApfIdServiceApis(ctx echo.Context, apfId string) error { log.Tracef("entering PostApfIdServiceApis apfId %s", apfId) + log.Debugf("PostApfIdServiceApis KongControlPlaneIPv4 %s", ps.KongControlPlaneIPv4) + log.Debugf("PostApfIdServiceApis KongDataPlaneIPv4 %s", ps.KongDataPlaneIPv4) capifcoreUrl := fmt.Sprintf("%s://%s:%d/published-apis/v1/", ps.CapifProtocol, ps.CapifIPv4, ps.CapifPort) client, err := publishapi.NewClientWithResponses(capifcoreUrl) @@ -82,7 +95,14 @@ func (ps *PublishService) PostApfIdServiceApis(ctx echo.Context, apfId string) e newServiceAPIDescription.PrepareNewService() - statusCode, err := newServiceAPIDescription.RegisterKong(ps.KongDomain, ps.KongProtocol, ps.KongIPv4, ps.KongDataPlanePort, ps.KongControlPlanePort, apfId) + statusCode, err := newServiceAPIDescription.RegisterKong( + ps.KongDomain, + ps.KongProtocol, + ps.KongControlPlaneIPv4, + ps.KongControlPlanePort, + ps.KongDataPlaneIPv4, + ps.KongDataPlanePort, + apfId) if (err != nil) || (statusCode != http.StatusCreated) { // We can return with http.StatusForbidden if there is a http.StatusConflict detected by Kong msg := err.Error() @@ -107,7 +127,7 @@ func (ps *PublishService) PostApfIdServiceApis(ctx echo.Context, apfId string) e log.Debugf("PostApfIdServiceApisWithResponse status code %d", rsp.StatusCode()) log.Debugf("PostApfIdServiceApisWithResponse error %s", msg) if rsp.StatusCode() == http.StatusForbidden || rsp.StatusCode() == http.StatusBadRequest { - newServiceAPIDescription.UnregisterKong(ps.KongDomain, ps.KongProtocol, ps.KongIPv4, ps.KongDataPlanePort, ps.KongControlPlanePort) + newServiceAPIDescription.UnregisterKong(ps.KongDomain, ps.KongProtocol, ps.KongControlPlaneIPv4, ps.KongControlPlanePort) } return sendCoreError(ctx, rsp.StatusCode(), msg) } @@ -161,7 +181,8 @@ func (ps *PublishService) DeleteApfIdServiceApisServiceApiId(ctx echo.Context, a } rspServiceAPIDescription := *rsp.JSON200 - statusCode, err = rspServiceAPIDescription.UnregisterKong(ps.KongDomain, ps.KongProtocol, ps.KongIPv4, ps.KongDataPlanePort, ps.KongControlPlanePort) + + statusCode, err = rspServiceAPIDescription.UnregisterKong(ps.KongDomain, ps.KongProtocol, ps.KongControlPlaneIPv4, ps.KongControlPlanePort) if (err != nil) || (statusCode != http.StatusNoContent) { msg := err.Error() log.Errorf("error on UnregisterKong %s", msg) @@ -302,7 +323,7 @@ func (ps *PublishService) PutApfIdServiceApisServiceApiId(ctx echo.Context, apfI if rsp.StatusCode() != http.StatusOK { log.Errorf("PutApfIdServiceApisServiceApiIdWithResponse status code %d", rsp.StatusCode()) if rsp.StatusCode() == http.StatusBadRequest { - updatedServiceDescription.UnregisterKong(ps.KongDomain, ps.KongProtocol, ps.KongIPv4, ps.KongDataPlanePort, ps.KongControlPlanePort) + updatedServiceDescription.UnregisterKong(ps.KongDomain, ps.KongProtocol,ps.KongControlPlaneIPv4, ps.KongControlPlanePort) } msg := string(rsp.Body) return sendCoreError(ctx, rsp.StatusCode(), msg) diff --git a/servicemanager/internal/publishservice/publishservice_test.go b/servicemanager/internal/publishservice/publishservice_test.go index 7bec335..c42cba7 100644 --- a/servicemanager/internal/publishservice/publishservice_test.go +++ b/servicemanager/internal/publishservice/publishservice_test.go @@ -45,17 +45,17 @@ import ( publishapi "oransc.org/nonrtric/servicemanager/internal/publishserviceapi" "oransc.org/nonrtric/capifcore" - "oransc.org/nonrtric/servicemanager/mockkong" + mockKong "oransc.org/nonrtric/servicemanager/mockkong" ) var ( - eServiceManager *echo.Echo - eCapifWeb *echo.Echo - eKong *echo.Echo - mockConfigReader *envreader.MockConfigReader + eServiceManager *echo.Echo + eCapifWeb *echo.Echo + eKong *echo.Echo + mockConfigReader *envreader.MockConfigReader serviceManagerServer *httptest.Server - capifServer *httptest.Server - mockKongServer *httptest.Server + capifServer *httptest.Server + mockKongServer *httptest.Server ) func TestMain(m *testing.M) { @@ -108,9 +108,10 @@ func setupTest() error { MockedConfig: map[string]string{ "KONG_DOMAIN": "kong", "KONG_PROTOCOL": "http", - "KONG_IPV4": mockKongHost, - "KONG_DATA_PLANE_PORT": "32080", + "KONG_CONTROL_PLANE_IPV4": mockKongHost, "KONG_CONTROL_PLANE_PORT": mockKongControlPlanePort, + "KONG_DATA_PLANE_IPV4": "10.101.1.101", + "KONG_DATA_PLANE_PORT": "32080", "CAPIF_PROTOCOL": "http", "CAPIF_IPV4": capifHost, "CAPIF_PORT": capifPort, @@ -168,7 +169,7 @@ func getProvider() provapi.APIProviderEnrolmentDetails { } } -func capifCleanUp() { +func capifCleanUp() { t := new(testing.T) // Create a new testing.T instance for capifCleanUp // Delete the invoker @@ -364,13 +365,13 @@ func TestPublishUnpublishService(t *testing.T) { resultServiceIpv4 := *interfaceDescription.Ipv4Addr resultServicePort := *interfaceDescription.Port - kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"]) + kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"]) kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) - assert.NotEmpty(t, kongIPv4, "KONG_IPV4 is required in .env file for unit testing") + assert.NotEmpty(t, kongDataPlaneIPv4, "KONG_DATA_PLANE_IPV4 is required in .env file for unit testing") assert.NotZero(t, kongDataPlanePort, "KONG_DATA_PLANE_PORT is required in .env file for unit testing") - assert.Equal(t, kongIPv4, resultServiceIpv4) + assert.Equal(t, kongDataPlaneIPv4, resultServiceIpv4) assert.Equal(t, kongDataPlanePort, resultServicePort) // Publish the same service again should result in Forbidden @@ -406,9 +407,10 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string] capifPort := common29122.Port(myPorts["CAPIF_PORT"]) kongDomain := myEnv["KONG_DOMAIN"] kongProtocol := myEnv["KONG_PROTOCOL"] - kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"]) - kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) + kongControlPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_CONTROL_PLANE_IPV4"]) kongControlPlanePort := common29122.Port(myPorts["KONG_CONTROL_PLANE_PORT"]) + kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"]) + kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) // Register ProviderManagement providerManagerSwagger, err := provapi.GetSwagger() @@ -433,7 +435,11 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string] publishServiceSwagger.Servers = nil - ps := NewPublishService(kongDomain, kongProtocol, kongIPv4, kongDataPlanePort, kongControlPlanePort, capifProtocol, capifIPv4, capifPort) + ps := NewPublishService( + kongDomain, kongProtocol, + kongControlPlaneIPv4, kongControlPlanePort, + kongDataPlaneIPv4, kongDataPlanePort, + capifProtocol, capifIPv4, capifPort) group = e.Group("/published-apis/v1") group.Use(echomiddleware.Logger()) diff --git a/servicemanager/internal/publishserviceapi/typeupdate.go b/servicemanager/internal/publishserviceapi/typeupdate.go index e8a1f9c..d7246bd 100644 --- a/servicemanager/internal/publishserviceapi/typeupdate.go +++ b/servicemanager/internal/publishserviceapi/typeupdate.go @@ -38,26 +38,30 @@ func (sd *ServiceAPIDescription) PrepareNewService() { sd.ApiId = &apiName } -func (sd *ServiceAPIDescription) RegisterKong(kongDomain string, - kongProtocol string, - kongIPv4 common29122.Ipv4Addr, - kongDataPlanePort common29122.Port, +func (sd *ServiceAPIDescription) RegisterKong( + kongDomain string, + kongProtocol string, + kongControlPlaneIPv4 common29122.Ipv4Addr, kongControlPlanePort common29122.Port, - apfId string) (int, error) { + kongDataPlaneIPv4 common29122.Ipv4Addr, + kongDataPlanePort common29122.Port, + apfId string) (int, error) { log.Trace("entering RegisterKong") + log.Debugf("RegisterKong kongDataPlaneIPv4 %s", kongDataPlaneIPv4) + var ( statusCode int err error ) - kongControlPlaneURL := fmt.Sprintf("%s://%s:%d", kongProtocol, kongIPv4, kongControlPlanePort) + kongControlPlaneURL := fmt.Sprintf("%s://%s:%d", kongProtocol, kongControlPlaneIPv4, kongControlPlanePort) statusCode, err = sd.createKongRoutes(kongControlPlaneURL, apfId) if (err != nil) || (statusCode != http.StatusCreated) { return statusCode, err } - sd.updateInterfaceDescription(kongIPv4, kongDataPlanePort, kongDomain) + sd.updateInterfaceDescription(kongDataPlaneIPv4, kongDataPlanePort, kongDomain) log.Trace("exiting from RegisterKong") return statusCode, nil @@ -272,10 +276,12 @@ func (sd *ServiceAPIDescription) findFirstAEFProfile() (common29122.Ipv4Addr, co } // Update our exposures to point to Kong by replacing in incoming interface description with Kong interface descriptions. -func (sd *ServiceAPIDescription) updateInterfaceDescription(kongIPv4 common29122.Ipv4Addr, kongDataPlanePort common29122.Port, kongDomain string) { +func (sd *ServiceAPIDescription) updateInterfaceDescription(kongDataPlaneIPv4 common29122.Ipv4Addr, kongDataPlanePort common29122.Port, kongDomain string) { log.Trace("updating InterfaceDescriptions") + log.Debugf("InterfaceDescriptions kongDataPlaneIPv4 %s", kongDataPlaneIPv4) + interfaceDesc := InterfaceDescription{ - Ipv4Addr: &kongIPv4, + Ipv4Addr: &kongDataPlaneIPv4, Port: &kongDataPlanePort, } interfaceDescs := []InterfaceDescription{interfaceDesc} @@ -288,14 +294,14 @@ func (sd *ServiceAPIDescription) updateInterfaceDescription(kongIPv4 common29122 } } -func (sd *ServiceAPIDescription) UnregisterKong(kongDomain string, kongProtocol string, kongIPv4 common29122.Ipv4Addr, kongDataPlanePort common29122.Port, kongControlPlanePort common29122.Port) (int, error) { +func (sd *ServiceAPIDescription) UnregisterKong(kongDomain string, kongProtocol string, kongControlPlaneIPv4 common29122.Ipv4Addr, kongControlPlanePort common29122.Port) (int, error) { log.Trace("entering UnregisterKong") var ( statusCode int err error ) - kongControlPlaneURL := fmt.Sprintf("%s://%s:%d", kongProtocol, kongIPv4, kongControlPlanePort) + kongControlPlaneURL := fmt.Sprintf("%s://%s:%d", kongProtocol, kongControlPlaneIPv4, kongControlPlanePort) statusCode, err = sd.deleteKongRoutes(kongControlPlaneURL) if (err != nil) || (statusCode != http.StatusNoContent) { diff --git a/servicemanager/main.go b/servicemanager/main.go index a791314..5b949aa 100644 --- a/servicemanager/main.go +++ b/servicemanager/main.go @@ -46,12 +46,12 @@ import ( ) func main() { - realConfigReader := &envreader.RealConfigReader{} - myEnv, myPorts, err := realConfigReader.ReadDotEnv() - if err != nil { + realConfigReader := &envreader.RealConfigReader{} + myEnv, myPorts, err := realConfigReader.ReadDotEnv() + if err != nil { log.Fatal("error loading environment file") - return - } + return + } eServiceManager := echo.New() err = registerHandlers(eServiceManager, myEnv, myPorts) @@ -77,9 +77,10 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string] capifPort := common29122.Port(myPorts["CAPIF_PORT"]) kongDomain := myEnv["KONG_DOMAIN"] kongProtocol := myEnv["KONG_PROTOCOL"] - kongIPv4 := common29122.Ipv4Addr(myEnv["KONG_IPV4"]) - kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) + kongControlPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_CONTROL_PLANE_IPV4"]) kongControlPlanePort := common29122.Port(myPorts["KONG_CONTROL_PLANE_PORT"]) + kongDataPlaneIPv4 := common29122.Ipv4Addr(myEnv["KONG_DATA_PLANE_IPV4"]) + kongDataPlanePort := common29122.Port(myPorts["KONG_DATA_PLANE_PORT"]) var group *echo.Group @@ -102,7 +103,11 @@ func registerHandlers(e *echo.Echo, myEnv map[string]string, myPorts map[string] return err } publishServiceSwagger.Servers = nil - publishService := publishservice.NewPublishService(kongDomain, kongProtocol, kongIPv4, kongDataPlanePort, kongControlPlanePort, capifProtocol, capifIPv4, capifPort) + publishService := publishservice.NewPublishService( + kongDomain, kongProtocol, + kongControlPlaneIPv4, kongControlPlanePort, + kongDataPlaneIPv4, kongDataPlanePort, + capifProtocol, capifIPv4, capifPort) group = e.Group("/published-apis/v1") group.Use(middleware.OapiRequestValidator(publishServiceSwagger)) diff --git a/servicemanager/main_test.go b/servicemanager/main_test.go index 20353bd..ac65fb0 100644 --- a/servicemanager/main_test.go +++ b/servicemanager/main_test.go @@ -102,9 +102,10 @@ func setupTest() error { MockedConfig: map[string]string{ "KONG_DOMAIN": "kong", "KONG_PROTOCOL": "http", - "KONG_IPV4": mockKongHost, - "KONG_DATA_PLANE_PORT": "32080", + "KONG_CONTROL_PLANE_IPV4": mockKongHost, "KONG_CONTROL_PLANE_PORT": mockKongControlPlanePort, + "KONG_DATA_PLANE_IPV4": "10.101.1.101", + "KONG_DATA_PLANE_PORT": "32080", "CAPIF_PROTOCOL": "http", "CAPIF_IPV4": capifHost, "CAPIF_PORT": capifPort,