Return endpoint's IP address instead of ClusterIP 82/482/6
authorMohamed Abukar <abukar.mohamed@nokia.com>
Mon, 8 Jul 2019 15:09:44 +0000 (18:09 +0300)
committerMohamed Abukar <abukar.mohamed@nokia.com>
Wed, 10 Jul 2019 06:13:39 +0000 (09:13 +0300)
Change-Id: I30b72d7a408c7f450a932384c2928a721c017918
Signed-off-by: Mohamed Abukar <abukar.mohamed@nokia.com>
Dockerfile
cmd/appmgr/desc.go
cmd/appmgr/desc_test.go
cmd/appmgr/helm.go
cmd/appmgr/helm_test.go
cmd/appmgr/logger.go
config/appmgr.yaml
container-tag.yaml
helm_chart/appmgr/values.yaml

index db660b9..adc0d17 100644 (file)
@@ -69,7 +69,7 @@ CMD ["/bin/bash"]
 #----------------------------------------------------------
 FROM appmgr-xapp-base as appmgr-build
 
-ARG HELMVERSION=v2.13.0-rc.1
+ARG HELMVERSION=v2.12.3
 ARG PACKAGEURL=gerrit.o-ran-sc.org/r/c/ric-plt/appmgr/
 
 #
index d4493be..7f33444 100755 (executable)
@@ -327,4 +327,3 @@ func (cm *ConfigMap) GetNamespace(ns string) string {
        }
        return ns
 }
-
index a49836b..8f005a1 100755 (executable)
 package main
 
 import (
-       "testing"
-       "reflect"
-       "errors"
        "encoding/json"
+       "errors"
        "log"
+       "reflect"
+       "testing"
 )
 
 var helmSearchOutput = `
@@ -59,8 +59,8 @@ var kubectlConfigmapOutput = `
 `
 
 type ConfigSample struct {
-       Level   int
-       Host    string
+       Level int
+       Host  string
 }
 
 type MockedConfigMapper struct {
@@ -74,7 +74,7 @@ func (cm *MockedConfigMapper) UploadConfig() (cfg []XAppConfig) {
        return
 }
 
-func (cm *MockedConfigMapper) CreateConfigMap(r XAppConfig) (errList []CMError, err error){
+func (cm *MockedConfigMapper) CreateConfigMap(r XAppConfig) (errList []CMError, err error) {
        return
 }
 
@@ -134,7 +134,7 @@ func TestGetMessages(t *testing.T) {
                return []byte(kubectlConfigmapOutput), nil
        }
 
-    result := cm.GetMessages("dummy-xapp")
+       result := cm.GetMessages("dummy-xapp")
        if !reflect.DeepEqual(result, expectedMsgs) {
                t.Errorf("TestGetMessages failed: expected: %v, got: %v", expectedMsgs, result)
        }
@@ -144,11 +144,11 @@ func TestHelmNamespace(t *testing.T) {
        cm := ConfigMap{}
 
        if cm.GetNamespace("pltxapp") != "pltxapp" {
-        t.Errorf("getNamespace failed!")
+               t.Errorf("getNamespace failed!")
        }
 
-    if cm.GetNamespace("") != "ricxapp" {
-        t.Errorf("getNamespace failed!")
+       if cm.GetNamespace("") != "default" {
+               t.Errorf("getNamespace failed!")
        }
 }
 
@@ -319,4 +319,4 @@ func TestValidationFails(t *testing.T) {
        }
 
        log.Println("Feedbacks: ", feedback)
-}
\ No newline at end of file
+}
index 5a5c28a..8651ff0 100755 (executable)
@@ -273,6 +273,16 @@ func (h *Helm) GetAddress(out string) (ip, port string) {
        return
 }
 
+func (h *Helm) GetEndpointInfo(name string) (ip string, port int) {
+       args := fmt.Sprintf(" get endpoints -o=jsonpath='{.subsets[*].addresses[*].ip}' %s -n %s", name, h.cm.GetNamespace(""))
+       out, err := KubectlExec(args)
+       if err != nil {
+               return
+       }
+
+       return string(out), 4560
+}
+
 func (h *Helm) GetNames(out string) (names []string, err error) {
        re := regexp.MustCompile(`Name: .*`)
        result := re.FindAllStringSubmatch(out, -1)
@@ -290,7 +300,11 @@ func (h *Helm) GetNames(out string) (names []string, err error) {
 }
 
 func (h *Helm) FillInstanceData(name string, out string, xapp *Xapp, msgs MessageTypes) {
-       ip, port := h.GetAddress(out)
+       ip, port := h.GetEndpointInfo(name)
+       if ip == "" {
+               Logger.Info("Endpoint IP address not found, using CluserIP")
+               ip, _ = h.GetAddress(out)
+       }
 
        var tmp string
        r := regexp.MustCompile(`.*(?s)(Running|Pending|Succeeded|Failed|Unknown).*?\r?\n\r?\n`)
@@ -307,7 +321,7 @@ func (h *Helm) FillInstanceData(name string, out string, xapp *Xapp, msgs Messag
                        fmt.Sscanf(v[0], "%s %s %s", &x.Name, &tmp, &x.Status)
                        x.Status = strings.ToLower(x.Status)
                        x.Ip = ip
-                       x.Port, _ = strconv.Atoi(strings.Split(port, "/")[0])
+                       x.Port = port
                        x.TxMessages = msgs.TxMessages
                        x.RxMessages = msgs.RxMessages
                        xapp.Instances = append(xapp.Instances, x)
index b3ff348..6ad10c6 100755 (executable)
 package main
 
 import (
-    "testing"
-    "reflect"
+       "reflect"
+       "testing"
 )
 
-
 var helmStatusOutput = `
 LAST DEPLOYED: Sat Mar  9 06:50:45 2019
 NAMESPACE: default
