From 3c6aeeebb81b58ddb557f1528b03d8389b704ada Mon Sep 17 00:00:00 2001
From: Sergey Yakubov <sergey.yakubov@desy.de>
Date: Wed, 8 Apr 2020 12:08:23 +0200
Subject: [PATCH] update discovery config

---
 .../asapo/configs/asapo-discovery.json         | 18 +++++-------------
 .../asapo/templates/_service.tpl               |  1 +
 .../asapo/templates/configs.yaml               |  2 +-
 .../asapo/templates/roles.yaml                 |  1 +
 deploy/asapo_helm_chart/asapo/values.yaml      |  3 +--
 .../request_handler_kubernetes.go              |  3 +++
 6 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/deploy/asapo_helm_chart/asapo/configs/asapo-discovery.json b/deploy/asapo_helm_chart/asapo/configs/asapo-discovery.json
index fdd032094..11d922101 100644
--- a/deploy/asapo_helm_chart/asapo/configs/asapo-discovery.json
+++ b/deploy/asapo_helm_chart/asapo/configs/asapo-discovery.json
@@ -1,21 +1,13 @@
 {
-  "Mode": "static",
+  "Mode": "kubernetes",
+  "Kubernetes":{
+    "Mode": "internal",
+    "Namespace": "{{ .Release.Namespace }}"
+  },
   "Receiver": {
-    "StaticEndpoints": [
-      "127.0.0.1:22001"
-    ],
     "MaxConnections": 32,
     "UseIBAddress": false
   },
-  "Broker": {
-    "StaticEndpoint": "127.0.0.1:5005"
-  },
-  "Mongo": {
-    "StaticEndpoint": "127.0.0.1:27017"
-  },
-  "FileTransferService": {
-    "StaticEndpoint": "127.0.0.1:27017"
-  },
   "Port": {{ .Values.ownServices.discovery.port }},
   "LogLevel": "debug"
 }
diff --git a/deploy/asapo_helm_chart/asapo/templates/_service.tpl b/deploy/asapo_helm_chart/asapo/templates/_service.tpl
index 09cb95b02..808feac9d 100644
--- a/deploy/asapo_helm_chart/asapo/templates/_service.tpl
+++ b/deploy/asapo_helm_chart/asapo/templates/_service.tpl
@@ -6,6 +6,7 @@ metadata:
   name: {{ .service.serviceName }}
 spec:
   type: {{ if .service._exposeServiceExtrernally }}NodePort{{ else }}ClusterIP{{ end }}
+  {{ if .service._exposeServiceExtrernally }}externalTrafficPolicy: Local{{ end }}
   ports:
     - protocol: TCP
       port: {{ .service.port }}
diff --git a/deploy/asapo_helm_chart/asapo/templates/configs.yaml b/deploy/asapo_helm_chart/asapo/templates/configs.yaml
index 6dd1c5c49..7497412bb 100644
--- a/deploy/asapo_helm_chart/asapo/templates/configs.yaml
+++ b/deploy/asapo_helm_chart/asapo/templates/configs.yaml
@@ -1,5 +1,5 @@
 {{- range .Values.ownServices }}
-  {{ $data := dict "Chart" $.Chart "Template" $.Template "Values" $.Values "Files" $.Files "service" . }}
+  {{ $data := dict "Release" $.Release "Chart" $.Chart "Template" $.Template "Values" $.Values "Files" $.Files "service" . }}
     {{- template "asapo.configmap-fromfile" $data }}
 ---
 {{- end }}
diff --git a/deploy/asapo_helm_chart/asapo/templates/roles.yaml b/deploy/asapo_helm_chart/asapo/templates/roles.yaml
index e412266d9..748e9d5f1 100644
--- a/deploy/asapo_helm_chart/asapo/templates/roles.yaml
+++ b/deploy/asapo_helm_chart/asapo/templates/roles.yaml
@@ -8,6 +8,7 @@ rules:
       - ""
     resources:
       - services
+      - pods
     verbs:
       - get
       - list
diff --git a/deploy/asapo_helm_chart/asapo/values.yaml b/deploy/asapo_helm_chart/asapo/values.yaml
index 1729e975a..fb6a5359d 100644
--- a/deploy/asapo_helm_chart/asapo/values.yaml
+++ b/deploy/asapo_helm_chart/asapo/values.yaml
@@ -57,8 +57,7 @@ common:
   authSecret: "12ljzgneasfd"
   offlineDir: "/test_offline"
   onlineDir: "/test_online"
-  asapoVersionTag: "develop.20.03-10-g06dc0be"
-  nodesPrefix: g
+  asapoVersionTag: "feature_ASAPO-108-kubernetes-deployment.latest"
 
 influxdb:
   authEnabled: false
diff --git a/discovery/src/asapo_discovery/request_handler/request_handler_kubernetes.go b/discovery/src/asapo_discovery/request_handler/request_handler_kubernetes.go
index 0013d58ef..6173f77e8 100644
--- a/discovery/src/asapo_discovery/request_handler/request_handler_kubernetes.go
+++ b/discovery/src/asapo_discovery/request_handler/request_handler_kubernetes.go
@@ -23,6 +23,9 @@ type KubernetesRequestHandler struct {
 
 func (rh *KubernetesRequestHandler) GetServices(name string, use_ib bool) ([]string, error) {
 	pods, err := rh.client.CoreV1().Pods(rh.namespace).List(metav1.ListOptions{LabelSelector:"app="+name,FieldSelector:"status.phase=Running"})
+	if err != nil {
+		return []string{},err
+	}
 
 	var result = make([]string, 0)
 
-- 
GitLab