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

Conversation

MRColorR
Copy link
Contributor

@MRColorR MRColorR commented Jan 3, 2025

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 feat: add support for NodePort service type in Helm chart #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!

@cdr-bot cdr-bot bot added the community Pull Requests and issues created by the community. label Jan 3, 2025
Copy link

github-actions bot commented Jan 3, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@MRColorR MRColorR changed the title Feat: Add support for nodePort specification in LoadBalancer services helm chart feat(helm): add support for nodePort specification in LoadBalancer services helm chart Jan 3, 2025
@MRColorR
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

cdrci2 added a commit to coder/cla that referenced this pull request Jan 10, 2025
@MRColorR
Copy link
Contributor Author

recheck

@matifali
Copy link
Member

Hi, @MRColorR, you also need to run make gen to update generated files.

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a corresponding helm test for the new loadbalancer type.

@MRColorR
Copy link
Contributor Author

MRColorR commented Jan 16, 2025

Hi, @MRColorR, you also need to run make gen to update generated files.

hello, thank you for the help. i've done it in my code devcontainer but i see no new files in git status.
make gen exited without errors after some time.

@MRColorR
Copy link
Contributor Author

Please also add a corresponding helm test for the new loadbalancer type.

could you please elaborate more ? i've see there's an already existing svc_loadbalancer_class test , would you like me to extend this one or create a new one ?

@johnstcn
Copy link
Member

johnstcn commented Jan 16, 2025

could you please elaborate more ? i've see there's an already existing svc_loadbalancer_class test , would you like me to extend this one or create a new one ?

@MRColorR Sure thing! As I see it, there are three paths we need to consider:

  • If coder.service.type is LoadBalancer, then template coder.service.httpNodePort and coder.service.httpsNodePort (new behaviour, currently not covered)
  • If coder.service.type is NodePort, then template coder.service.httpNodePort and coder.service.httpsNodePort (existing behaviour, currently not covered)
  • Otherwise, do not template coder.service.httpNodePort and coder.service.httpsNodePort (existing behaviour, covered)

Based on that, I think we need to:

  • Add helm/coder/tests/testdata/svc_nodeport.yaml with the corresponding values to set service_type to NodePort. It looks like test coverage was missed when this was previously added. You'll also want to add a corresponding test case in helm/coder/tests/testdata/chart_test.go.
  • Update existing helm/coder/tests/testdata/*.golden with your current set of changes and review the output of helm template.

Tip: you can run go test ./helm/coder/tests -update to update the existing golden files without failing on a diff.

Hope that helps!

@MRColorR
Copy link
Contributor Author

could you please elaborate more ? i've see there's an already existing svc_loadbalancer_class test , would you like me to extend this one or create a new one ?

@MRColorR Sure thing! As I see it, there are three paths we need to consider:

  • If coder.service.type is LoadBalancer, then template coder.service.httpNodePort and coder.service.httpsNodePort (new behaviour, currently not covered)
  • If coder.service.type is NodePort, then template coder.service.httpNodePort and coder.service.httpsNodePort (existing behaviour, currently not covered)
  • Otherwise, do not template coder.service.httpNodePort and coder.service.httpsNodePort (existing behaviour, covered)

Based on that, I think we need to:

  • Add helm/coder/tests/testdata/svc_nodeport.yaml with the corresponding values to set service_type to NodePort. It looks like test coverage was missed when this was previously added. You'll also want to add a corresponding test case in helm/coder/tests/testdata/chart_test.go.
  • Update existing helm/coder/tests/testdata/*.golden with your current set of changes and review the output of helm template.

Tip: you can run go test ./helm/coder/tests -update to update the existing golden files without failing on a diff.

Hope that helps!

ok , i was already working on a test file sorry for the overlap. now i'll add the case you've mentioned.

@MRColorR
Copy link
Contributor Author

I've added the test cases as requested. Please let me know if there's anything else I should do.

@matifali matifali requested a review from johnstcn January 17, 2025 07:31
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual testing:

Ran kubectl apply on following files in a temporary namespace:

  • default_values.golden applied successfully:
NAME                         READY   STATUS    RESTARTS   AGE
pod/coder-7cc8f95b66-d2gcs   0/1     Running   0          3s

NAME            TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)        AGE
service/coder   LoadBalancer   10.101.182.44   192.168.1.34   80:31198/TCP   3s

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/coder   0/1     1            0           3s

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/coder-7cc8f95b66   1         1         0       3s
  • svc_loadbalancer.golden applied successfully:
NAME                         READY   STATUS    RESTARTS   AGE
pod/coder-7cc8f95b66-wtw9j   0/1     Running   0          5s

NAME            TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)        AGE
service/coder   LoadBalancer   10.104.167.126   192.168.1.34   80:30080/TCP   5s

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/coder   0/1     1            0           5s

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/coder-7cc8f95b66   1         1         0       5s
  • svc_loadbalancer_class.golden applied successfully:
NAME                         READY   STATUS    RESTARTS   AGE
pod/coder-7cc8f95b66-tq5ht   0/1     Running   0          3s

NAME            TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/coder   LoadBalancer   10.99.184.182   <pending>     80:32053/TCP   3s

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/coder   0/1     1            0           3s

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/coder-7cc8f95b66   1         1         0       3s
  • svc_nodeport.golden applied successfully:
NAME                         READY   STATUS    RESTARTS   AGE
pod/coder-7cc8f95b66-fnlg6   0/1     Running   0          6s

NAME            TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/coder   NodePort   10.111.126.236   <none>        80:30080/TCP   6s

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/coder   0/1     1            0           6s

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/coder-7cc8f95b66   1         1         0       6s

@johnstcn
Copy link
Member

@ericpaulsen OK to merge?

@ericpaulsen
Copy link
Member

ericpaulsen commented Jan 20, 2025

@johnstcn LGTM - pressing the big green button.

@ericpaulsen ericpaulsen merged commit d8fbbcb into coder:main Jan 20, 2025
30 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community Pull Requests and issues created by the community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants