From 08b8f5c4f542362931a67ae198dc8408002e410f Mon Sep 17 00:00:00 2001
From: Pete Birley <pete@port.direct>
Date: Sat, 3 Mar 2018 15:41:24 +0000
Subject: [PATCH] Heat: use endpoints section and lookups to set port

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

Change-Id: Id44db993c1b5df5ffd2b9bb6602faca4ac3472a6
---
 heat/templates/configmap-etc.yaml         | 12 ++++++++++++
 heat/templates/deployment-api.yaml        |  5 +++--
 heat/templates/deployment-cfn.yaml        |  5 +++--
 heat/templates/deployment-cloudwatch.yaml |  5 +++--
 heat/templates/service-api.yaml           |  2 +-
 heat/templates/service-cfn.yaml           |  2 +-
 heat/templates/service-cloudwatch.yaml    |  2 +-
 heat/values.yaml                          | 12 +++++++++---
 8 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/heat/templates/configmap-etc.yaml b/heat/templates/configmap-etc.yaml
index c43d15c7b1..13e98a5ccf 100644
--- a/heat/templates/configmap-etc.yaml
+++ b/heat/templates/configmap-etc.yaml
@@ -109,6 +109,18 @@ limitations under the License.
 {{- tuple "identity" "internal" "api" . | include "helm-toolkit.endpoints.keystone_endpoint_uri_lookup" | trimSuffix .Values.endpoints.identity.path.default | set .Values.conf.heat.trustee "auth_url" | quote | trunc 0 -}}
 {{- end -}}
 
+{{- if empty .Values.conf.heat.heat_api.bind_port -}}
+{{- tuple "orchestration" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" | set .Values.conf.heat.heat_api "bind_port" | quote | trunc 0 -}}
+{{- end -}}
+
+{{- if empty .Values.conf.heat.heat_api_cloudwatch.bind_port -}}
+{{- tuple "cloudwatch" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" | set .Values.conf.heat.heat_api_cloudwatch "bind_port" | quote | trunc 0 -}}
+{{- end -}}
+
+{{- if empty .Values.conf.heat.heat_api_cfn.bind_port -}}
+{{- tuple "cloudformation" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" | set .Values.conf.heat.heat_api_cfn "bind_port" | quote | trunc 0 -}}
+{{- end -}}
+
 ---
 apiVersion: v1
 kind: ConfigMap
diff --git a/heat/templates/deployment-api.yaml b/heat/templates/deployment-api.yaml
index 337edbcbf7..ce93dc4877 100644
--- a/heat/templates/deployment-api.yaml
+++ b/heat/templates/deployment-api.yaml
@@ -64,10 +64,11 @@ spec:
                   - /tmp/heat-api.sh
                   - stop
           ports:
-            - containerPort: {{ .Values.conf.heat.heat_api.bind_port }}
+            - name: h-api
+              containerPort: {{ tuple "orchestration" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
           readinessProbe:
             tcpSocket:
-              port: {{ .Values.conf.heat.heat_api.bind_port }}
+              port: {{ tuple "orchestration" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
           volumeMounts:
             - name: pod-etc-heat
               mountPath: /etc/heat
diff --git a/heat/templates/deployment-cfn.yaml b/heat/templates/deployment-cfn.yaml
index 250c472a4e..71f7c3e60e 100644
--- a/heat/templates/deployment-cfn.yaml
+++ b/heat/templates/deployment-cfn.yaml
@@ -64,10 +64,11 @@ spec:
                   - /tmp/heat-cfn.sh
                   - stop
           ports:
-            - containerPort: {{ .Values.conf.heat.heat_api_cfn.bind_port }}
+            - name: h-cfn
+              containerPort: {{ tuple "cloudformation" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
           readinessProbe:
             tcpSocket:
-              port: {{ .Values.conf.heat.heat_api_cfn.bind_port }}
+              port: {{ tuple "cloudformation" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
           volumeMounts:
             - name: pod-etc-heat
               mountPath: /etc/heat
diff --git a/heat/templates/deployment-cloudwatch.yaml b/heat/templates/deployment-cloudwatch.yaml
index f3b531a94a..cdb06c02f3 100644
--- a/heat/templates/deployment-cloudwatch.yaml
+++ b/heat/templates/deployment-cloudwatch.yaml
@@ -64,10 +64,11 @@ spec:
                   - /tmp/heat-cloudwatch.sh
                   - stop
           ports:
-            - containerPort: {{ .Values.conf.heat.heat_api_cloudwatch.bind_port }}
+            - name: h-cwh
+              containerPort: {{ tuple "cloudwatch" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
           readinessProbe:
             tcpSocket:
-              port: {{ .Values.conf.heat.heat_api_cloudwatch.bind_port }}
+              port: {{ tuple "cloudwatch" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
           volumeMounts:
             - name: pod-etc-heat
               mountPath: /etc/heat
diff --git a/heat/templates/service-api.yaml b/heat/templates/service-api.yaml
index 380027d46d..47c7e78280 100644
--- a/heat/templates/service-api.yaml
+++ b/heat/templates/service-api.yaml
@@ -24,7 +24,7 @@ metadata:
 spec:
   ports:
     - name: h-api
-      port: {{ .Values.conf.heat.heat_api.bind_port }}
+      port: {{ tuple "orchestration" "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/heat/templates/service-cfn.yaml b/heat/templates/service-cfn.yaml
index 4dc5087c21..f5945f92ba 100644
--- a/heat/templates/service-cfn.yaml
+++ b/heat/templates/service-cfn.yaml
@@ -24,7 +24,7 @@ metadata:
 spec:
   ports:
     - name: h-cfn
-      port: {{ .Values.conf.heat.heat_api_cfn.bind_port }}
+      port: {{ tuple "cloudformation" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
     {{ if .Values.network.cfn.node_port.enabled }}
       nodePort: {{ .Values.network.cfn.node_port.port }}
     {{ end }}
diff --git a/heat/templates/service-cloudwatch.yaml b/heat/templates/service-cloudwatch.yaml
index 6f5bd25257..82f9ed79d6 100644
--- a/heat/templates/service-cloudwatch.yaml
+++ b/heat/templates/service-cloudwatch.yaml
@@ -24,7 +24,7 @@ metadata:
 spec:
   ports:
     - name: h-cwh
-      port: {{ .Values.conf.heat.heat_api_cloudwatch.bind_port }}
+      port: {{ tuple "cloudwatch" "internal" "api" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }}
     {{ if .Values.network.cloudwatch.node_port.enabled }}
       nodePort: {{ .Values.network.cloudwatch.node_port.port }}
     {{ end }}
diff --git a/heat/values.yaml b/heat/values.yaml
index d8848e1e64..3214b4d45d 100644
--- a/heat/values.yaml
+++ b/heat/values.yaml
@@ -223,13 +223,19 @@ conf:
       auth_type: password
       auth_version: v3
     heat_api:
-      bind_port: 8004
+      #NOTE(portdirect): the bind port should not be defined, and is manipulated
+      # via the endpoints section.
+      bind_port: null
       workers: 4
     heat_api_cloudwatch:
-      bind_port: 8003
+      #NOTE(portdirect): the bind port should not be defined, and is manipulated
+      # via the endpoints section.
+      bind_port: null
       workers: 4
     heat_api_cfn:
-      bind_port: 8000
+      #NOTE(portdirect): the bind port should not be defined, and is manipulated
+      # via the endpoints section.
+      bind_port: null
       workers: 4
     paste_deploy:
       api_paste_config: /etc/heat/api-paste.ini