session affinity

This commit is contained in:
Stavros kois
2023-02-06 14:18:20 +02:00
parent 9be1053351
commit 0dd398d884
9 changed files with 143 additions and 16 deletions
@@ -43,6 +43,8 @@ tests:
some_family: IPv6
some_ip: 172.16.20.35
some_other_ip: 10.200.34.53
some_affinity: ClientIP
some_timeout: 100
service:
my-service:
enabled: true
@@ -57,6 +59,10 @@ tests:
externalIPs:
- "{{ .Values.some_other_ip }}"
- 10.200.34.54
sessionAffinity: "{{ .Values.some_affinity }}"
sessionAffinityConfig:
clientIP:
timeoutSeconds: "{{ .Values.some_timeout }}"
ports:
port-name:
enabled: true
@@ -82,3 +88,7 @@ tests:
externalIPs:
- 10.200.34.53
- 10.200.34.54
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 100
@@ -14,14 +14,8 @@ tests:
port-name:
enabled: true
primary: true
workload:
my-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- documentIndex: &serviceDoc 1
- documentIndex: &serviceDoc 0
isKind:
of: Service
- documentIndex: *serviceDoc
@@ -41,6 +35,8 @@ tests:
set:
some_policy: Local
some_ip: 10.200.34.53
some_affinity: ClientIP
some_timeout: 100
service:
my-service:
enabled: true
@@ -51,16 +47,14 @@ tests:
externalIPs:
- "{{ .Values.some_ip }}"
- 10.200.34.54
sessionAffinity: "{{ .Values.some_affinity }}"
sessionAffinityConfig:
clientIP:
timeoutSeconds: "{{ .Values.some_timeout }}"
ports:
port-name:
enabled: true
primary: true
workload:
my-workload:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- documentIndex: *serviceDoc
equal:
@@ -71,3 +65,7 @@ tests:
externalIPs:
- 10.200.34.53
- 10.200.34.54
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 100
@@ -39,6 +39,8 @@ tests:
some_other_ip: 10.200.34.53
some_name: my-external-name
some_policy: Local
some_affinity: ClientIP
some_timeout: 100
service:
my-service:
enabled: true
@@ -51,6 +53,10 @@ tests:
externalIPs:
- "{{ .Values.some_other_ip }}"
- 10.200.34.54
sessionAffinity: "{{ .Values.some_affinity }}"
sessionAffinityConfig:
clientIP:
timeoutSeconds: "{{ .Values.some_timeout }}"
ports:
port-name:
enabled: true
@@ -68,3 +74,7 @@ tests:
externalIPs:
- 10.200.34.53
- 10.200.34.54
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 100
@@ -45,6 +45,8 @@ tests:
some_policy: Local
some_range: 11.100.200.0/24
some_family: IPv6
some_affinity: ClientIP
some_timeout: 100
service:
my-service:
enabled: true
@@ -64,6 +66,10 @@ tests:
externalIPs:
- "{{ .Values.some_extra_ip }}"
- 10.200.34.54
sessionAffinity: "{{ .Values.some_affinity }}"
sessionAffinityConfig:
clientIP:
timeoutSeconds: "{{ .Values.some_timeout }}"
ports:
port-name:
enabled: true
@@ -94,3 +100,7 @@ tests:
externalIPs:
- 10.200.34.53
- 10.200.34.54
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 100
@@ -43,6 +43,8 @@ tests:
some_family: IPv6
some_policy: Local
some_other_ip: 10.200.34.53
some_affinity: ClientIP
some_timeout: 100
service:
my-service:
enabled: true
@@ -58,6 +60,10 @@ tests:
externalIPs:
- "{{ .Values.some_other_ip }}"
- 10.200.34.54
sessionAffinity: "{{ .Values.some_affinity }}"
sessionAffinityConfig:
clientIP:
timeoutSeconds: "{{ .Values.some_timeout }}"
ports:
port-name:
enabled: true
@@ -84,3 +90,7 @@ tests:
externalIPs:
- 10.200.34.53
- 10.200.34.54
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 100
@@ -315,3 +315,50 @@ tests:
asserts:
- failedTemplate:
errorMessage: Service - Expected non-empty <externalName> on ExternalName service type.
- it: should fail with invalid sessionAffinity
set:
service:
service-name1:
enabled: true
primary: true
type: ClusterIP
sessionAffinity: not-an-affinity
ports:
port-name1:
enabled: true
primary: true
workload:
some-pod-name:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- failedTemplate:
errorMessage: Service - Expected <sessionAffinity> to be one of [ClientIP, None], but got [not-an-affinity]
- it: should fail with invalid timeoutSeconds in sessionAffinityConfig
set:
service:
service-name1:
enabled: true
primary: true
type: ClusterIP
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: -1
ports:
port-name1:
enabled: true
primary: true
workload:
some-pod-name:
enabled: true
primary: true
type: Deployment
podSpec: {}
asserts:
- failedTemplate:
errorMessage: Service - Expected <sessionAffinityConfig.clientIP.timeoutSeconds> to be between [0 - 86400], but got [-1]
@@ -89,7 +89,7 @@ spec:
externalIPs:
{{- . | nindent 2 }}
{{- end -}}
{{/* TODO: sessionAffinity */}}
{{- include "ix.v1.common.lib.service.sessionAffinity" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }}
ports:
{{/* TODO: ports */}}
{{- if not (mustHas $svcType $specialTypes) }}
@@ -97,6 +97,6 @@ selector:
{{- include "ix.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "podName" $podValues.shortName) | trim | nindent 2 }}
{{- end -}}
{{- if eq $svcType "ExternalIP" -}}
{{/* TODO: endpoints for externalIP */}}
{{/* TODO: endpointsslice for externalIP */}}
{{- end -}}
{{- end -}}
@@ -7,7 +7,7 @@ objectData: The service object data
{{- define "ix.v1.common.lib.service.ipFamily" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
{{- $objectData := .objectData -}}
{{- with $objectData.ipFamilyPolicy -}}
{{- $famPolicy := tpl . $rootCtx -}}
@@ -0,0 +1,42 @@
{{/* Service - Session Affinity */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.service.sessionAffinity" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the service
objectData: The service object data
*/}}
{{- define "ix.v1.common.lib.service.sessionAffinity" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- with $objectData.sessionAffinity -}}
{{- $affinity := tpl . $rootCtx -}}
{{- $affinities := (list "ClientIP" "None") -}}
{{- if not (mustHas $affinity $affinities) -}}
{{- fail (printf "Service - Expected <sessionAffinity> to be one of [%s], but got [%s]" (join ", " $affinities) $affinity) -}}
{{- end }}
sessionAffinity: {{ $affinity }}
{{- if eq $affinity "ClientIP" -}}
{{- with $objectData.sessionAffinityConfig -}}
{{- with .clientIP -}}
{{- $timeout := .timeoutSeconds -}}
{{- if kindIs "string" $timeout -}}
{{- $timeout = tpl $timeout $rootCtx -}}
{{- end -}}
{{- $timeout = int $timeout -}}
{{- if and $timeout (mustHas (kindOf $timeout) (list "float64" "int")) -}}
{{- if or (lt $timeout 0) (gt $timeout 86400) -}}
{{- fail (printf "Service - Expected <sessionAffinityConfig.clientIP.timeoutSeconds> to be between [0 - 86400], but got [%v]" $timeout) -}}
{{- end }}
sessionAffinityConfig:
clientIP:
timeoutSeconds: {{ $timeout }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}