Skip to content

Commit

Permalink
add serviceType for the collector service (#1286)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schneider <[email protected]>
  • Loading branch information
sschne authored Nov 11, 2020
1 parent 1c1e75d commit 37135a4
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 2 deletions.
2 changes: 2 additions & 0 deletions deploy/crds/jaegertracing.io_jaegers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2662,6 +2662,8 @@ spec:
type: object
serviceAccount:
type: string
serviceType:
type: string
tolerations:
items:
properties:
Expand Down
9 changes: 9 additions & 0 deletions examples/service-types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: jaegertracing.io/v1
kind: Jaeger
metadata:
name: service-types
spec:
query:
serviceType: LoadBalancer
collector:
serviceType: LoadBalancer
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -1582,4 +1583,4 @@ sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
sourcegraph.com/sqs/pbtypes v1.0.0/go.mod h1:3AciMUv4qUuRHRHhOG4TZOB+72GdPVz5k+c648qsFS4=
sourcegraph.com/sqs/pbtypes v1.0.0/go.mod h1:3AciMUv4qUuRHRHhOG4TZOB+72GdPVz5k+c648qsFS4=
7 changes: 7 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ type JaegerCollectorSpec struct {

// +optional
Config FreeForm `json:"config,omitempty"`

// +optional
// ServiceType represents the type of Service to create.
// Valid values include: ClusterIP, NodePort, LoadBalancer, and ExternalName.
// The default, if omitted, is ClusterIP.
// See https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
ServiceType v1.ServiceType `json:"serviceType,omitempty"`
}

// JaegerIngesterSpec defines the options to be used when deploying the ingester
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.

11 changes: 10 additions & 1 deletion pkg/service/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func headlessCollectorService(jaeger *v1.Jaeger, selector map[string]string) *co
}

func clusteripCollectorService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Service {
return collectorService(jaeger, selector)
svc := collectorService(jaeger, selector)
svc.Spec.Type = getTypeForCollectorService(jaeger)
return svc
}

func collectorService(jaeger *v1.Jaeger, selector map[string]string) *corev1.Service {
Expand Down Expand Up @@ -121,3 +123,10 @@ func GetPortNameForGRPC(jaeger *v1.Jaeger) string {
// doesn't look like we have TLS enabled
return "http-grpc"
}

func getTypeForCollectorService(jaeger *v1.Jaeger) corev1.ServiceType {
if jaeger.Spec.Collector.ServiceType != "" {
return jaeger.Spec.Collector.ServiceType
}
return corev1.ServiceTypeClusterIP
}
13 changes: 13 additions & 0 deletions pkg/service/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
Expand Down Expand Up @@ -130,3 +131,15 @@ func TestCollectorGRPCPortName(t *testing.T) {
})
}
}

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

jaeger := v1.NewJaeger(types.NamespacedName{Name: name})
jaeger.Spec.Collector.ServiceType = corev1.ServiceTypeLoadBalancer
svc := NewCollectorServices(jaeger, selector)

// Only the non-headless service will receive the type
assert.Equal(t, svc[1].Spec.Type, corev1.ServiceTypeLoadBalancer)
}
22 changes: 22 additions & 0 deletions test/e2e/examples2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
package e2e

import (
"context"
"fmt"
"testing"

"github.com/sirupsen/logrus"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

framework "github.com/operator-framework/operator-sdk/pkg/test"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -63,6 +66,25 @@ func (suite *ExamplesTestSuite2) TestWithBadgerAndVolumeExample() {
smokeTestAllInOneExample("with-badger-and-volume", "../../examples/with-badger-and-volume.yaml")
}

func (suite *ExamplesTestSuite2) TestServiceTypesExample() {
yamlFileName := "../../examples/service-types.yaml"
name := "service-types"
jaegerInstance := createJaegerInstanceFromFile(name, yamlFileName)
defer undeployJaegerInstance(jaegerInstance)

err := WaitForDeployment(t, fw.KubeClient, namespace, name, 1, retryInterval, timeout)
require.NoErrorf(t, err, "Error waiting for %s to deploy", name)

AllInOneSmokeTest(name)

collectorService, err := fw.KubeClient.CoreV1().Services(namespace).Get(context.Background(), fmt.Sprintf("%s-collector", name), v1.GetOptions{})
require.NoError(t, err)
require.Equal(t, "LoadBalancer", string(collectorService.Spec.Type))
queryService, err := fw.KubeClient.CoreV1().Services(namespace).Get(context.Background(), fmt.Sprintf("%s-query", name), v1.GetOptions{})
require.NoError(t, err)
require.Equal(t, "LoadBalancer", string(queryService.Spec.Type))
}

func (suite *ExamplesTestSuite2) TestSimpleProdWithVolumes() {
yamlFileName := "../../examples/simple-prod-with-volumes.yaml"
smokeTestProductionExample("simple-prod", yamlFileName)
Expand Down

0 comments on commit 37135a4

Please sign in to comment.