@@ -70,38 +69,40 @@ Releases:
   Status: DEPLOYED
   Updated: Sun Mar 24 07:17:00 2019`
 
-
 var h = Helm{}
 
 func TestHelmStatus(t *testing.T) {
        h.SetCM(&ConfigMap{})
+       KubectlExec = func(args string) (out []byte, err error) {
+               return []byte("10.102.184.212"), nil
+       }
        xapp, err := h.ParseStatus("dummy-xapp", helmStatusOutput)
-    if err != nil {
-        t.Errorf("Helm install failed: %v", err)
+       if err != nil {
+               t.Errorf("Helm install failed: %v", err)
        }
 
-    x := getXappData()
-    xapp.Version = "1.0"
+       x := getXappData()
+       xapp.Version = "1.0"
 
-    if !reflect.DeepEqual(xapp, x) {
-        t.Errorf("\n%v \n%v", xapp, x)
-    }
+       if !reflect.DeepEqual(xapp, x) {
+               t.Errorf("\n%v \n%v", xapp, x)
+       }
 }
 
 func TestHelmLists(t *testing.T) {
-    names, err := h.GetNames(helListOutput)
-    if err != nil {
-        t.Errorf("Helm status failed: %v", err)
+       names, err := h.GetNames(helListOutput)
+       if err != nil {
+               t.Errorf("Helm status failed: %v", err)
        }
 
-    if !reflect.DeepEqual(names, []string{"dummy-xapp", "dummy-xapp2"}) {
-        t.Errorf("Helm status failed: %v", err)
-    }
+       if !reflect.DeepEqual(names, []string{"dummy-xapp", "dummy-xapp2"}) {
+               t.Errorf("Helm status failed: %v", err)
+       }
 }
 
 func TestAddTillerEnv(t *testing.T) {
-    if addTillerEnv() != nil {
-        t.Errorf("TestAddTillerEnv failed!")
+       if addTillerEnv() != nil {
+               t.Errorf("TestAddTillerEnv failed!")
        }
 }
 
@@ -110,35 +111,34 @@ func TestGetInstallArgs(t *testing.T) {
 
        expectedArgs := "install helm-repo/dummy-xapp --name=dummy-xapp  --namespace=ricxapp"
        if args := getInstallArgs(x, false); args != expectedArgs {
-        t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
+               t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
        }
 
        x.ImageRepo = "localhost:5000"
        expectedArgs = expectedArgs + " --set global.repository=" + "localhost:5000"
        if args := getInstallArgs(x, false); args != expectedArgs {
-        t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
+               t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
        }
 
        x.ServiceName = "xapp"
        expectedArgs = expectedArgs + " --set ricapp.service.name=" + "xapp"
        if args := getInstallArgs(x, false); args != expectedArgs {
-        t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
+               t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
        }
 
        x.ServiceName = "xapp"
        expectedArgs = expectedArgs + " --set ricapp.appconfig.override=dummy-xapp-appconfig"
        if args := getInstallArgs(x, true); args != expectedArgs {
-        t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
+               t.Errorf("TestGetInstallArgs failed: expected %v, got %v", expectedArgs, args)
        }
 }
 
 func getXappData() (x Xapp) {
-    x = generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "10.102.184.212", "80")
-    x.Instances = append(x.Instances, x.Instances[0])
-    x.Instances = append(x.Instances, x.Instances[0])
-    x.Instances[1].Name = "dummy-xapp-8984fc9fd-l6xch"
-    x.Instances[2].Name = "dummy-xapp-8984fc9fd-pp4hg"
+       x = generateXapp("dummy-xapp", "deployed", "1.0", "dummy-xapp-8984fc9fd-bkcbp", "running", "10.102.184.212", "4560")
+       x.Instances = append(x.Instances, x.Instances[0])
+       x.Instances = append(x.Instances, x.Instances[0])
+       x.Instances[1].Name = "dummy-xapp-8984fc9fd-l6xch"
+       x.Instances[2].Name = "dummy-xapp-8984fc9fd-pp4hg"
 
-    return x
+       return x
 }
-
index b8a7475..d1bcf15 100755 (executable)
@@ -20,9 +20,9 @@
 package main
 
 import (
+       mdclog "gerrit.o-ran-sc.org/r/com/golog"
        "net/http"
        "time"
-       mdclog "gerrit.o-ran-sc.org/r/com/golog"
 )
 
 type Log struct {
@@ -45,22 +45,22 @@ func (l *Log) SetMdc(key string, value string) {
 }
 
 func (l *Log) Error(pattern string, args ...interface{}) {
-       l.SetMdc("time", time.Now().Format("2019-01-02 15:04:05"))
+       l.SetMdc("time", time.Now().Format(time.RFC3339))
        l.logger.Error(pattern, args...)
 }
 
 func (l *Log) Warn(pattern string, args ...interface{}) {
-       l.SetMdc("time", time.Now().Format("2019-01-02 15:04:05"))
+       l.SetMdc("time", time.Now().Format(time.RFC3339))
        l.logger.Warning(pattern, args...)
 }
 
 func (l *Log) Info(pattern string, args ...interface{}) {
-       l.SetMdc("time", time.Now().Format("2019-01-02 15:04:05"))
+       l.SetMdc("time", time.Now().Format(time.RFC3339))
        l.logger.Info(pattern, args...)
 }
 
 func (l *Log) Debug(pattern string, args ...interface{}) {
-       l.SetMdc("time", time.Now().Format("2019-01-02 15:04:05"))
+       l.SetMdc("time", time.Now().Format(time.RFC3339))
        l.logger.Debug(pattern, args...)
 }
 
index 34db29e..58545fc 100755 (executable)
@@ -26,7 +26,7 @@
   "helm-password-file": "./helm_repo_password"
   "retry": 1
 "xapp":
-  "namespace": "ricxapp"
+  "namespace": "default"
   "tarDir": "/tmp"
   "schema": "descriptors/schema.json"
   "config": "config/config-file.json"
index 585bbf8..d7e5871 100644 (file)
@@ -1,3 +1,3 @@
 # The Jenkins job requires a tag to build a Docker image
 ---
-tag: '0.1.3'
+tag: '0.1.4'
index 8b2fc04..268081b 100755 (executable)
@@ -31,7 +31,7 @@ image:
 
   # xAppmanager Docker image name and tag
   name: appmgr
-  tag: 1.0.1
+  tag: 0.1.4
 
   #nameOverride: ""
   #fullnameOverride: ""
@@ -74,7 +74,7 @@ appconfig:
       "retry": 1
     "xapp":
       #Namespace to install xAPPs
-      "namespace": "ricxapp"
+      "namespace": "default"
       "tarDir": "/tmp"
       "schema": "descriptors/schema.json"
       "config": "config/config-file.json"