add test for metallb and simplify logic

This commit is contained in:
Stavros kois
2024-03-09 23:05:18 +02:00
parent 07c83a9f6b
commit e26229c1af
2 changed files with 95 additions and 5 deletions

View File

@@ -157,6 +157,99 @@ tests:
metallb.universe.tf/allow-shared-ip: test-release-name-common-test
traefik.ingress.kubernetes.io/service.serversscheme: https
- it: should add metallb shared ip annotation without externalTrafficPolicy
set:
global:
metallb:
addServiceAnnotations: true
service:
my-service1:
enabled: true
primary: true
type: LoadBalancer
ports:
port-name:
enabled: true
primary: true
port: 12345
workload:
my-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- documentIndex: *serviceDoc
isKind:
of: Service
- documentIndex: *serviceDoc
isSubset:
path: metadata.annotations
content:
metallb.universe.tf/allow-shared-ip: test-release-name-common-test
- it: should add metallb shared ip annotation with externalTrafficPolicy set to Cluster
set:
global:
metallb:
addServiceAnnotations: true
service:
my-service1:
enabled: true
primary: true
type: LoadBalancer
externalTrafficPolicy: Cluster
ports:
port-name:
enabled: true
primary: true
port: 12345
workload:
my-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- documentIndex: *serviceDoc
isKind:
of: Service
- documentIndex: *serviceDoc
isSubset:
path: metadata.annotations
content:
metallb.universe.tf/allow-shared-ip: test-release-name-common-test
- it: should NOT add metallb shared ip annotation with externalTrafficPolicy set to Local
set:
global:
metallb:
addServiceAnnotations: true
service:
my-service1:
enabled: true
primary: true
type: LoadBalancer
externalTrafficPolicy: Local
ports:
port-name:
enabled: true
primary: true
port: 12345
workload:
my-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- documentIndex: *serviceDoc
isKind:
of: Service
- documentIndex: *serviceDoc
notExists:
path: metadata.annotations.metallb\.universe\.tf/allow-shared-ip
- it: should pass with correct selector with targetSelector
set:
service:

View File

@@ -20,11 +20,8 @@ annotations: The annotations variable reference, to append the MetalLB annotatio
{{- if (hasKey $rootCtx.Values.global "metallb") -}}
{{- if $rootCtx.Values.global.metallb.addServiceAnnotations -}}
{{- if $objectData.externalTrafficPolicy -}}
{{- if ne $objectData.externalTrafficPolicy "Local" -}}
{{- $_ := set $annotations "metallb.universe.tf/allow-shared-ip" $sharedKey -}}
{{- end -}}
{{- else -}}
{{/* If externalTrafficPolicy is not set or is not Local, add the shared key as annotation */}}
{{- if ne $objectData.externalTrafficPolicy "Local" -}}
{{- $_ := set $annotations "metallb.universe.tf/allow-shared-ip" $sharedKey -}}
{{- end -}}