Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(misc): hostNetwork deployment when hostPort mismatches containerPort #337

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f5c06fd
fix(misc): see traefik/traefik-helm-chart#336
faust64 Jan 14, 2021
3ece6c9
Merge remote-tracking branch 'upstream/master' into patch-hostnetwork
faust64 Jan 21, 2021
db0f2e0
fix(travis)
faust64 Jan 21, 2021
9e275bb
fix(unit-tests)
faust64 Jan 21, 2021
becfcf5
fix(pebkac)
faust64 Jan 21, 2021
0eccc68
Merge branch 'master' into patch-hostnetwork
faust64 Feb 4, 2021
3fc29a9
merge master
faust64 Feb 23, 2021
dca9ad3
Merge remote-tracking branch 'upstream/master' into patch-hostnetwork
faust64 Feb 23, 2021
668581e
Merge branch 'master' into patch-hostnetwork
faust64 Mar 2, 2021
fd3a8a3
fix(tests): allowCrossNamespace
faust64 Mar 2, 2021
deeb9f6
fix(tests): hostNetwork
faust64 Mar 2, 2021
3ad03df
Merge remote-tracking branch 'upstream/master' into patch-hostnetwork
faust64 Apr 9, 2021
e477c92
Merge remote-tracking branch 'traefik/master' into patch-hostnetwork
faust64 Aug 10, 2021
57a8a19
Merge remote-tracking branch 'upstream/master' into patch-hostnetwork
faust64 Sep 21, 2021
eb90b6a
Merge remote-tracking branch 'upstream/master' into patch-hostnetwork
faust64 Oct 13, 2021
12bf69a
Merge remote-tracking branch 'origin/master' into patch-hostnetwork
faust64 Dec 5, 2021
8f61a2f
fix
faust64 Dec 5, 2021
2475154
fix(tests): checked later
faust64 Dec 5, 2021
75b0f50
fix(tests)
faust64 Dec 5, 2021
8598c73
fix(tests)
faust64 Dec 5, 2021
fa168c4
Merge branch 'master' into patch-hostnetwork
faust64 Dec 15, 2021
257f9b0
update version
faust64 Dec 15, 2021
fcb6611
Merge remote-tracking branch 'upstream/master' into patch-hostnetwork
faust64 Mar 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion traefik/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: traefik
description: A Traefik based Kubernetes ingress controller
type: application
version: 10.15.0
version: 10.15.1
appVersion: 2.6.1
keywords:
- traefik
Expand Down
24 changes: 24 additions & 0 deletions traefik/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ If release name contains chart name it will be used as a full name.
{{- end -}}
{{- end -}}

{{/*
Overrides hostNetwork value in container definition, when at least one of the hostPorts exposed mismatches containerPort.
*/}}
{{- define "traefik.sethostnet" -}}
{{- if .Values.hostNetwork -}}
{{- range $name, $config := .Values.ports -}}
{{- if $config -}}
{{- if $config.hostPort -}}
{{- if ne ($config.hostPort | int) ($config.port | int) -}}
1
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "traefik.hostnetwork" -}}
{{- if gt (len (include "traefik.sethostnet" .)) 0 -}}
false
{{- else -}}
{{- .Values.hostNetwork -}}
{{- end -}}
{{- end -}}

