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 link to openshift console #1142

Merged
merged 12 commits into from
Aug 4, 2020
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PROMETHEUS_OPERATOR_TAG ?= v0.39.0
PROMETHEUS_RULES_CRD ?= https://raw.githubusercontent.com/coreos/prometheus-operator/${PROMETHEUS_OPERATOR_TAG}/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml
PROMETHEUS_SERVICE_MONITORS_CRD ?= https://raw.githubusercontent.com/coreos/prometheus-operator/${PROMETHEUS_OPERATOR_TAG}/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
ES_OPERATOR_IMAGE ?= quay.io/openshift/origin-elasticsearch-operator:4.4
SDK_VERSION=v0.15.1
SDK_VERSION=v0.18.2
GOPATH ?= "$(HOME)/go"

LD_FLAGS ?= "-X $(VERSION_PKG).version=$(OPERATOR_VERSION) -X $(VERSION_PKG).buildDate=$(VERSION_DATE) -X $(VERSION_PKG).defaultJaeger=$(JAEGER_VERSION)"
Expand Down
10 changes: 6 additions & 4 deletions pkg/consolelink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// RouteAnnotation used to annotate the link with the route name
var RouteAnnotation = "consolelink.jaegertracing.io/route"

// Get returns an ConsoleLink specification for the current instance
// Get returns a ConsoleLink specification for the current instance
func Get(jaeger *v1.Jaeger, route *routev1.Route) *consolev1.ConsoleLink {
// If ingress is not enable there is no reason for create a console link
if jaeger.Spec.Ingress.Enabled != nil && *jaeger.Spec.Ingress.Enabled == false {
Expand All @@ -22,10 +22,12 @@ func Get(jaeger *v1.Jaeger, route *routev1.Route) *consolev1.ConsoleLink {

return &consolev1.ConsoleLink{
ObjectMeta: metav1.ObjectMeta{
Name: jaeger.Namespace + ".jaeger-consolelink-" + jaeger.Name,
Namespace: jaeger.Namespace,
Name: "jaeger-" + jaeger.Namespace + "-" + jaeger.Name,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could you create a function to derive the name from the jaeger instance? and then also use from the tests (main_test, but also the various strategy tests).

Namespace: jaeger.Namespace, // Prevent warning at creation time.
Labels: map[string]string{
"app.kubernetes.io/instance": jaeger.Name,
"app.kubernetes.io/instance": jaeger.Name,
// Allow distinction between same jaeger instances in different namespaces
"app.kubernetes.io/namespace": jaeger.Namespace,
"app.kubernetes.io/managed-by": "jaeger-operator",
},
Annotations: map[string]string{
Expand Down
6 changes: 3 additions & 3 deletions pkg/consolelink/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ func TestConsoleLinkGet(t *testing.T) {
}

link := Get(jaeger, route)
assert.Equal(t, jaeger.Namespace+".jaeger-consolelink-"+jaeger.Name, link.Name)
assert.Equal(t, "jaeger-"+jaeger.Namespace+"-"+jaeger.Name, link.Name)
assert.Contains(t, link.Annotations, RouteAnnotation)
assert.Equal(t, routerNamer, link.Annotations[RouteAnnotation])
}

func TestUpdateHref(t *testing.T) {
jaegerName := "TestConsoleLinkJaeger"
jaegerNamespace := "TestNS"
routerNamer := "TestConsoleLinkRoute"
routerName := "TestConsoleLinkRoute"
jaeger := v1.NewJaeger(types.NamespacedName{Name: jaegerName, Namespace: jaegerNamespace})
route := corev1.Route{
TypeMeta: metav1.TypeMeta{
Kind: "Route",
APIVersion: "route.openshift.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: routerNamer,
Name: routerName,
},
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/controller/jaeger/consolelink.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

osconsolev1 "github.com/openshift/api/console/v1"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"go.opentelemetry.io/otel/global"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -18,10 +19,15 @@ func (r *ReconcileJaeger) applyConsoleLinks(ctx context.Context, jaeger v1.Jaege
ctx, span := tracer.Start(ctx, "applyConsoleLinks")
defer span.End()

if viper.GetString(v1.ConfigOperatorScope) != v1.OperatorScopeCluster {
jaeger.Logger().Trace("console link skipped, operator isn't cluster-wide")
return nil
}

opts := []client.ListOption{
client.InNamespace(jaeger.Namespace),
client.MatchingLabels(map[string]string{
"app.kubernetes.io/instance": jaeger.Name,
"app.kubernetes.io/namespace": jaeger.Namespace,
"app.kubernetes.io/managed-by": "jaeger-operator",
}),
}
Expand Down
67 changes: 67 additions & 0 deletions pkg/controller/jaeger/consolelink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"testing"

"k8s.io/apimachinery/pkg/api/errors"

v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
"github.com/jaegertracing/jaeger-operator/pkg/consolelink"

Expand All @@ -26,6 +28,7 @@ func TestConsoleLinkCreate(t *testing.T) {
Name: "my-instance",
}
viper.Set("platform", "openshift")
rubenvp8510 marked this conversation as resolved.
Show resolved Hide resolved
viper.Set(v1.ConfigOperatorScope, v1.OperatorScopeCluster)
defer viper.Reset()

objs := []runtime.Object{
Expand Down Expand Up @@ -81,13 +84,15 @@ func TestConsoleLinkUpdate(t *testing.T) {
Name: "my-instance",
}
viper.Set("platform", "openshift")
rubenvp8510 marked this conversation as resolved.
Show resolved Hide resolved
viper.Set(v1.ConfigOperatorScope, v1.OperatorScopeCluster)
defer viper.Reset()

orig := osconsolev1.ConsoleLink{}
orig.Name = nsn.Name
orig.Annotations = map[string]string{"key": "value"}
orig.Labels = map[string]string{
"app.kubernetes.io/instance": orig.Name,
"app.kubernetes.io/namespace": orig.Namespace,
"app.kubernetes.io/managed-by": "jaeger-operator",
}

Expand Down Expand Up @@ -137,12 +142,14 @@ func TestConsoleLinkDelete(t *testing.T) {
Name: "my-instance",
}
viper.Set("platform", "openshift")
rubenvp8510 marked this conversation as resolved.
Show resolved Hide resolved
viper.Set(v1.ConfigOperatorScope, v1.OperatorScopeCluster)
defer viper.Reset()

orig := osconsolev1.ConsoleLink{}
orig.Name = nsn.Name
orig.Labels = map[string]string{
"app.kubernetes.io/instance": orig.Name,
"app.kubernetes.io/namespace": orig.Namespace,
"app.kubernetes.io/managed-by": "jaeger-operator",
}

Expand Down Expand Up @@ -182,6 +189,8 @@ func TestConsoleLinksCreateExistingNameInAnotherNamespace(t *testing.T) {
Namespace: "tenant2",
}
viper.Set("platform", "openshift")
rubenvp8510 marked this conversation as resolved.
Show resolved Hide resolved
viper.Set(v1.ConfigOperatorScope, v1.OperatorScopeCluster)

defer viper.Reset()

objs := []runtime.Object{
Expand Down Expand Up @@ -260,3 +269,61 @@ func TestConsoleLinksCreateExistingNameInAnotherNamespace(t *testing.T) {
assert.Equal(t, "https://host1", persistedExisting.Spec.Href)

}

func TestConsoleLinksSkipped(t *testing.T) {
namespace := "observability"
viper.Set("platform", "openshift")
viper.Set(v1.ConfigOperatorScope, v1.OperatorScopeNamespace)
viper.Set(v1.ConfigWatchNamespace, namespace)
defer viper.Reset()

nsn := types.NamespacedName{
Name: "my-instance",
Namespace: namespace,
}

objs := []runtime.Object{
v1.NewJaeger(nsn),
}

req := reconcile.Request{
NamespacedName: nsn,
}

r, cl := getReconciler(objs)
r.strategyChooser = func(ctx context.Context, jaeger *v1.Jaeger) strategy.S {
s := strategy.New().WithConsoleLinks([]osconsolev1.ConsoleLink{{
ObjectMeta: metav1.ObjectMeta{
Name: nsn.Name,
Namespace: nsn.Namespace,
Annotations: map[string]string{
consolelink.RouteAnnotation: "my-route-1",
},
},
}}).WithRoutes([]osroutev1.Route{{
ObjectMeta: metav1.ObjectMeta{
Name: "my-route-1",
Namespace: nsn.Namespace,
},
Spec: osroutev1.RouteSpec{
Host: "host",
},
}})
return s
}

// test
res, err := r.Reconcile(req)

// verify
assert.NoError(t, err)
assert.False(t, res.Requeue, "We don't requeue for now")

persisted := &osconsolev1.ConsoleLink{}
persistedName := types.NamespacedName{
Name: nsn.Name,
Namespace: nsn.Namespace,
}
err = cl.Get(context.Background(), persistedName, persisted)
assert.Equal(t, metav1.StatusReasonNotFound, errors.ReasonForError(err))
}
4 changes: 2 additions & 2 deletions pkg/controller/jaeger/jaeger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ func (r *ReconcileJaeger) apply(ctx context.Context, jaeger v1.Jaeger, str strat
return jaeger, tracing.HandleError(err, span)
}
routes := osv1.RouteList{}
err = r.rClient.List(ctx, &routes)
err = r.rClient.List(ctx, &routes, client.InNamespace(jaeger.Namespace))
if err == nil {
if err := r.applyConsoleLinks(ctx, jaeger, str.ConsoleLinks(routes.Items)); err != nil {
jaeger.Logger().WithError(tracing.HandleError(err, span)).Warn("failed to reconcile console links")
}
} else {
jaeger.Logger().WithError(tracing.HandleError(err, span)).Warn("failed to reconcile console links")
jaeger.Logger().WithError(tracing.HandleError(err, span)).Warn("failed to obtain a list of routes to reconcile consolelinks")
}
} else {
if err := r.applyIngresses(ctx, jaeger, str.Ingresses()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategy/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func assertDeploymentsAndServicesForAllInOne(t *testing.T, name string, s S, has
consoleLinks := map[string]bool{}
if viper.GetString("platform") == v1.FlagPlatformOpenShift {
routes[fmt.Sprintf("%s", util.DNSName(name))] = false
consoleLinks[".jaeger-consolelink-"+name] = false
consoleLinks["jaeger--"+name] = false

} else {
ingresses[fmt.Sprintf("%s-query", name)] = false
Expand Down
2 changes: 1 addition & 1 deletion pkg/strategy/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func assertDeploymentsAndServicesForProduction(t *testing.T, name string, s S, h
consoleLinks := map[string]bool{}
if viper.GetString("platform") == v1.FlagPlatformOpenShift {
routes[util.DNSName(name)] = false
consoleLinks[".jaeger-consolelink-"+name] = false
consoleLinks["jaeger--"+name] = false
} else {
ingresses[fmt.Sprintf("%s-query", name)] = false
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/strategy/streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

func init() {
viper.SetDefault("jaeger-agent-image", "jaegertracing/jaeger-agent")

}

func TestCreateStreamingDeployment(t *testing.T) {
Expand Down Expand Up @@ -205,7 +206,7 @@ func assertDeploymentsAndServicesForStreaming(t *testing.T, name string, s S, ha
consoleLinks := map[string]bool{}
if viper.GetString("platform") == v1.FlagPlatformOpenShift {
routes[name] = false
consoleLinks[".jaeger-consolelink-"+name] = false
consoleLinks["jaeger--"+name] = false
} else {
ingresses[fmt.Sprintf("%s-query", name)] = false
}
Expand Down