Skip to content

Commit

Permalink
Add support for dual stack clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
UXabre committed Aug 23, 2023
1 parent ea1c369 commit 0878b35
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 0 deletions.
8 changes: 8 additions & 0 deletions templates/server-ha-active-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ spec:
{{- if .Values.server.service.type}}
type: {{ .Values.server.service.type }}
{{- end}}
{{- if (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) }}
{{- if .Values.server.service.ipFamilyPolicy }}
ipFamilyPolicy: {{ .Values.server.service.ipFamilyPolicy }}
{{- end }}
{{- if .Values.server.service.ipFamilies }}
ipFamilies: {{ .Values.server.service.ipFamilies | toYaml | nindent 2 }}
{{- end }}
{{- end }}
{{- if .Values.server.service.clusterIP }}
clusterIP: {{ .Values.server.service.clusterIP }}
{{- end }}
Expand Down
8 changes: 8 additions & 0 deletions templates/server-ha-standby-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ spec:
{{- if .Values.server.service.type}}
type: {{ .Values.server.service.type }}
{{- end}}
{{- if (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) }}
{{- if .Values.server.service.ipFamilyPolicy }}
ipFamilyPolicy: {{ .Values.server.service.ipFamilyPolicy }}
{{- end }}
{{- if .Values.server.service.ipFamilies }}
ipFamilies: {{ .Values.server.service.ipFamilies | toYaml | nindent 2 }}
{{- end }}
{{- end }}
{{- if .Values.server.service.clusterIP }}
clusterIP: {{ .Values.server.service.clusterIP }}
{{- end }}
Expand Down
8 changes: 8 additions & 0 deletions templates/server-headless-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ metadata:
annotations:
{{ template "vault.service.annotations" .}}
spec:
{{- if (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) }}
{{- if .Values.server.service.ipFamilyPolicy }}
ipFamilyPolicy: {{ .Values.server.service.ipFamilyPolicy }}
{{- end }}
{{- if .Values.server.service.ipFamilies }}
ipFamilies: {{ .Values.server.service.ipFamilies | toYaml | nindent 2 }}
{{- end }}
{{- end }}
clusterIP: None
publishNotReadyAddresses: true
ports:
Expand Down
8 changes: 8 additions & 0 deletions templates/server-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ spec:
{{- if .Values.server.service.type}}
type: {{ .Values.server.service.type }}
{{- end}}
{{- if (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) }}
{{- if .Values.server.service.ipFamilyPolicy }}
ipFamilyPolicy: {{ .Values.server.service.ipFamilyPolicy }}
{{- end }}
{{- if .Values.server.service.ipFamilies }}
ipFamilies: {{ .Values.server.service.ipFamilies | toYaml | nindent 2 }}
{{- end }}
{{- end }}
{{- if .Values.server.service.clusterIP }}
clusterIP: {{ .Values.server.service.clusterIP }}
{{- end }}
Expand Down
9 changes: 9 additions & 0 deletions templates/ui-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ metadata:
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- template "vault.ui.annotations" . }}
spec:

{{- if (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) }}
{{- if .Values.ui.serviceIpFamilyPolicy }}
ipFamilyPolicy: {{ .Values.ui.serviceIpFamilyPolicy }}
{{- end }}
{{- if .Values.ui.serviceIpFamilies }}
ipFamilies: {{ .Values.ui.serviceIpFamilies | toYaml | nindent 2 }}
{{- end }}
{{- end }}
selector:
app.kubernetes.io/name: {{ include "vault.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
Expand Down
42 changes: 42 additions & 0 deletions test/unit/server-headless-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,46 @@ load _helpers
. | tee /dev/stderr |
yq -r '.metadata.namespace' | tee /dev/stderr)
[ "${actual}" = "bar" ]
}

@test "server/headless-Service: Assert ipFamilyPolicy set" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-headless-service.yaml \
--set 'server.service.ipFamilyPolicy=PreferDualStack' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilyPolicy' | tee /dev/stderr)
[ "${actual}" = "PreferDualStack" ]
}

@test "server/headless-Service: Assert ipFamilies set" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-headless-service.yaml \
--set 'server.service.ipFamilies={IPv4,IPv6}' \
. | tee /dev/stderr |
yq '.spec.ipFamilies' -c | tee /dev/stderr)
[ "${actual}" = '["IPv4","IPv6"]' ]
}

@test "server/headless-Service: Assert ipFamilyPolicy is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-headless-service.yaml \
--kube-version 1.22.0 \
--set 'server.service.ipFamilyPolicy=PreferDualStack' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilyPolicy' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/headless-Service: Assert ipFamilies is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-headless-service.yaml \
--kube-version 1.22.0 \
--set 'server.service.ipFamilies={IPv4,IPv6}' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilies' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
42 changes: 42 additions & 0 deletions test/unit/server-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,45 @@ load _helpers
yq -r '.spec.selector["app.kubernetes.io/instance"]' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/Service: Assert ipFamilyPolicy set" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-service.yaml \
--set 'server.service.ipFamilyPolicy=PreferDualStack' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilyPolicy' | tee /dev/stderr)
[ "${actual}" = "PreferDualStack" ]
}

@test "server/Service: Assert ipFamilies set" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-service.yaml \
--set 'server.service.ipFamilies={IPv4,IPv6}' \
. | tee /dev/stderr |
yq '.spec.ipFamilies' -c | tee /dev/stderr)
[ "${actual}" = '["IPv4","IPv6"]' ]
}

@test "server/Service: Assert ipFamilyPolicy is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-service.yaml \
--kube-version 1.22.0 \
--set 'server.service.ipFamilyPolicy=PreferDualStack' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilyPolicy' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/Service: Assert ipFamilies is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/server-service.yaml \
--kube-version 1.22.0 \
--set 'server.service.ipFamilies={IPv4,IPv6}' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilies' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
45 changes: 45 additions & 0 deletions test/unit/ui-service.bats
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,50 @@ load _helpers
. | tee /dev/stderr |
yq '.spec.externalTrafficPolicy' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "ui/Service: Assert ipFamilies set" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/ui-service.yaml \
--set 'ui.enabled=true' \
--set 'ui.serviceIpFamilies={IPv4,IPv6}' \
. | tee /dev/stderr |
yq '.spec.ipFamilies' -c | tee /dev/stderr)
[ "${actual}" = '["IPv4","IPv6"]' ]
}

@test "ui/Service: Assert ipFamilyPolicy set" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/ui-service.yaml \
--set 'ui.enabled=true' \
--set 'ui.serviceIpFamilyPolicy=PreferDualStack' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilyPolicy' | tee /dev/stderr)
[ "${actual}" = "PreferDualStack" ]
}

@test "server/Service: Assert ipFamilyPolicy is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/ui-service.yaml \
--kube-version 1.22.0 \
--set 'ui.enabled=true' \
--set 'ui.serviceIpFamilyPolicy=PreferDualStack' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilyPolicy' | tee /dev/stderr)
[ "${actual}" = "null" ]
}

@test "server/Service: Assert ipFamilies is not set if version below 1.23" {
cd `chart_dir`
local actual=$(helm template \
--show-only templates/ui-service.yaml \
--kube-version 1.22.0 \
--set 'ui.enabled=true' \
--set 'ui.serviceIpFamilies={IPv4,IPv6}' \
. | tee /dev/stderr |
yq -r '.spec.ipFamilies' | tee /dev/stderr)
[ "${actual}" = "null" ]
}
18 changes: 18 additions & 0 deletions values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,14 @@
},
"standbyNodePort": {
"type": "integer"
},
"ipFamilyPolicy": {
"type": "string"
},
"ipFamilies": {
"type": [
"array"
]
}
}
},
Expand Down Expand Up @@ -1143,6 +1151,16 @@
},
"targetPort": {
"type": "integer"
},
"serviceIpFamilyPolicy": {
"type": [
"string"
]
},
"serviceIpFamilies": {
"type": [
"array"
]
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,22 @@ server:
# or NodePort.
#type: ClusterIP

# The IP family and IP families options are to set the behaviour in a dual-stack environment
# Omitting these values will let the service fall back to whatever the CNI dictates the defaults
# should be
#
# Only supported for kubernetes versions >=1.23.0
#
# Configures the service's supported IP family policy, can be either:
# SingleStack: Single-stack service. The control plane allocates a cluster IP for the Service, using the first configured service cluster IP range.
# PreferDualStack: Allocates IPv4 and IPv6 cluster IPs for the Service.
# RequireDualStack: Allocates Service .spec.ClusterIPs from both IPv4 and IPv6 address ranges.
ipFamilyPolicy: ""
#
# Sets the families that should be supported and the order in which they should be applied to ClusterIP as well
#
ipFamilies: []

# Do not wait for pods to be ready before including them in the services'
# targets. Does not apply to the headless service, which is used for
# cluster-internal communication.
Expand Down Expand Up @@ -979,6 +995,21 @@ ui:
externalPort: 8200
targetPort: 8200

# The IP family and IP families options are to set the behaviour in a dual-stack environment
# Omitting these values will let the service fall back to whatever the CNI dictates the defaults
# should be
#
# Sets the families that should be supported and the order in which they should be applied to ClusterIP as well
# Can be IPv4 and/or IPv6
serviceIpFamilies: []

# Configures the service's supported IP family, can be either:
# SingleStack: Single-stack service. The control plane allocates a cluster IP for the Service, using the first configured service cluster IP range.
# PreferDualStack: Allocates IPv4 and IPv6 cluster IPs for the Service.
# RequireDualStack: Allocates Service .spec.ClusterIPs from both IPv4 and IPv6 address ranges.
# Only supported for kubernetes versions >=1.23.0
serviceIpFamilyPolicy: ""

# The externalTrafficPolicy can be set to either Cluster or Local
# and is only valid for LoadBalancer and NodePort service types.
# The default value is Cluster.
Expand Down

0 comments on commit 0878b35

Please sign in to comment.