Skip to content

Commit

Permalink
Support injection of JAEGER_SERVICE_NAME based on app or k8s recommen…
Browse files Browse the repository at this point in the history
…ded labels (#362)

Signed-off-by: Gary Brown <[email protected]>
  • Loading branch information
objectiser authored and jpkrohling committed Apr 5, 2019
1 parent 7f314b5 commit 922d562
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/inject/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ func container(jaeger *v1.Jaeger) corev1.Container {
}

func decorate(dep *appsv1.Deployment) {
if app, found := dep.Spec.Template.Labels["app"]; found {
app, found := dep.Spec.Template.Labels["app.kubernetes.io/instance"]
if !found {
app, found = dep.Spec.Template.Labels["app.kubernetes.io/name"]
}
if !found {
app, found = dep.Spec.Template.Labels["app"]
}
if found {
// Append the namespace to the app name. Using the DNS style "<app>.<namespace>""
// which also matches with the style used in Istio.
if len(dep.Namespace) > 0 {
Expand Down
27 changes: 27 additions & 0 deletions pkg/inject/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ func TestInjectSidecarWithEnvVars(t *testing.T) {
assert.Equal(t, "jaeger,b3", dep.Spec.Template.Spec.Containers[0].Env[1].Value)
}

func TestInjectSidecarWithEnvVarsK8sAppName(t *testing.T) {
jaeger := v1.NewJaeger("TestInjectSidecarWithEnvVarsK8sAppName")
dep := dep(map[string]string{Annotation: jaeger.Name}, map[string]string{
"app": "noapp",
"app.kubernetes.io/name": "testapp",
})
dep = Sidecar(jaeger, dep)
assert.Len(t, dep.Spec.Template.Spec.Containers, 2)
assert.Len(t, dep.Spec.Template.Spec.Containers[0].Env, 2)
assert.Equal(t, envVarServiceName, dep.Spec.Template.Spec.Containers[0].Env[0].Name)
assert.Equal(t, "testapp.default", dep.Spec.Template.Spec.Containers[0].Env[0].Value)
}

func TestInjectSidecarWithEnvVarsK8sAppInstance(t *testing.T) {
jaeger := v1.NewJaeger("TestInjectSidecarWithEnvVarsK8sAppInstance")
dep := dep(map[string]string{Annotation: jaeger.Name}, map[string]string{
"app": "noapp",
"app.kubernetes.io/name": "noname",
"app.kubernetes.io/instance": "testapp",
})
dep = Sidecar(jaeger, dep)
assert.Len(t, dep.Spec.Template.Spec.Containers, 2)
assert.Len(t, dep.Spec.Template.Spec.Containers[0].Env, 2)
assert.Equal(t, envVarServiceName, dep.Spec.Template.Spec.Containers[0].Env[0].Name)
assert.Equal(t, "testapp.default", dep.Spec.Template.Spec.Containers[0].Env[0].Value)
}

func TestInjectSidecarWithEnvVarsWithNamespace(t *testing.T) {
jaeger := v1.NewJaeger("TestInjectSidecarWithEnvVarsWithNamespace")
dep := dep(map[string]string{Annotation: jaeger.Name}, map[string]string{"app": "testapp"})
Expand Down

0 comments on commit 922d562

Please sign in to comment.