{{/*
The name of the service account to use
*/}}
Expand Down
2 changes: 1 addition & 1 deletion traefik/templates/_podtemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{{- end }}
serviceAccountName: {{ include "traefik.serviceAccountName" . }}
terminationGracePeriodSeconds: {{ default 60 .Values.deployment.terminationGracePeriodSeconds }}
hostNetwork: {{ .Values.hostNetwork }}
hostNetwork: {{ template "traefik.hostnetwork" . }}
faust64 marked this conversation as resolved.
Show resolved Hide resolved
{{- with .Values.deployment.dnsPolicy }}
dnsPolicy: {{ . }}
{{- end }}
Expand Down
22 changes: 22 additions & 0 deletions traefik/templates/rbac/ingressclass-clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if and .Values.rbac.enabled .Values.rbac.namespaced }}
faust64 marked this conversation as resolved.
Show resolved Hide resolved
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "traefik.fullname" . }}-{{ .Release.Namespace }}
labels:
app.kubernetes.io/name: {{ template "traefik.name" . }}
helm.sh/chart: {{ template "traefik.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
rules:
- apiGroups:
- extensions
- networking.k8s.io
resources:
- ingressclasses
verbs:
- get
- list
- watch
{{- end -}}
20 changes: 20 additions & 0 deletions traefik/templates/rbac/ingressclass-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if and .Values.rbac.enabled .Values.rbac.namespaced }}
faust64 marked this conversation as resolved.
Show resolved Hide resolved
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ template "traefik.fullname" . }}-{{ .Release.Namespace }}
labels:
app.kubernetes.io/name: {{ template "traefik.name" . }}
helm.sh/chart: {{ template "traefik.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "traefik.fullname" . }}-{{ .Release.Namespace }}
subjects:
- kind: ServiceAccount
name: {{ include "traefik.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
10 changes: 7 additions & 3 deletions traefik/templates/rbac/podsecuritypolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ metadata:
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
privileged: false
allowPrivilegeEscalation: false
requiredDropCapabilities:
- ALL
{{- if not .Values.securityContext.runAsNonRoot }}
allowedCapabilities:
- NET_BIND_SERVICE
allowPrivilegeEscalation: true
privileged: true
{{- else }}
allowedCapabilities: []
allowPrivilegeEscalation: false
privileged: false
{{- end }}
hostNetwork: {{ .Values.hostNetwork }}
hostIPC: false
Expand Down Expand Up @@ -65,4 +69,4 @@ spec:
{{- if .Values.persistence.enabled }}
- persistentVolumeClaim
{{- end -}}
{{- end -}}
{{- end -}}
1 change: 1 addition & 0 deletions traefik/templates/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if and .Values.rbac.enabled .Values.rbac.namespaced }}
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand Down
1 change: 1 addition & 0 deletions traefik/templates/rbac/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if and .Values.rbac.enabled .Values.rbac.namespaced }}
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand Down
30 changes: 30 additions & 0 deletions traefik/tests/pod-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,36 @@ tests:
content:
key: "RSA"
operator: "Destructor"
- it: should request hostNetwork at Pod level when containerPort equals hostPort
set:
hostNetwork: true
ports:
web:
expose: true
hostPort: 8080
port: 8080
websecure:
expose: true
hostPort: 8443
port: 8443
asserts:
- equal:
path: spec.template.spec.hostnetwork
content: true
- it: should not request hostNetwork at Pod level when containerPort mistmatches hostPort
set:
hostNetwork: true
ports:
web:
port: 8080
hostPort: 80
websecure:
port: 8443
hostPort: 443
asserts:
- equal:
path: spec.template.spec.hostnetwork
content: false
- it: should have all k8s provider enabled when gateway provider is enabled
set:
experimental:
Expand Down
18 changes: 18 additions & 0 deletions traefik/tests/rbac-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ tests:
- isKind:
of: ClusterRoleBinding
template: rbac/clusterrolebinding.yaml
- hasDocuments:
count: 0
template: rbac/ingressclass-clusterrole.yaml
- hasDocuments:
count: 0
template: rbac/ingressclass-clusterrolebinding.yaml
- hasDocuments:
count: 0
template: rbac/role.yaml
Expand Down Expand Up @@ -40,6 +46,12 @@ tests:
- hasDocuments:
count: 0
template: rbac/clusterrolebinding.yaml
- hasDocuments:
count: 0
template: rbac/ingressclass-clusterrole.yaml
- hasDocuments:
count: 0
template: rbac/ingressclass-clusterrolebinding.yaml
- hasDocuments:
count: 0
template: rbac/role.yaml
Expand All @@ -57,6 +69,12 @@ tests:
- isKind:
of: RoleBinding
template: rbac/rolebinding.yaml
- isKind:
of: ClusterRole
template: rbac/ingressclass-clusterrole.yaml
- isKind:
of: ClusterRoleBinding
template: rbac/ingressclass-clusterrolebinding.yaml
- hasDocuments:
count: 0
template: rbac/clusterrole.yaml
Expand Down
37 changes: 26 additions & 11 deletions traefik/tests/traefik-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ tests:
- contains:
path: spec.template.spec.containers[0].args
content: "--providers.kubernetesingress.ingressendpoint.publishedservice=foo/bar"

- it: should allow cross namespace services when specified in configuration
set:
providers:
kubernetesCRD:
allowCrossNamespace: true
asserts:
- contains:
path: spec.template.spec.containers[0].args
content: "--providers.kubernetescrd.allowCrossNamespace=true"
- it: should allow external name services when specified in configuration
set:
providers:
Expand Down Expand Up @@ -208,7 +198,32 @@ tests:
- equal:
path: spec.template.spec.containers[0].volumeMounts[3].mountPath
value: /var/log/traefik

- it: should set KubernetesCRD allowCrossNamespace
set:
providers:
kubernetesCRD:
allowCrossNamespace: true
enabled: true
asserts:
- contains:
path: spec.template.spec.containers[0].args
content: "--providers.kubernetescrd.allowCrossNamespace=true"
- contains:
path: spec.template.spec.containers[0].args
content: "--providers.kubernetescrd"
- it: should disable KubernetesCRD allowCrossNamespace
set:
providers:
kubernetesCRD:
allowCrossNamespace: false
enabled: true
asserts:
- notContains:
path: spec.template.spec.containers[0].args
content: "--providers.kubernetescrd.allowCrossNamespace=true"
- contains:
path: spec.template.spec.containers[0].args
content: "--providers.kubernetescrd"
- it: should set custom probe port
set:
additionalArguments:
Expand Down