From 13f24c930ecd490f9b38e9b257f5a72607874a57 Mon Sep 17 00:00:00 2001
From: Pete Birley <pete@port.direct>
Date: Sat, 3 Mar 2018 16:33:21 +0000
Subject: [PATCH] Senlin: use endpoints section and lookups to set port

This PS moves senlin to use the endpoints section and lookups to
set the port it serves on.

Change-Id: I87ebb242387fbab619173348b2c71b63f1654381
---
 senlin/templates/configmap-etc.yaml  | 4 ++++
 senlin/templates/deployment-api.yaml | 5 +++--
 senlin/templates/service-api.yaml    | 2 +-
 senlin/values.yaml                   | 4 +++-
 4 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/senlin/templates/configmap-etc.yaml b/senlin/templates/configmap-etc.yaml
index aa32fcd676..11fa9dcffb 100644
--- a/senlin/templates/configmap-etc.yaml
+++ b/senlin/templates/configmap-etc.yaml
@@ -62,6 +62,10 @@ limitations under the License.
 {{- tuple "oslo_messaging" "internal" "senlin" "amqp" . | include "helm-toolkit.endpoints.authenticated_endpoint_uri_lookup" | set .Values.conf.senlin.DEFAULT "transport_url" | quote | trunc 0 -}}
 {{- end -}}
 
+{{- if empty .Values.conf.senlin.senlin_api.bind_port -}}
+{{- tuple "clustering" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" | set .Values.conf.senlin.senlin_api "bind_port" | quote | trunc 0 -}}
+{{- end -}}
+
 ---
 apiVersion: v1
 kind: ConfigMap
diff --git a/senlin/templates/deployment-api.yaml b/senlin/templates/deployment-api.yaml
index d06bc609d9..8f55adc044 100644
--- a/senlin/templates/deployment-api.yaml
+++ b/senlin/templates/deployment-api.yaml
@@ -64,10 +64,11 @@ spec:
                   - /tmp/senlin-api.sh
                   - stop
           ports:
-            - containerPort: {{ .Values.conf.senlin.senlin_api.bind_port }}
+            - name: s-api
+              containerPort: {{ tuple "clustering" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
           readinessProbe:
             tcpSocket:
-              port: {{ .Values.conf.senlin.senlin_api.bind_port }}
+              port: {{ tuple "clustering" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
           volumeMounts:
             - name: senlin-bin
               mountPath: /tmp/senlin-api.sh
diff --git a/senlin/templates/service-api.yaml b/senlin/templates/service-api.yaml
index e8aa1575fb..d9e9ded584 100644
--- a/senlin/templates/service-api.yaml
+++ b/senlin/templates/service-api.yaml
@@ -24,7 +24,7 @@ metadata:
 spec:
   ports:
     - name: s-api
-      port: {{ .Values.conf.senlin.senlin_api.bind_port }}
+      port: {{ tuple "clustering" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
     {{ if .Values.network.api.node_port.enabled }}
       nodePort: {{ .Values.network.api.node_port.port }}
     {{ end }}
diff --git a/senlin/values.yaml b/senlin/values.yaml
index 43b69d6780..3660d210d8 100644
--- a/senlin/values.yaml
+++ b/senlin/values.yaml
@@ -130,7 +130,9 @@ conf:
       auth_version: v3
       memcache_security_strategy: ENCRYPT
     senlin_api:
-      bind_port: 8778
+      #NOTE(portdirect): the bind port should not be defined, and is manipulated
+      # via the endpoints section.
+      bind_port: null
 
 network:
   api: