Files
Stavros KoisandGitHub 3b2ef37384 common(ports): detect potential issue with port names (#29051)
**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  #29041

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [x] 🪛 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:**

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

** App addition**

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

- [ ] 🖼️ 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._
2024-11-11 15:58:45 +00:00

403 lines
11 KiB
YAML

suite: container ports test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should create the correct ports without selector
set:
some_port: 80
image: &image
repository: nginx
tag: 1.19.0
pullPolicy: IfNotPresent
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: &probes
liveness:
enabled: false
readiness:
enabled: false
startup:
enabled: false
workload-name2:
enabled: true
primary: false
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
service:
my-service1:
enabled: true
primary: true
ports:
port-name:
enabled: true
primary: true
port: "{{ .Values.some_port }}"
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
ports:
- name: port-name
containerPort: 80
hostPort: null
protocol: TCP
- documentIndex: &otherDeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *otherDeploymentDoc
isNull:
path: spec.template.spec.containers[0].ports
- it: should create the correct ports with selector
set:
some_port: 53
image: &image
repository: nginx
tag: 1.19.0
pullPolicy: IfNotPresent
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
workload-name2:
enabled: true
primary: false
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
service:
my-service1:
enabled: true
primary: true
targetSelector: workload-name1
ports:
port-name:
enabled: true
primary: true
targetSelector: container-name1
port: 1234
my-service2:
enabled: true
primary: false
targetSelector: workload-name2
ports:
port-name:
enabled: true
primary: true
targetSelector: container-name1
port: 54
targetPort: "{{ .Values.some_port }}"
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
ports:
- name: port-name
containerPort: 1234
hostPort: null
protocol: TCP
- documentIndex: *deploymentDoc
isNotSubset:
path: spec.template.spec.containers[0].securityContext.capabilities
content:
add:
- NET_BIND_SERVICE
- documentIndex: &otherDeploymentDoc 1
isKind:
of: Deployment
- documentIndex: *otherDeploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
ports:
- name: port-name
containerPort: 53
hostPort: null
protocol: TCP
- documentIndex: *otherDeploymentDoc
isSubset:
path: spec.template.spec.containers[0].securityContext.capabilities
content:
add:
- NET_BIND_SERVICE
- it: should create the correct ports with hostPort
set:
image: &image
repository: nginx
tag: 1.19.0
pullPolicy: IfNotPresent
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
service:
my-service1:
enabled: true
primary: true
ports:
port-name:
enabled: true
primary: true
port: 1234
targetPort: 5678
hostPort: 20000
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
ports:
- name: port-name
containerPort: 5678
protocol: TCP
hostPort: 20000
- it: should create the correct protocol from tpl
set:
some_protocol: https
image: &image
repository: nginx
tag: 1.19.0
pullPolicy: IfNotPresent
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
service:
my-service1:
enabled: true
primary: true
ports:
port-name:
enabled: true
primary: true
port: 1234
protocol: "{{ .Values.some_protocol }}"
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
ports:
- name: port-name
containerPort: 1234
hostPort: null
protocol: TCP
- it: should create the correct protocol
set:
image: &image
repository: nginx
tag: 1.19.0
pullPolicy: IfNotPresent
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
service:
my-service1:
enabled: true
primary: true
ports:
port-name:
enabled: true
primary: true
port: 1234
protocol: udp
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
ports:
- name: port-name
containerPort: 1234
hostPort: null
protocol: UDP
- it: should fail if there are duplicate ports but they are not adjacent
set:
service:
my-service1:
enabled: true
primary: true
targetSelector: workload-name1
ports:
my-port:
enabled: true
primary: true
port: 1234
protocol: tcp
targetSelector: container-name1
my-port2:
enabled: true
port: 1235
protocol: tcp
targetSelector: container-name1
my-port3:
enabled: true
port: 1234
protocol: udp
targetSelector: container-name1
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
asserts:
- failedTemplate:
errorMessage: "Port number [1234] is used by multiple ports [my-port, my-port3] in the service [my-service1] but their names are not adjacent when sorted alphabetically (Other ports in this container sorted: [my-port, my-port2, my-port3]). This can cause issues with Kubernetes port updates."
- it: should pass if there are duplicate ports but they are adjacent
set:
service:
my-service1:
enabled: true
primary: true
targetSelector: workload-name1
ports:
my-port:
enabled: true
primary: true
port: 1234
protocol: tcp
targetSelector: container-name1
my-port2:
enabled: true
port: 1234
protocol: udp
targetSelector: container-name1
my-port3:
enabled: true
port: 1235
protocol: udp
targetSelector: container-name1
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
asserts:
- documentIndex: &deploymentDoc 0
isKind:
of: Deployment
- documentIndex: *deploymentDoc
equal:
path: spec.template.spec.containers[0].ports
value:
- name: my-port
containerPort: 1234
protocol: TCP
hostPort: null
- name: my-port2
containerPort: 1234
protocol: UDP
hostPort: null
- name: my-port3
containerPort: 1235
protocol: UDP
hostPort: null