From b6e413571bf3f44d4cd076815334449831d84e28 Mon Sep 17 00:00:00 2001 From: Mohamed Abukar Date: Mon, 8 Jul 2019 18:09:44 +0300 Subject: [PATCH] Return endpoint's IP address instead of ClusterIP Change-Id: I30b72d7a408c7f450a932384c2928a721c017918 Signed-off-by: Mohamed Abukar --- Dockerfile | 2 +- cmd/appmgr/desc.go | 1 - cmd/appmgr/desc_test.go | 22 ++++++++-------- cmd/appmgr/helm.go | 18 +++++++++++-- cmd/appmgr/helm_test.go | 60 +++++++++++++++++++++---------------------- cmd/appmgr/logger.go | 10 ++++---- config/appmgr.yaml | 2 +- container-tag.yaml | 2 +- helm_chart/appmgr/values.yaml | 4 +-- 9 files changed, 67 insertions(+), 54 deletions(-) diff --git a/Dockerfile b/Dockerfile index db660b9..adc0d17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ # diff --git a/cmd/appmgr/desc.go b/cmd/appmgr/desc.go index d4493be..7f33444 100755 --- a/cmd/appmgr/desc.go +++ b/cmd/appmgr/desc.go @@ -327,4 +327,3 @@ func (cm *ConfigMap) GetNamespace(ns string) string { } return ns } - diff --git a/cmd/appmgr/desc_test.go b/cmd/appmgr/desc_test.go index a49836b..8f005a1 100755 --- a/cmd/appmgr/desc_test.go +++ b/cmd/appmgr/desc_test.go @@ -20,11 +20,11 @@ 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 +} diff --git a/cmd/appmgr/helm.go b/cmd/appmgr/helm.go index 5a5c28a..8651ff0 100755 --- a/cmd/appmgr/helm.go +++ b/cmd/appmgr/helm.go @@ -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) diff --git a/cmd/appmgr/helm_test.go b/cmd/appmgr/helm_test.go index b3ff348..6ad10c6 100755 --- a/cmd/appmgr/helm_test.go +++ b/cmd/appmgr/helm_test.go @@ -20,11 +20,10 @@ 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 } - diff --git a/cmd/appmgr/logger.go b/cmd/appmgr/logger.go index b8a7475..d1bcf15 100755 --- a/cmd/appmgr/logger.go +++ b/cmd/appmgr/logger.go @@ -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...) } diff --git a/config/appmgr.yaml b/config/appmgr.yaml index 34db29e..58545fc 100755 --- a/config/appmgr.yaml +++ b/config/appmgr.yaml @@ -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" diff --git a/container-tag.yaml b/container-tag.yaml index 585bbf8..d7e5871 100644 --- a/container-tag.yaml +++ b/container-tag.yaml @@ -1,3 +1,3 @@ # The Jenkins job requires a tag to build a Docker image --- -tag: '0.1.3' +tag: '0.1.4' diff --git a/helm_chart/appmgr/values.yaml b/helm_chart/appmgr/values.yaml index 8b2fc04..268081b 100755 --- a/helm_chart/appmgr/values.yaml +++ b/helm_chart/appmgr/values.yaml @@ -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" -- 2.16.6