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

[FEATURE] Add ability to specify nodePort #107

Open
Moep90 opened this issue Nov 9, 2021 · 0 comments
Open

[FEATURE] Add ability to specify nodePort #107

Moep90 opened this issue Nov 9, 2021 · 0 comments

Comments

@Moep90
Copy link
Contributor

Moep90 commented Nov 9, 2021

In my current usecase I want to add a service of type NodePort. Currently this is possible but without the ability to specify the nodePort itself.
So if I create a service of type NodePort I get a service with a (by kubernetes) randomly added NodePort between 30000-32767

Official docs:
https://kubernetes.io/docs/concepts/services-networking/service/#nodeport

Expected input:

  components:
    myapp:
[...]
      ports:
        my-service:
          service_port: 80
          container_port: 80
          node_port: 30007

expected outcome:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: myapp
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 80
      targetPort: 80
      # Optional field
      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
      nodePort: 30007

The old libsonnet generator has it:

nodePort: utils.objectGet(self.port_info, 'node_port'),

The new kadet generator doesn't honor the node_port

all_ports = [component.ports] + [container.ports for container in component.additional_containers.values()
if 'ports' in container]
exposed_ports = {}
for port in all_ports:
for port_name in port.keys():
if not service_spec.expose_ports or port_name in service_spec.expose_ports:
exposed_ports.update(port)
for port_name in sorted(exposed_ports):
port_spec = exposed_ports[port_name]
if 'service_port' in port_spec:
self.root.spec.ports += [{
'name': port_name,
'port': port_spec.service_port,
'targetPort': port_name,
'protocol': port_spec.get('protocol', 'TCP')
}]

So I exceeded my knowledge and time to solve this issue myself 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant