Skip to content

Commit

Permalink
added targetPort support
Browse files Browse the repository at this point in the history
  • Loading branch information
TLPNull authored Apr 19, 2023
1 parent 7a6c6f1 commit 0f1eef1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion traefik/templates/_service-internal.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{{- if $config.expose }}
- port: {{ default $config.port $config.exposedPort }}
name: {{ $name | quote }}
targetPort: {{ $name }}
targetPort: {{ default $name $config.targetPort }}
protocol: {{ default "TCP" $config.protocol }}
{{- if $config.nodePort }}
nodePort: {{ $config.nodePort }}
Expand Down
4 changes: 2 additions & 2 deletions traefik/templates/_service.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{{- if $config.expose }}
- port: {{ default $config.port $config.exposedPort }}
name: {{ $name | quote }}
targetPort: {{ $name }}
targetPort: {{ default $name $config.targetPort }}
protocol: {{ default "TCP" $config.protocol }}
{{- if $config.nodePort }}
nodePort: {{ $config.nodePort }}
Expand All @@ -49,7 +49,7 @@
{{- $http3Port := default $config.exposedPort $config.http3.advertisedPort }}
- port: {{ $http3Port }}
name: "{{ $name }}-http3"
targetPort: {{ $config.port }}
targetPort: {{ default $config.port $config.targetPort }}
protocol: UDP
{{- if $config.nodePort }}
nodePort: {{ $config.nodePort }}
Expand Down
27 changes: 27 additions & 0 deletions traefik/tests/service-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,30 @@ tests:
- equal:
path: metadata.namespace
value: "traefik-ns-override"
- it: should have different target port when targetPort is different from port
set:
ports:
web:
port: 8080
exposedPort: 80
expose: true
targetPort: 80
websecure:
port: 443
exposedPort: 443
expose: true
targetPort: 80
documentIndex: 0
asserts:
- equal:
path: spec.ports[0].port
value: 80
- equal:
path: spec.ports[0].targetPort
value: 80
- equal:
path: spec.ports[1].port
value: 443
- equal:
path: spec.ports[1].targetPort
value: 80
4 changes: 4 additions & 0 deletions traefik/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ ports:
# containerPort: 8000
expose: true
exposedPort: 80
## Different target traefik port on the cluster, useful for IP type LB
# targetPort: 80
# The port protocol (TCP/UDP)
protocol: TCP
# Use nodeport if set. This is useful if you have configured Traefik in a
Expand Down Expand Up @@ -601,6 +603,8 @@ ports:
# containerPort: 8443
expose: true
exposedPort: 443
## Different target traefik port on the cluster, useful for IP type LB
# targetPort: 80
## The port protocol (TCP/UDP)
protocol: TCP
# nodePort: 32443
Expand Down

0 comments on commit 0f1eef1

Please sign in to comment.