Skip to content

feat(helm): add support for nodePort specification in LoadBalancer services helm chart #16032

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

Merged
merged 8 commits into from
Jan 20, 2025
8 changes: 4 additions & 4 deletions helm/coder/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ spec:
port: 80
targetPort: "http"
protocol: TCP
{{ if eq .Values.coder.service.type "NodePort" }}
{{- if or (eq .Values.coder.service.type "NodePort") (eq .Values.coder.service.type "LoadBalancer") }}
nodePort: {{ .Values.coder.service.httpNodePort }}
{{ end }}
{{- end }}
{{- if eq (include "coder.tlsEnabled" .) "true" }}
- name: "https"
port: 443
targetPort: "https"
protocol: TCP
{{ if eq .Values.coder.service.type "NodePort" }}
{{- if or (eq .Values.coder.service.type "NodePort") (eq .Values.coder.service.type "LoadBalancer") }}
nodePort: {{ .Values.coder.service.httpsNodePort }}
{{ end }}
{{- end }}
{{- end }}
{{- if eq "LoadBalancer" .Values.coder.service.type }}
{{- with .Values.coder.service.loadBalancerIP }}
Expand Down
8 changes: 8 additions & 0 deletions helm/coder/tests/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ var testCases = []testCase{
name: "svc_loadbalancer_class",
expectedError: "",
},
{
name: "svc_nodeport",
expectedError: "",
},
{
name: "svc_loadbalancer",
expectedError: "",
},
}

type testCase struct {
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/auto_access_url_1.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/auto_access_url_2.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/auto_access_url_3.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/command.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/command_args.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/default_values.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/env_from.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/extra_templates.golden
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/labels_annotations.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 0 additions & 2 deletions helm/coder/tests/testdata/prometheus.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:

selector:
app.kubernetes.io/name: coder
app.kubernetes.io/instance: release-name
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/provisionerd_psk.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/sa.golden
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/sa_disabled.golden
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/sa_extra_rules.golden
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
Expand Down
190 changes: 190 additions & 0 deletions helm/coder/tests/testdata/svc_loadbalancer.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
---
# Source: coder/templates/coder.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
annotations: {}
labels:
app.kubernetes.io/instance: release-name
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: coder
app.kubernetes.io/part-of: coder
app.kubernetes.io/version: 0.1.0
helm.sh/chart: coder-0.1.0
name: coder
---
# Source: coder/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: coder-workspace-perms
rules:
- apiGroups: [""]
resources: ["pods"]
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
- apiGroups: [""]
resources: ["persistentvolumeclaims"]
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
- deployments
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
---
# Source: coder/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: "coder"
subjects:
- kind: ServiceAccount
name: "coder"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: coder-workspace-perms
---
# Source: coder/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: coder
labels:
helm.sh/chart: coder-0.1.0
app.kubernetes.io/name: coder
app.kubernetes.io/instance: release-name
app.kubernetes.io/part-of: coder
app.kubernetes.io/version: "0.1.0"
app.kubernetes.io/managed-by: Helm
annotations:
{}
spec:
type: LoadBalancer
sessionAffinity: None
ports:
- name: "http"
port: 80
targetPort: "http"
protocol: TCP
nodePort: 30080
externalTrafficPolicy: "Cluster"
selector:
app.kubernetes.io/name: coder
app.kubernetes.io/instance: release-name
---
# Source: coder/templates/coder.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
app.kubernetes.io/instance: release-name
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: coder
app.kubernetes.io/part-of: coder
app.kubernetes.io/version: 0.1.0
helm.sh/chart: coder-0.1.0
name: coder
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: release-name
app.kubernetes.io/name: coder
template:
metadata:
annotations: {}
labels:
app.kubernetes.io/instance: release-name
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: coder
app.kubernetes.io/part-of: coder
app.kubernetes.io/version: 0.1.0
helm.sh/chart: coder-0.1.0
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: app.kubernetes.io/instance
operator: In
values:
- coder
topologyKey: kubernetes.io/hostname
weight: 1
containers:
- args:
- server
command:
- /opt/coder
env:
- name: CODER_HTTP_ADDRESS
value: 0.0.0.0:8080
- name: CODER_PROMETHEUS_ADDRESS
value: 0.0.0.0:2112
- name: CODER_ACCESS_URL
value: http://coder.default.svc.cluster.local
- name: KUBE_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: CODER_DERP_SERVER_RELAY_URL
value: http://$(KUBE_POD_IP):8080
image: ghcr.io/coder/coder:latest
imagePullPolicy: IfNotPresent
lifecycle: {}
livenessProbe:
httpGet:
path: /healthz
port: http
scheme: HTTP
name: coder
ports:
- containerPort: 8080
name: http
protocol: TCP
readinessProbe:
httpGet:
path: /healthz
port: http
scheme: HTTP
resources: {}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: null
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
volumeMounts: []
restartPolicy: Always
serviceAccountName: coder
terminationGracePeriodSeconds: 60
volumes: []
8 changes: 8 additions & 0 deletions helm/coder/tests/testdata/svc_loadbalancer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coder:
image:
tag: latest

service:
type: LoadBalancer
httpNodePort: 30080
httpsNodePort: 30043
2 changes: 1 addition & 1 deletion helm/coder/tests/testdata/svc_loadbalancer_class.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ spec:
port: 80
targetPort: "http"
protocol: TCP

nodePort:
externalTrafficPolicy: "Cluster"
loadBalancerClass: "test"
selector:
Expand Down
Loading
Loading