Skip to content

Commit d8fbbcb

Browse files
authored
feat(helm): add support for nodePort specification in LoadBalancer services helm chart (#16032)
## Short description: This pull request introduces support for optionally specify `nodePort` values when using `LoadBalancer` service type in the Coder Helm chart. This enhancement addresses a limitation where `httpNodePort` and `httpsNodePort` values were previously ignored for `LoadBalancer` services. This PR should expand the service customization options without disrupting existing configurations. ## Why this is Useful In some enterprise environments, applications may be required to use specific ports for compliance with organizational policies or cloud infrastructure requirements. For instance: - Reserved port blocks are allocated for specific applications for security and clarity. - Ensuring predictable port assignments helps in debugging and management scenarios. Since LoadBalancer in Kubernetes operates on top of nodePort, this feature is useful for enabling enterprises to adhere to such policies if they whish. ## What Was Changed - Updated helm/coder/templates/service.yaml: - Allowed nodePort specification for both NodePort and LoadBalancer service types. - Updated helm/coder/templates/values.yaml: - Updated inline comments to reflect the changes for nodeport values use cases. ### Regarding backward compatibility: If nodePort is not specified, Kubernetes dynamically assigns a port, maintaining the current behavior. ### Testing Performed - Validated through Helm dry-run: nodePort values are rendered correctly in the resulting Kubernetes YAML. - Deployed the updated chart in an enterprise Kubernetes cluster. - Tested coder environment with LoadBalancer service and specified nodePort values for both HTTP and HTTPS. ## Additional Notes - This PR expands the nodeport functionality introduced in PR #8993 to the Loadbalancer service. - If merged, an update to the documentation to include examples of LoadBalancer with nodePort values may be useful. - I've read the contributing guidelines and code of conduct. This is my first PR for the Coder project, and I hope it meets the community standards. Any advice, feedback, or help is greatly appreciated!
1 parent 2913fe8 commit d8fbbcb

25 files changed

+427
-26
lines changed

helm/coder/templates/service.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ spec:
1616
port: 80
1717
targetPort: "http"
1818
protocol: TCP
19-
{{ if eq .Values.coder.service.type "NodePort" }}
19+
{{- if or (eq .Values.coder.service.type "NodePort") (eq .Values.coder.service.type "LoadBalancer") }}
2020
nodePort: {{ .Values.coder.service.httpNodePort }}
21-
{{ end }}
21+
{{- end }}
2222
{{- if eq (include "coder.tlsEnabled" .) "true" }}
2323
- name: "https"
2424
port: 443
2525
targetPort: "https"
2626
protocol: TCP
27-
{{ if eq .Values.coder.service.type "NodePort" }}
27+
{{- if or (eq .Values.coder.service.type "NodePort") (eq .Values.coder.service.type "LoadBalancer") }}
2828
nodePort: {{ .Values.coder.service.httpsNodePort }}
29-
{{ end }}
29+
{{- end }}
3030
{{- end }}
3131
{{- if eq "LoadBalancer" .Values.coder.service.type }}
3232
{{- with .Values.coder.service.loadBalancerIP }}

helm/coder/tests/chart_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ var testCases = []testCase{
100100
name: "svc_loadbalancer_class",
101101
expectedError: "",
102102
},
103+
{
104+
name: "svc_nodeport",
105+
expectedError: "",
106+
},
107+
{
108+
name: "svc_loadbalancer",
109+
expectedError: "",
110+
},
103111
}
104112

105113
type testCase struct {

helm/coder/tests/testdata/auto_access_url_1.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
port: 80
9191
targetPort: "http"
9292
protocol: TCP
93-
93+
nodePort:
9494
externalTrafficPolicy: "Cluster"
9595
selector:
9696
app.kubernetes.io/name: coder

helm/coder/tests/testdata/auto_access_url_2.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
port: 80
9191
targetPort: "http"
9292
protocol: TCP
93-
93+
nodePort:
9494
externalTrafficPolicy: "Cluster"
9595
selector:
9696
app.kubernetes.io/name: coder

helm/coder/tests/testdata/auto_access_url_3.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
port: 80
9191
targetPort: "http"
9292
protocol: TCP
93-
93+
nodePort:
9494
externalTrafficPolicy: "Cluster"
9595
selector:
9696
app.kubernetes.io/name: coder

helm/coder/tests/testdata/command.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
port: 80
9191
targetPort: "http"
9292
protocol: TCP
93-
93+
nodePort:
9494
externalTrafficPolicy: "Cluster"
9595
selector:
9696
app.kubernetes.io/name: coder

helm/coder/tests/testdata/command_args.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
port: 80
9191
targetPort: "http"
9292
protocol: TCP
93-
93+
nodePort:
9494
externalTrafficPolicy: "Cluster"
9595
selector:
9696
app.kubernetes.io/name: coder

helm/coder/tests/testdata/default_values.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
port: 80
9191
targetPort: "http"
9292
protocol: TCP
93-
93+
nodePort:
9494
externalTrafficPolicy: "Cluster"
9595
selector:
9696
app.kubernetes.io/name: coder

helm/coder/tests/testdata/env_from.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ spec:
9090
port: 80
9191
targetPort: "http"
9292
protocol: TCP
93-
93+
nodePort:
9494
externalTrafficPolicy: "Cluster"
9595
selector:
9696
app.kubernetes.io/name: coder

helm/coder/tests/testdata/extra_templates.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ spec:
9999
port: 80
100100
targetPort: "http"
101101
protocol: TCP
102-
102+
nodePort:
103103
externalTrafficPolicy: "Cluster"
104104
selector:
105105
app.kubernetes.io/name: coder

0 commit comments

Comments
 (0)