From 2632fe8bd90de9880fd5b23f93d53660e101b8ba Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Mon, 19 Dec 2022 16:10:16 +0200 Subject: [PATCH] account for loadbalancer IP --- .../tests/portal/portal_host_test.yaml | 27 +++++++++++++++++++ .../common/1.0.0/templates/class/_portal.tpl | 9 +------ .../1.0.0/templates/lib/portal/_host.tpl | 9 ++++++- .../1.0.0/templates/lib/portal/_protocol.tpl | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/library/common-test/tests/portal/portal_host_test.yaml b/library/common-test/tests/portal/portal_host_test.yaml index 821ebb0fb7..c23d1b7903 100644 --- a/library/common-test/tests/portal/portal_host_test.yaml +++ b/library/common-test/tests/portal/portal_host_test.yaml @@ -53,6 +53,33 @@ tests: content: host-main-main: $node_ip + - it: should pass with LoadBalancer and IP set on single service/port + documentIndex: &portalDoc 2 + set: + service: + main: + enabled: true + type: LoadBalancer + loadBalancerIP: 10.10.10.100 + ports: + main: + enabled: true + port: 10000 + protocol: HTTP + targetPort: 80 + asserts: + - isKind: + of: ConfigMap + - isAPIVersion: + of: v1 + - equal: + path: metadata.name + value: portal + - isSubset: + path: data + content: + host-main-main: "10.10.10.100" + - it: should pass with host override on single service/port documentIndex: *portalDoc set: diff --git a/library/common/1.0.0/templates/class/_portal.tpl b/library/common/1.0.0/templates/class/_portal.tpl index e7dc494a68..3e4b6b437b 100644 --- a/library/common/1.0.0/templates/class/_portal.tpl +++ b/library/common/1.0.0/templates/class/_portal.tpl @@ -1,3 +1,4 @@ +{{/* A placeholder is added, just to avoid having an empty configmap */}} {{- define "ix.v1.common.class.portal" -}} {{- $root := .root -}} @@ -35,11 +36,3 @@ data: {{- end -}} {{- end -}} {{- end -}} -{{/* -TODO: -Current "bugs", you can't disable per port portal, -if port protocol is not HTTP or HTTPS, -it will still create an HTTP portal. -A placeholder is added, just to avoid having - an empty configmap -*/}} diff --git a/library/common/1.0.0/templates/lib/portal/_host.tpl b/library/common/1.0.0/templates/lib/portal/_host.tpl index 847bd01566..35e091e9b7 100644 --- a/library/common/1.0.0/templates/lib/portal/_host.tpl +++ b/library/common/1.0.0/templates/lib/portal/_host.tpl @@ -5,7 +5,14 @@ {{- $root := .root -}} {{- $portalHost := "$node_ip" -}} - {{/*TODO: When LB + LB-ip = LB-ip*/}} + + {{- $svc := (get $root.Values.service $svcName) -}} + {{- if eq $svc.type "LoadBalancer" -}} + {{- with $svc.loadBalancerIP -}} + {{- $portalHost = toString . -}} + {{- end -}} + {{- end -}} + {{/* If ingress is added at any point, here is the place to implement */}} {{/* Check if there are any overrides in .Values.portal */}} diff --git a/library/common/1.0.0/templates/lib/portal/_protocol.tpl b/library/common/1.0.0/templates/lib/portal/_protocol.tpl index a3d6f280ab..491bf31445 100644 --- a/library/common/1.0.0/templates/lib/portal/_protocol.tpl +++ b/library/common/1.0.0/templates/lib/portal/_protocol.tpl @@ -8,7 +8,7 @@ {{- $portalProtocol := "http" -}} {{- if $port.protocol -}} - {{- if (has $port.protocol (list "HTTP" "HTTPS")) -}} + {{- if (mustHas $port.protocol (list "HTTP" "HTTPS")) -}} {{ $portalProtocol = ($port.protocol | lower) }} {{- end -}} {{- end -}}