fix(portcheck,externalip): Convert everything to int for port check and fix protocol check logic for externalIP type (#391)

**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes https://github.com/truecharts/charts/issues/7983
⚒️ Fixes https://github.com/truecharts/charts/issues/8028

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [ ] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [ ] ⚖️ My code follows the style guidelines of this project
- [ ] 👀 I have performed a self-review of my own code
- [ ] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [ ] ⚠️ My changes generate no new warnings
- [ ] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [ ] ⬆️ I increased versions for any altered app according to semantic
versioning

** App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🪞 I have opened a PR on
[truecharts/containers](https://github.com/truecharts/containers) adding
the container to TrueCharts mirror repo.
- [ ] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._
This commit is contained in:
Stavros Kois
2023-04-15 23:05:28 +03:00
committed by GitHub
parent 9ebd44b138
commit ccbfef0b0f
4 changed files with 69 additions and 17 deletions

View File

@@ -143,3 +143,56 @@ tests:
value:
- addresses:
- 1.1.1.1
- it: should pass with type ExternalIP and https
set:
service:
my-service:
enabled: true
primary: true
type: ExternalIP
externalIP: 1.1.1.1
ports:
port-name:
enabled: true
primary: true
port: 443
protocol: https
asserts:
- documentIndex: *serviceDoc
equal:
path: spec
value:
publishNotReadyAddresses: false
ports:
- name: port-name
port: 443
protocol: TCP
targetPort: 443
- documentIndex: &endpointSliceDoc 1
isKind:
of: EndpointSlice
- documentIndex: *endpointSliceDoc
isAPIVersion:
of: discovery.k8s.io/v1
- documentIndex: *endpointSliceDoc
equal:
path: ports
value:
- name: port-name
port: 443
protocol: TCP
- documentIndex: *endpointSliceDoc
equal:
path: endpoints
value:
- addresses:
- 1.1.1.1
- documentIndex: &serviceDoc 0
isKind:
of: Service
- documentIndex: *serviceDoc
isSubset:
path: metadata.annotations
content:
traefik.ingress.kubernetes.io/service.serversscheme: https

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 12.4.13
version: 12.4.14

View File

@@ -19,6 +19,18 @@ objectData: The service data, that will be used to render the Service object.
{{- $hostNetwork := false -}}
{{- $podValues := dict -}}
{{- range $portName, $port := $objectData.ports -}}
{{- if $port.enabled -}}
{{- if eq (tpl ($port.protocol | default "") $rootCtx) "https" -}}
{{- $hasHTTPSPort = true -}}
{{- end -}}
{{- if and (hasKey $port "hostPort") $port.hostPort -}}
{{- $hasHostPort = true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $specialTypes := (list "ExternalName" "ExternalIP") -}}
{{/* External Name / External IP does not rely on any pod values */}}
{{- if not (mustHas $svcType $specialTypes) -}}
@@ -34,18 +46,6 @@ objectData: The service data, that will be used to render the Service object.
{{- end -}}
{{- end -}}
{{- range $portName, $port := $objectData.ports -}}
{{- if $port.enabled -}}
{{- if eq (tpl ($port.protocol | default "") $rootCtx) "https" -}}
{{- $hasHTTPSPort = true -}}
{{- end -}}
{{- if and (hasKey $port "hostPort") $port.hostPort -}}
{{- $hasHostPort = true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* When hostPort is defined, force ClusterIP aswell */}}
{{- if $hasHostPort -}}
{{- $svcType = "ClusterIP" -}}

View File

@@ -38,15 +38,14 @@ objectData: The object data to be used to render the Pod.
{{- $portToCheck := ($portValues.targetPort | default $portValues.port) -}}
{{- if kindIs "string" $portToCheck -}}
{{/* Helm stores ints as floats, so convert string to float before comparing */}}
{{- $portToCheck = (tpl $portToCheck $rootCtx) | float64 -}}
{{- $portToCheck = (tpl $portToCheck $rootCtx) | int -}}
{{- end -}}
{{- if or (not $portRange.low) (lt $portToCheck ($portRange.low | float64)) -}}
{{- if or (not $portRange.low) (lt ($portToCheck | int) ($portRange.low | int)) -}}
{{- $_ := set $portRange "low" $portToCheck -}}
{{- end -}}
{{- if or (not $portRange.high) (gt $portToCheck ($portRange.high | float64)) -}}
{{- if or (not $portRange.high) (gt ($portToCheck | int) ($portRange.high | int)) -}}
{{- $_ := set $portRange "high" $portToCheck -}}
{{- end -}}