Skip to content

Commit

Permalink
Merge branch 'master' into grpc-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pavolloffay authored Jul 26, 2021
2 parents b34e311 + 25e9291 commit 9020585
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/deployment/all_in_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ func (a *AllInOne) Get() *appsv1.Deployment {

// Services returns a list of services to be deployed along with the all-in-one deployment
func (a *AllInOne) Services() []*corev1.Service {
labels := a.labels()
// merge defined labels with default labels
spec := util.Merge([]v1.JaegerCommonSpec{a.jaeger.Spec.AllInOne.JaegerCommonSpec, a.jaeger.Spec.JaegerCommonSpec, v1.JaegerCommonSpec{Labels: a.labels()}})
labels := spec.Labels

return append(service.NewCollectorServices(a.jaeger, labels),
service.NewQueryService(a.jaeger, labels),
service.NewAgentService(a.jaeger, labels),
Expand Down
36 changes: 36 additions & 0 deletions pkg/deployment/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,42 @@ func TestAllInOneLabels(t *testing.T) {
assert.Equal(t, "false", dep.Spec.Selector.MatchLabels["another"])
}

func TestAllInOneOverwrittenDefaultLabels(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestAllInOneOverwrittenDefaultLabels"})
jaeger.Spec.Labels = map[string]string{
"name": "operator",
"hello": "jaeger",
"app.kubernetes.io/name": "my-jaeger", // Override default labels
}
jaeger.Spec.AllInOne.Labels = map[string]string{
"hello": "world", // Override top level annotation
"another": "false",
}

allinone := NewAllInOne(jaeger)
dep := allinone.Get()

assert.Equal(t, "operator", dep.Spec.Template.Labels["name"])
assert.Equal(t, "world", dep.Spec.Template.Labels["hello"])
assert.Equal(t, "false", dep.Spec.Template.Labels["another"])
assert.Equal(t, "my-jaeger", dep.Spec.Template.Labels["app.kubernetes.io/name"])

// Deployment selectors should be the same as the template labels.
assert.Equal(t, "operator", dep.Spec.Selector.MatchLabels["name"])
assert.Equal(t, "world", dep.Spec.Selector.MatchLabels["hello"])
assert.Equal(t, "false", dep.Spec.Selector.MatchLabels["another"])
assert.Equal(t, "my-jaeger", dep.Spec.Selector.MatchLabels["app.kubernetes.io/name"])

// Service selectors should be the same as the template labels.
services := allinone.Services()
for _, svc := range services {
assert.Equal(t, "operator", svc.Spec.Selector["name"])
assert.Equal(t, "world", svc.Spec.Selector["hello"])
assert.Equal(t, "false", svc.Spec.Selector["another"])
assert.Equal(t, "my-jaeger", svc.Spec.Selector["app.kubernetes.io/name"])
}
}

func TestAllInOneHasOwner(t *testing.T) {
name := "TestAllInOneHasOwner"
a := NewAllInOne(v1.NewJaeger(types.NamespacedName{Name: name}))
Expand Down
16 changes: 16 additions & 0 deletions pkg/strategy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ func normalize(ctx context.Context, jaeger *v1.Jaeger) {
jaeger.Spec.Storage.Type = v1.JaegerMemoryStorage
}

// remove reserved labels
for _, labels := range []map[string]string{
jaeger.Spec.JaegerCommonSpec.Labels,
jaeger.Spec.AllInOne.JaegerCommonSpec.Labels,
jaeger.Spec.Query.JaegerCommonSpec.Labels,
} {
if _, ok := labels["app.kubernetes.io/instance"]; ok {
span.AddEvent(fmt.Sprintf("the reserved label 'app.kubernetes.io/instance' is overwritten, falling back to %s", jaeger.Name))
delete(labels, "app.kubernetes.io/instance")
}
if _, ok := labels["app.kubernetes.io/managed-by"]; ok {
span.AddEvent("the reserved label 'app.kubernetes.io/managed-by' is overwritten, falling back to jaeger-operator")
delete(labels, "app.kubernetes.io/managed-by")
}
}

// normalize the deployment strategy
if jaeger.Spec.Strategy != v1.DeploymentStrategyProduction && jaeger.Spec.Strategy != v1.DeploymentStrategyStreaming {
jaeger.Spec.Strategy = v1.DeploymentStrategyAllInOne
Expand Down
13 changes: 13 additions & 0 deletions pkg/strategy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ func TestAcceptExplicitValueFromSecurityWhenOnOpenShift(t *testing.T) {
assert.Equal(t, v1.IngressSecurityNoneExplicit, jaeger.Spec.Ingress.Security)
}

func TestRemoveReservedLabels(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestRemoveReservedLabels"})
jaeger.Spec.Labels = map[string]string{
"app.kubernetes.io/instance": "custom-instance",
"app.kubernetes.io/managed-by": "custom-managed-by",
}

normalize(context.Background(), jaeger)

assert.NotContains(t, jaeger.Spec.Labels, "app.kubernetes.io/instance")
assert.NotContains(t, jaeger.Spec.Labels, "app.kubernetes.io/managed-by")
}

func TestNormalizeIndexCleaner(t *testing.T) {
trueVar := true
falseVar := false
Expand Down

0 comments on commit 9020585

Please sign in to comment.