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 for NodePort in Jaeger Query Service #1394

Merged
merged 3 commits into from
Mar 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ type JaegerQuerySpec struct {
// See https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
ServiceType v1.ServiceType `json:"serviceType,omitempty"`

// +optional
// NodePort represents the port at which the NodePort service to allocate
NodePort int32 `json:"nodePort,omitempty"`

// +optional
// TracingEnabled if set to false adds the JAEGER_DISABLED environment flag and removes the injected
// agent container from the query component to disable tracing requests to the query service.
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 17 additions & 7 deletions pkg/service/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ func NewQueryService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Serv
annotations["service.alpha.openshift.io/serving-cert-secret-name"] = GetTLSSecretNameForQueryService(jaeger)
}

ports := []corev1.ServicePort{
{
Name: getPortNameForQueryService(jaeger),
Port: int32(GetPortForQueryService(jaeger)),
TargetPort: intstr.FromInt(getTargetPortForQueryService(jaeger)),
},
}
if jaeger.Spec.Query.ServiceType == corev1.ServiceTypeNodePort {
ports[0].NodePort = int32(GetNodePortForQueryService(jaeger))
}

return &corev1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
Expand All @@ -41,13 +52,7 @@ func NewQueryService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Serv
Spec: corev1.ServiceSpec{
Selector: selector,
Type: getTypeForQueryService(jaeger),
Ports: []corev1.ServicePort{
{
Name: getPortNameForQueryService(jaeger),
Port: int32(GetPortForQueryService(jaeger)),
TargetPort: intstr.FromInt(getTargetPortForQueryService(jaeger)),
},
},
Ports: ports,
},
}
}
Expand Down Expand Up @@ -90,3 +95,8 @@ func getTypeForQueryService(jaeger *v1.Jaeger) corev1.ServiceType {
}
return corev1.ServiceTypeClusterIP
}

// GetNodePortForQueryService returns the query service NodePort for this Jaeger instance
func GetNodePortForQueryService(jaeger *v1.Jaeger) int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this function is returning int instead of int32. When you use it you cast it again to int32
I would suggest to change this to:

func GetNodePortForQueryService(jaeger *v1.Jaeger) int32 {
	return jaeger.Spec.Query.NodePort
}

And ged rid of all int32(GetNodePortForQueryService(jaeger)) casts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi -
I set the function to return an int in lieu of an int32, for consistency with the getTargetPortForQueryService function. Let me make the change and update this MR 👍

return int(jaeger.Spec.Query.NodePort)
}
19 changes: 19 additions & 0 deletions pkg/service/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func TestQueryServiceNodePortWithIngress(t *testing.T) {
assert.Len(t, svc.Spec.Ports, 1)
assert.Equal(t, int32(16686), svc.Spec.Ports[0].Port)
assert.Equal(t, "http-query", svc.Spec.Ports[0].Name)
assert.Equal(t, int32(0), svc.Spec.Ports[0].NodePort)
rubenvp8510 marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, intstr.FromInt(16686), svc.Spec.Ports[0].TargetPort)
assert.Equal(t, svc.Spec.Type, corev1.ServiceTypeNodePort) // make sure we get a NodePort service
}
Expand All @@ -84,3 +85,21 @@ func TestQueryServiceLoadBalancerWithIngress(t *testing.T) {
assert.Equal(t, intstr.FromInt(16686), svc.Spec.Ports[0].TargetPort)
assert.Equal(t, svc.Spec.Type, corev1.ServiceTypeLoadBalancer) // make sure we get a LoadBalancer service
}

func TestQueryServiceSpecifiedNodePortWithIngress(t *testing.T) {
name := "TestQueryServiceSpecifiedNodePortWithIngress"
selector := map[string]string{"app": "myapp", "jaeger": name, "jaeger-component": "query"}

jaeger := v1.NewJaeger(types.NamespacedName{Name: name})
jaeger.Spec.Query.ServiceType = corev1.ServiceTypeNodePort
jaeger.Spec.Query.NodePort = 32767
svc := NewQueryService(jaeger, selector)

assert.Equal(t, "testqueryservicespecifiednodeportwithingress-query", svc.ObjectMeta.Name)
assert.Len(t, svc.Spec.Ports, 1)
assert.Equal(t, int32(16686), svc.Spec.Ports[0].Port)
rubenvp8510 marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, "http-query", svc.Spec.Ports[0].Name)
assert.Equal(t, int32(32767), svc.Spec.Ports[0].NodePort) // make sure we get the same NodePort as set above
rubenvp8510 marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, intstr.FromInt(16686), svc.Spec.Ports[0].TargetPort)
assert.Equal(t, svc.Spec.Type, corev1.ServiceTypeNodePort)
}