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

Add support to configure multiple service ports #316

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shivamerla
Copy link
Collaborator

  • Default named port of "api" will be added with legacy .spec.port attribute
  • Ability to setup multiple named ports "api", "metrics" etc.
  • auto detection of metrics and api ports for probes and metrics collection

 * Default named port of "api" will be added with legacy .spec.port attribute
 * Ability to setup multiple named ports "api", "metrics" etc.
 * auto detection of metrics and api ports for probes and metrics collection

Signed-off-by: Shiva Krishna, Merla <[email protected]>
Copy link

copy-pr-bot bot commented Feb 7, 2025

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@shivamerla shivamerla requested review from shengnuo and varunrsekar and removed request for ArangoGutierrez February 7, 2025 23:13
api/apps/v1alpha1/nemo_entitystore_types.go Outdated Show resolved Hide resolved
}

// getProbePort determines the appropriate port for probes based on the service spec.
func getProbePort(serviceSpec Service) intstr.IntOrString {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can probably use rendertypes.ServiceParams as input here and simplify this to always prefer "api" namedPort from the ServiceParams.Ports list

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Each resource is rendered independently during reconciliation. That will add a dependency that we always have to render serviceParams before setting up deployment or servicemonitor.

api/apps/v1alpha1/nemo_entitystore_types.go Outdated Show resolved Hide resolved
Type: intstr.Type(0),
IntVal: n.Spec.Expose.Service.Port,
},
Port: getProbePort(n.Spec.Expose.Service),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This implies that .spec.expose.service is required, but it is not currently.
Maybe we should make it a required field or add a default value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, we can make this as a required field, earlier there was just single port param and default for that, so it was always present.

api/apps/v1alpha1/nemo_datastore_types.go Show resolved Hide resolved
api/apps/v1alpha1/common_types.go Outdated Show resolved Hide resolved
api/apps/v1alpha1/nemo_evaluator_types.go Outdated Show resolved Hide resolved
Comment on lines 134 to 152
switch len(serviceSpec.Ports) {
case 1:
port := serviceSpec.Ports[0]
if port.Name != "" {
return intstr.FromString(port.Name)
}
return intstr.FromInt(int(port.Port))
case 0:
// Default to "api" as the operator always adds a default named port with 8000
return intstr.FromString("api")
default:
// Multiple ports: Prefer "api"
if portName := selectNamedPort(serviceSpec, "api"); portName != "" {
return intstr.FromString(portName)
}
// Default when multiple ports exist
return intstr.FromString("api")
}
}
Copy link
Collaborator

@varunrsekar varunrsekar Feb 12, 2025

Choose a reason for hiding this comment

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

case where length is 1 and default case where length > 1 should have similar behavior:

  • Prefer "api"
  • Otherwise, pick first port
    Isn't this the case? Defaulting to "api" when other options exist doesnt seem right to me.
Suggested change
switch len(serviceSpec.Ports) {
case 1:
port := serviceSpec.Ports[0]
if port.Name != "" {
return intstr.FromString(port.Name)
}
return intstr.FromInt(int(port.Port))
case 0:
// Default to "api" as the operator always adds a default named port with 8000
return intstr.FromString("api")
default:
// Multiple ports: Prefer "api"
if portName := selectNamedPort(serviceSpec, "api"); portName != "" {
return intstr.FromString(portName)
}
// Default when multiple ports exist
return intstr.FromString("api")
}
}
switch len(serviceSpec.Ports) {
case 0:
// Default to "api" as the operator always adds a default named port with 8000
return intstr.FromString("api")
default:
// Multiple ports: Prefer "api"
if portName := selectNamedPort(serviceSpec, "api"); portName != "" {
return intstr.FromString(portName)
}
// Default when multiple ports exist
port := serviceSpec.Ports[0]
if port.Name != "" {
return intstr.FromString(port.Name)
}
return intstr.FromInt(int(port.Port))
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We just can't assume to use the first port when multiple ports are given. For e.g. in case of Customizer, if "api" and "internal" ports are used with different names, we can't assume "internal" ports for liveness/startup probes etc. Hence i was always enforcing that a named port of "api" should be specified in that case. Probably better things is to validate this during reconciliation and error out when required named ports are not provided.

return intstr.FromString(portName)
}
// Default when multiple ports exist
return intstr.FromString("metrics")
Copy link
Collaborator

Choose a reason for hiding this comment

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

similarly here: Shouldn't we be getting the first port from the list if "metrics" and "api" dont exist?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same logic as above, in documentation we have to specify that named ports for "api" or "metrics" should be provided when they are served differently by the underlying service. Randomly assigning would not work.

expected intstr.IntOrString
}{
{"Single named port", Service{Ports: []corev1.ServicePort{{Name: "metrics", Port: 8081}}}, intstr.FromString("metrics")},
{"Single unnamed port", Service{Ports: []corev1.ServicePort{{Port: 8181}}}, intstr.FromInt(8181)},
Copy link
Collaborator

Choose a reason for hiding this comment

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

trying to understand the logic.. in this case, why it shouldn't produce api like the test case in L63?

Copy link
Collaborator Author

@shivamerla shivamerla Feb 13, 2025

Choose a reason for hiding this comment

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

when say user provides input as below:

  expose:
    service:
      type: ClusterIP
      ports:
        - port: 8000
           protocol: TCP

then, in the deployment spec, we don't add any named ports like "api". Hence we use the port number that is given to us. we will add a default named port ("api: 8000" ) when no ports are given in the config at all.

Signed-off-by: Shiva Krishna, Merla <[email protected]>
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 this pull request may close these issues.

4 participants