mirror of
https://github.com/truenas/charts.git
synced 2024-04-21 15:21:45 +00:00
loadbalancer
This commit is contained in:
@@ -2,15 +2,13 @@ suite: service clusterIP test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should pass with type ClusterIP and custom cluster ip
|
||||
- it: should pass with type ClusterIP
|
||||
set:
|
||||
some_ip: 172.16.20.35
|
||||
service:
|
||||
my-service:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: ClusterIP
|
||||
clusterIP: "{{ .Values.some_ip }}"
|
||||
ports:
|
||||
port-name:
|
||||
enabled: true
|
||||
@@ -37,17 +35,18 @@ tests:
|
||||
path: spec
|
||||
value:
|
||||
type: ClusterIP
|
||||
clusterIP: 172.16.20.35
|
||||
|
||||
- it: should pass with type ClusterIP and ipFamilyPolicy set
|
||||
- it: should pass with type ClusterIP and available options set
|
||||
set:
|
||||
some_policy: PreferDualStack
|
||||
some_family: IPv6
|
||||
some_ip: 172.16.20.35
|
||||
service:
|
||||
my-service:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: ClusterIP
|
||||
clusterIP: "{{ .Values.some_ip }}"
|
||||
ipFamilyPolicy: "{{ .Values.some_policy }}"
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
@@ -68,6 +67,7 @@ tests:
|
||||
path: spec
|
||||
value:
|
||||
type: ClusterIP
|
||||
clusterIP: 172.16.20.35
|
||||
ipFamilyPolicy: PreferDualStack
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
suite: service loadBalancer test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should pass with type LoadBalancer
|
||||
set:
|
||||
service:
|
||||
my-service:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
port-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
workload:
|
||||
my-workload:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
asserts:
|
||||
- documentIndex: &serviceDoc 1
|
||||
isKind:
|
||||
of: Service
|
||||
- documentIndex: *serviceDoc
|
||||
isAPIVersion:
|
||||
of: v1
|
||||
- documentIndex: *serviceDoc
|
||||
equal:
|
||||
path: metadata.name
|
||||
value: release-name-common-test
|
||||
- documentIndex: *serviceDoc
|
||||
equal:
|
||||
path: spec
|
||||
value:
|
||||
type: LoadBalancer
|
||||
|
||||
- it: should pass with type LoadBalancer and available options set
|
||||
set:
|
||||
some_ip: 172.16.20.35
|
||||
some_other_ip: 10.100.200.45
|
||||
some_range: 11.100.200.0/24
|
||||
service:
|
||||
my-service:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: LoadBalancer
|
||||
clusterIP: "{{ .Values.some_ip }}"
|
||||
loadBalancerIP: "{{ .Values.some_other_ip }}"
|
||||
loadBalancerSourceRanges:
|
||||
- "{{ .Values.some_range }}"
|
||||
- 10.100.200.0/24
|
||||
externalTrafficPolicy: Local
|
||||
ipFamilyPolicy: PreferDualStack
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
- IPv6
|
||||
ports:
|
||||
port-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
workload:
|
||||
my-workload:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
asserts:
|
||||
- documentIndex: *serviceDoc
|
||||
equal:
|
||||
path: spec
|
||||
value:
|
||||
type: LoadBalancer
|
||||
clusterIP: 172.16.20.35
|
||||
loadBalancerIP: 10.100.200.45
|
||||
loadBalancerSourceRanges:
|
||||
- 11.100.200.0/24
|
||||
- 10.100.200.0/24
|
||||
externalTrafficPolicy: Local
|
||||
ipFamilyPolicy: PreferDualStack
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
- IPv6
|
||||
@@ -271,3 +271,25 @@ tests:
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Service - Expected <ipFamilies> to be one of [IPv4, IPv6], but got [not-a-family]
|
||||
|
||||
- it: should fail with invalid externalTrafficPolicy
|
||||
set:
|
||||
service:
|
||||
service-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: LoadBalancer
|
||||
externalTrafficPolicy: not-a-policy
|
||||
ports:
|
||||
port-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
workload:
|
||||
some-pod-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Service - Expected <externalTrafficPolicy> to be one of [Cluster, Local], but got [not-a-policy]
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
# Service
|
||||
|
||||
| Key | Type | Required | Helm Template | Default | Description |
|
||||
| :------------------------------------------- | :-------: | :------: | :----------------: | :---------: | :------------------------------------------------------------------------------------ |
|
||||
| service | `dict` | ❌ | ❌ | `{}` | Define the service as dicts |
|
||||
| service.[service-name] | `dict` | ✅ | ❌ | `{}` | Holds service definition |
|
||||
| service.[service-name].enabled | `boolean` | ✅ | ❌ | `false` | Enables or Disables the service |
|
||||
| service.[service-name].labels | `dict` | ❌ | ✅ (On value only) | `{}` | Additional labels for service |
|
||||
| service.[service-name].annotations | `dict` | ❌ | ✅ (On value only) | `{}` | Additional annotations for service |
|
||||
| service.[service-name].type | `string` | ❌ | ✅ | `ClusterIP` | Define the service type (ClusterIP, LoadBalancer, NodePort, ExternalIP, ExternalName) |
|
||||
| service.[service-name].sharedKey | `string` | ❌ | ✅ | `$FullName` | Custom Shared Key for MetalLB Annotation |
|
||||
| service.[service-name].clusterIP | `string` | ❌ | ✅ | | Custom Cluster IP |
|
||||
| service.[service-name].ipFamilyPolicy | `string` | ❌ | ✅ | | Define the ipFamilyPolicy (SingleStack, PreferDualStack, RequireDualStack) |
|
||||
| service.[service-name].ipFamilies | `list` | ❌ | ❌ | | Define the ipFamilies |
|
||||
| service.[service-name].ipFamilies.[ipFamily] | `string` | ❌ | ✅ | | Define the ipFamily (IPv4, IPv6) |
|
||||
| service.[service-name].targetSelector | `string` | ❌ | ✅ | `""` | Define the pod to link the service, by default will use the primary pod |
|
||||
| service.[service-name].ports | `list` | ✅ | ❌ | `{}` | Define the ports of the service |
|
||||
| Key | Type | Required | Helm Template | Default | Description |
|
||||
| :------------------------------------------------------------- | :-------: | :------: | :----------------: | :---------: | :------------------------------------------------------------------------------------ |
|
||||
| service | `dict` | ❌ | ❌ | `{}` | Define the service as dicts |
|
||||
| service.[service-name] | `dict` | ✅ | ❌ | `{}` | Holds service definition |
|
||||
| service.[service-name].enabled | `boolean` | ✅ | ❌ | `false` | Enables or Disables the service |
|
||||
| service.[service-name].labels | `dict` | ❌ | ✅ (On value only) | `{}` | Additional labels for service |
|
||||
| service.[service-name].annotations | `dict` | ❌ | ✅ (On value only) | `{}` | Additional annotations for service |
|
||||
| service.[service-name].type | `string` | ❌ | ✅ | `ClusterIP` | Define the service type (ClusterIP, LoadBalancer, NodePort, ExternalIP, ExternalName) |
|
||||
| service.[service-name].sharedKey | `string` | ❌ | ✅ | `$FullName` | Custom Shared Key for MetalLB Annotation |
|
||||
| service.[service-name].clusterIP | `string` | ❌ | ✅ | | Custom Cluster IP |
|
||||
| service.[service-name].ipFamilyPolicy | `string` | ❌ | ✅ | | Define the ipFamilyPolicy (SingleStack, PreferDualStack, RequireDualStack) |
|
||||
| service.[service-name].ipFamilies | `list` | ❌ | ❌ | | Define the ipFamilies |
|
||||
| service.[service-name].ipFamilies.[ipFamily] | `string` | ✅ | ✅ | | Define the ipFamily (IPv4, IPv6) |
|
||||
| service.[service-name].loadBalancerIP | `string` | ❌ | ✅ | | Define the load balancer IP |
|
||||
| service.[service-name].loadBalancerSourceRanges | `list` | ❌ | ❌ | | Define the load balancer source ranges |
|
||||
| service.[service-name].loadBalancerSourceRanges.[source-range] | `string` | ✅ | ✅ | | Define the load balancer source range |
|
||||
| service.[service-name].externalTrafficPolicy | `string` | ❌ | ✅ | | Define the external traffic policy (Cluster, Local) |
|
||||
| service.[service-name].targetSelector | `string` | ❌ | ✅ | `""` | Define the pod to link the service, by default will use the primary pod |
|
||||
| service.[service-name].ports | `list` | ✅ | ❌ | `{}` | Define the ports of the service |
|
||||
|
||||
---
|
||||
|
||||
@@ -35,12 +39,34 @@ Examples:
|
||||
|
||||
```yaml
|
||||
service:
|
||||
service-name:
|
||||
service-clusterip:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: ClusterIP
|
||||
clusterIP: 172.16.20.233
|
||||
ipFamilyPolicy: SingleStack
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
targetSelector: pod-name
|
||||
ports:
|
||||
port-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
container-name: container-name
|
||||
|
||||
service-lb:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: LoadBalancer
|
||||
loadBalancerIP: 10.100.100.2
|
||||
loadBalancerSourceRanges:
|
||||
- 10.100.100.0/24
|
||||
clusterIP: 172.16.20.233
|
||||
sharedKey: custom-shared-key
|
||||
ipFamilyPolicy: SingleStack
|
||||
ipFamilies:
|
||||
- IPv4
|
||||
externalTrafficPolicy: Cluster
|
||||
targetSelector: pod-name
|
||||
ports:
|
||||
port-name:
|
||||
enabled: true
|
||||
|
||||
@@ -69,7 +69,9 @@ metadata:
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- if eq $svcType "ClusterIP" -}}
|
||||
{{- include "ix.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }}
|
||||
{{- include "ix.v1.common.lib.service.spec.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }}
|
||||
{{- else if eq $svcType "LoadBalancer" -}}
|
||||
{{- include "ix.v1.common.lib.service.spec.loadBalancer" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }}
|
||||
{{- end }}
|
||||
{{- if not (mustHas $svcType (list "ExternalName" "ExternalIP")) }}
|
||||
selector:
|
||||
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
{{/* Service - ClusterIP */}}
|
||||
{{/* Service - clusterIP */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the service
|
||||
@@ -9,9 +9,8 @@ objectData: The service object data
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData }}
|
||||
|
||||
type: ClusterIP
|
||||
{{- with $objectData.clusterIP }}
|
||||
clusterIP: {{ tpl . $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- include "ix.v1.common.lib.service.ipFamily" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
|
||||
|
||||
{{- end -}}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
{{/* Service - externalTrafficPolicy */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the service
|
||||
objectData: The service object data
|
||||
*/}}
|
||||
|
||||
{{- define "ix.v1.common.lib.service.externalTrafficPolicy" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData }}
|
||||
|
||||
{{- with $objectData.externalTrafficPolicy }}
|
||||
{{- $policy := tpl . $rootCtx -}}
|
||||
{{- $policies := (list "Cluster" "Local") -}}
|
||||
|
||||
{{- if not (mustHas $policy $policies) -}}
|
||||
{{- fail (printf "Service - Expected <externalTrafficPolicy> to be one of [%s], but got [%s]" (join ", " $policies) $policy) -}}
|
||||
{{- end }}
|
||||
externalTrafficPolicy: {{ $policy }}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,16 @@
|
||||
{{/* Service - ClusterIP Spec */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.service.spec.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the service
|
||||
objectData: The service object data
|
||||
*/}}
|
||||
|
||||
{{- define "ix.v1.common.lib.service.spec.clusterIP" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData }}
|
||||
|
||||
type: ClusterIP
|
||||
|
||||
{{- include "ix.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
|
||||
{{- include "ix.v1.common.lib.service.ipFamily" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,27 @@
|
||||
{{/* Service - LoadBalancer Spec */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.service.spec.loadBalancer" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the service
|
||||
objectData: The service object data
|
||||
*/}}
|
||||
|
||||
{{- define "ix.v1.common.lib.service.spec.loadBalancer" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData }}
|
||||
|
||||
type: LoadBalancer
|
||||
{{- with $objectData.loadBalancerIP }}
|
||||
loadBalancerIP: {{ tpl . $rootCtx }}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $objectData.loadBalancerSourceRanges }}
|
||||
loadBalancerSourceRanges:
|
||||
{{- range . }}
|
||||
- {{ tpl . $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- include "ix.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
|
||||
{{- include "ix.v1.common.lib.service.ipFamily" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
|
||||
{{- include "ix.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user