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

Try to resolve container.name from the injected agent args #1319

Merged
merged 11 commits into from
Dec 1, 2020
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-openapi/spec v0.19.8
github.com/googleapis/gnostic v0.3.1
github.com/miekg/dns v1.1.35 // indirect
Copy link
Contributor

Choose a reason for hiding this comment

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

What's up with the changes to go.mod and go.sum ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have reverted all changes to go.mod and go.sum. But may be this is an indirect dependency, so it will be cleaned by go mod tidy?

Copy link
Contributor

Choose a reason for hiding this comment

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

Might be. Once this gets merged, would you like to run a go mod tidy against master and seeing if there are differences in the go.mod?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I would like to have a try.

github.com/mitchellh/go-homedir v1.1.0
github.com/openshift/api v0.0.0-20200701144905-de5b010b2b38
github.com/operator-framework/operator-sdk v0.18.2
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ github.com/gophercloud/gophercloud v0.3.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEo
github.com/gophercloud/gophercloud v0.6.0 h1:Xb2lcqZtml1XjgYZxbeayEemq7ASbeTp09m36gQFpEU=
github.com/gophercloud/gophercloud v0.6.0/go.mod h1:GICNByuaEBibcjmjvI7QvYJSZEbGkcYwAR7EZK2WMqM=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de h1:F7WD09S8QB4LrkEpka0dFPLSotH11HRpCsLIbIcJ7sU=
github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/handlers v0.0.0-20150720190736-60c7bfde3e33 h1:893HsJqtxp9z1SF76gg6hY70hRY1wVlTSnC/h1yUDCo=
Expand Down Expand Up @@ -627,6 +628,7 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
github.com/jsonnet-bundler/jsonnet-bundler v0.3.1/go.mod h1:/by7P/OoohkI3q4CgSFqcoFsVY+IaNbzOVDknEsKDeU=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
Expand Down Expand Up @@ -709,8 +711,6 @@ github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88J
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miekg/dns v1.1.22/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.35 h1:oTfOaDH+mZkdcgdIjH6yBajRGtIwcwcaR+rt23ZSrJs=
github.com/miekg/dns v1.1.35/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/mikefarah/yaml/v2 v2.4.0/go.mod h1:ahVqZF4n1W4NqwvVnZzC4es67xsW9uR/RRf2RRxieJU=
github.com/mikefarah/yq/v2 v2.4.1/go.mod h1:i8SYf1XdgUvY2OFwSqGAtWOOgimD2McJ6iutoxRm4k0=
github.com/minio/minio-go/v6 v6.0.49/go.mod h1:qD0lajrGW49lKZLtXKtCB4X/qkMf0a5tBvN2PaZg7Gg=
Expand Down Expand Up @@ -754,6 +754,7 @@ github.com/nakagami/firebirdsql v0.0.0-20190310045651-3c02a58cfed8/go.mod h1:86w
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d h1:AREM5mwr4u1ORQBMvzfzBgpsctsbQikCVpvC+tX285E=
github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96djdrsSGy3AWPyBgZMAGfxZNfgntdJG+11KU4QvbU=
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v0.0.0-20170117200651-66bb6560562f/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand All @@ -772,6 +773,7 @@ github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
github.com/onsi/ginkgo v1.12.1 h1:mFwc4LvZ0xpSvDZ3E+k8Yte0hLOMxXUlP+yXtJqkYfQ=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v0.0.0-20190113212917-5533ce8a0da3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
Expand Down Expand Up @@ -955,8 +957,10 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w=
github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.3/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down Expand Up @@ -1329,7 +1333,6 @@ golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200115044656-831fdb1e1868/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b h1:AFZdJUT7jJYXQEC29hYH/WZkoV7+KhwxQGmdZ19yYoY=
golang.org/x/tools v0.0.0-20200403190813-44a64ad78b9b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
Expand Down Expand Up @@ -1400,8 +1403,6 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.30.0 h1:M5a8xTlYTxwMn5ZFkwhRabsygDY5G8TYLyQDBxJNAxE=
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.32.0 h1:zWTV+LMdc3kaiJMSTOFz2UgSBgx8RNQoTGiZu3fR9S0=
google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand Down
65 changes: 48 additions & 17 deletions pkg/inject/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ func Sidecar(jaeger *v1.Jaeger, dep *appsv1.Deployment) *appsv1.Deployment {
hasAgent, agentContainerIndex := HasJaegerAgent(dep)
logFields.Debug("injecting sidecar")
if hasAgent { // This is an update
dep.Spec.Template.Spec.Containers[agentContainerIndex] = container(jaeger, dep)
dep.Spec.Template.Spec.Containers[agentContainerIndex] = container(jaeger, dep, agentContainerIndex)
} else {
dep.Spec.Template.Spec.Containers = append(dep.Spec.Template.Spec.Containers, container(jaeger, dep))

dep.Spec.Template.Spec.Containers = append(dep.Spec.Template.Spec.Containers, container(jaeger, dep, -1))
}

jaegerName := util.Truncate(jaeger.Name, 63)
Expand Down Expand Up @@ -164,7 +163,7 @@ func getJaeger(name string, jaegers *v1.JaegerList) *v1.Jaeger {
return nil
}

func container(jaeger *v1.Jaeger, dep *appsv1.Deployment) corev1.Container {
func container(jaeger *v1.Jaeger, dep *appsv1.Deployment, agentIdx int) corev1.Container {
args := append(jaeger.Spec.Agent.Options.ToArgs())

// we only add the grpc host if we are adding the reporter type and there's no explicit value yet
Expand All @@ -187,21 +186,29 @@ func container(jaeger *v1.Jaeger, dep *appsv1.Deployment) corev1.Container {
adminPort := util.GetAdminPort(args, 14271)

if len(util.FindItem("--jaeger.tags=", args)) == 0 {
agentTags := fmt.Sprintf("%s=%s,%s=%s,%s=%s,%s=%s,%s=%s",
"cluster", "undefined", // this value isn't currently available
"deployment.name", dep.Name,
"pod.namespace", dep.Namespace,
"pod.name", fmt.Sprintf("${%s:}", envVarPodName),
"host.ip", fmt.Sprintf("${%s:}", envVarHostIP),
)

if len(dep.Spec.Template.Spec.Containers) == 1 {
agentTags = fmt.Sprintf("%s,%s=%s", agentTags,
"container.name", dep.Spec.Template.Spec.Containers[0].Name,
)
defaultAgentTagsMap := make(map[string]string)
defaultAgentTagsMap["cluster"] = "undefined" // this value isn't currently available
defaultAgentTagsMap["deployment.name"] = dep.Name
defaultAgentTagsMap["pod.namespace"] = dep.Namespace
defaultAgentTagsMap["pod.name"] = fmt.Sprintf("${%s:}", envVarPodName)
defaultAgentTagsMap["host.ip"] = fmt.Sprintf("${%s:}", envVarHostIP)

if (agentIdx == -1 && len(dep.Spec.Template.Spec.Containers) == 1) || // if jaeger-agent does not exist, check if len of containers is one
(agentIdx > -1 && len(dep.Spec.Template.Spec.Containers)-1 == 1) { // otherwise check if len of containers is one with jaeger-agent filtered out
defaultAgentTagsMap["container.name"] = dep.Spec.Template.Spec.Containers[0].Name
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
}

if agentIdx > -1 {
existingAgentTags := parseAgentTags(dep.Spec.Template.Spec.Containers[agentIdx].Args)
// merge two maps
for key, value := range defaultAgentTagsMap {
existingAgentTags[key] = value
}
args = append(args, fmt.Sprintf(`--jaeger.tags=%s`, joinTags(existingAgentTags)))
} else {
args = append(args, fmt.Sprintf(`--jaeger.tags=%s`, joinTags(defaultAgentTagsMap)))
}

args = append(args, fmt.Sprintf(`--jaeger.tags=%s`, agentTags))
}

commonSpec := util.Merge([]v1.JaegerCommonSpec{jaeger.Spec.Agent.JaegerCommonSpec, jaeger.Spec.JaegerCommonSpec})
Expand Down Expand Up @@ -378,3 +385,27 @@ func EqualSidecar(dep, oldDep *appsv1.Deployment) bool {
oldDepContainer := oldDep.Spec.Template.Spec.Containers[oldDepIndex]
return reflect.DeepEqual(depContainer, oldDepContainer)
}

func parseAgentTags(args []string) map[string]string {
tagsArg := util.FindItem("--jaeger.tags=", args)
if tagsArg == "" {
return map[string]string{}
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
}
tagsParam := strings.SplitN(tagsArg, "=", 2)[1]
tagsMap := make(map[string]string)
tagsArr := strings.Split(tagsParam, ",")
for _, tagsPairStr := range tagsArr {
tagsPair := strings.SplitN(tagsPairStr, "=", 2)
tagsMap[tagsPair[0]] = tagsPair[1]
}
return tagsMap
}

func joinTags(tags map[string]string) string {
tagsSlice := make([]string, 0)
for key, value := range tags {
tagsSlice = append(tagsSlice, fmt.Sprintf("%s=%s", key, value))
}
sort.Strings(tagsSlice)
return strings.Join(tagsSlice, ",")
}
85 changes: 68 additions & 17 deletions pkg/inject/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package inject

import (
"fmt"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -508,8 +509,9 @@ func TestSidecarOrderOfArguments(t *testing.T) {
containsOptionWithPrefix(t, dep.Spec.Template.Spec.Containers[1].Args, "--c-option")
containsOptionWithPrefix(t, dep.Spec.Template.Spec.Containers[1].Args, "--jaeger.tags")
containsOptionWithPrefix(t, dep.Spec.Template.Spec.Containers[1].Args, "--reporter.grpc.host-port")
agentTags := agentTags(dep.Spec.Template.Spec.Containers[1].Args)
assert.Contains(t, agentTags, "container.name=only_container")
agentTagsMap := parseAgentTags(dep.Spec.Template.Spec.Containers[1].Args)
assert.Contains(t, agentTagsMap, "container.name")
assert.Equal(t, agentTagsMap["container.name"], "only_container")
Copy link
Contributor

Choose a reason for hiding this comment

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

If you are changing this PR for some other reason, you might want to remove the Contains, as the Equals assertion already covers it.

Copy link
Contributor Author

@lujiajing1126 lujiajing1126 Dec 1, 2020

Choose a reason for hiding this comment

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

Yes, you're right. Unnecessary Contains Removed. Also fix the same issue in two other places.

}

func TestSidecarExplicitTags(t *testing.T) {
Expand All @@ -523,8 +525,8 @@ func TestSidecarExplicitTags(t *testing.T) {

// verify
assert.Len(t, dep.Spec.Template.Spec.Containers, 2)
agentTags := agentTags(dep.Spec.Template.Spec.Containers[1].Args)
assert.Equal(t, []string{"key=val"}, agentTags)
agentTags := parseAgentTags(dep.Spec.Template.Spec.Containers[1].Args)
assert.True(t, reflect.DeepEqual(agentTags, map[string]string{"key": "val"}))
jpkrohling marked this conversation as resolved.
Show resolved Hide resolved
}

func TestSidecarCustomReporterPort(t *testing.T) {
Expand Down Expand Up @@ -671,8 +673,31 @@ func TestSidecarAgentTagsWithMultipleContainers(t *testing.T) {
assert.Len(t, dep.Spec.Template.Spec.Containers, 3, "Expected 3 containers")
assert.Equal(t, "jaeger-agent", dep.Spec.Template.Spec.Containers[2].Name)
containsOptionWithPrefix(t, dep.Spec.Template.Spec.Containers[2].Args, "--jaeger.tags")
agentTags := agentTags(dep.Spec.Template.Spec.Containers[2].Args)
assert.Equal(t, "", util.FindItem("container.name=", agentTags))
agentTagsMap := parseAgentTags(dep.Spec.Template.Spec.Containers[2].Args)
assert.NotContains(t, agentTagsMap, "container.name")
}

func TestSidecarAgentContainerNameTagWithDoubleInjectedContainer(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
dep := Sidecar(jaeger, dep(map[string]string{}, map[string]string{}))

// inject - 1st time
assert.Equal(t, dep.Labels[Label], jaeger.Name)
assert.Len(t, dep.Spec.Template.Spec.Containers, 2, "Expected 2 containers")
assert.Equal(t, "jaeger-agent", dep.Spec.Template.Spec.Containers[1].Name)
containsOptionWithPrefix(t, dep.Spec.Template.Spec.Containers[1].Args, "--jaeger.tags")
agentTagsMap := parseAgentTags(dep.Spec.Template.Spec.Containers[1].Args)
assert.Contains(t, agentTagsMap, "container.name")
assert.Equal(t, agentTagsMap["container.name"], "only_container")

// inject - 2nd time due to deployment/namespace reconciliation
dep = Sidecar(jaeger, dep)
assert.Len(t, dep.Spec.Template.Spec.Containers, 2, "Expected 2 containers")
assert.Equal(t, "jaeger-agent", dep.Spec.Template.Spec.Containers[1].Name)
containsOptionWithPrefix(t, dep.Spec.Template.Spec.Containers[1].Args, "--jaeger.tags")
agentTagsMap = parseAgentTags(dep.Spec.Template.Spec.Containers[1].Args)
assert.Contains(t, agentTagsMap, "container.name")
assert.Equal(t, agentTagsMap["container.name"], "only_container")
}

func ns(annotations map[string]string) *corev1.Namespace {
Expand Down Expand Up @@ -734,15 +759,6 @@ func containsOptionWithPrefix(t *testing.T, args []string, prefix string) bool {
return false
}

func agentTags(args []string) []string {
tagsArg := util.FindItem("--jaeger.tags=", args)
if tagsArg == "" {
return []string{}
}
tagsParam := strings.SplitN(tagsArg, "=", 2)[1]
return strings.Split(tagsParam, ",")
}

func TestSidecarArgumentsOpenshiftTLS(t *testing.T) {
viper.Set("platform", v1.FlagPlatformOpenShift)
defer viper.Reset()
Expand All @@ -765,8 +781,9 @@ func TestSidecarArgumentsOpenshiftTLS(t *testing.T) {
assert.Greater(t, len(util.FindItem("--reporter.grpc.host-port=dns:///my-instance-collector-headless.test.svc:14250", dep.Spec.Template.Spec.Containers[1].Args)), 0)
assert.Greater(t, len(util.FindItem("--reporter.grpc.tls.enabled=true", dep.Spec.Template.Spec.Containers[1].Args)), 0)
assert.Greater(t, len(util.FindItem("--reporter.grpc.tls.ca="+ca.ServiceCAPath, dep.Spec.Template.Spec.Containers[1].Args)), 0)
agentTags := agentTags(dep.Spec.Template.Spec.Containers[1].Args)
assert.Contains(t, agentTags, "container.name=only_container")
agentTagsMap := parseAgentTags(dep.Spec.Template.Spec.Containers[1].Args)
assert.Contains(t, agentTagsMap, "container.name")
assert.Equal(t, agentTagsMap["container.name"], "only_container")
}

func TestEqualSidecar(t *testing.T) {
Expand Down Expand Up @@ -863,3 +880,37 @@ func TestSidecarWithSecurityContext(t *testing.T) {
assert.Len(t, dep.Spec.Template.Spec.Containers, 2)
assert.Equal(t, dep.Spec.Template.Spec.Containers[1].SecurityContext, expectedSecurityContext)
}

func TestSortedTags(t *testing.T) {
defaultAgentTagsMap := make(map[string]string)
defaultAgentTagsMap["cluster"] = "undefined" // this value isn't currently available
defaultAgentTagsMap["deployment.name"] = "deploy"
defaultAgentTagsMap["pod.namespace"] = "ns"
defaultAgentTagsMap["pod.name"] = "pod_name"
defaultAgentTagsMap["host.ip"] = "0.0.0.0"
assert.Equal(t, joinTags(defaultAgentTagsMap), fmt.Sprintf("%s=%s,%s=%s,%s=%s,%s=%s,%s=%s",
"cluster", "undefined", // this value isn't currently available
"deployment.name", "deploy",
"host.ip", "0.0.0.0",
"pod.name", "pod_name",
"pod.namespace", "ns",
))
}

func TestSortedTagsWithContainer(t *testing.T) {
defaultAgentTagsMap := make(map[string]string)
defaultAgentTagsMap["cluster"] = "undefined" // this value isn't currently available
defaultAgentTagsMap["deployment.name"] = "deploy"
defaultAgentTagsMap["pod.namespace"] = "ns"
defaultAgentTagsMap["pod.name"] = "pod_name"
defaultAgentTagsMap["host.ip"] = "0.0.0.0"
defaultAgentTagsMap["container.name"] = "only_container"
assert.Equal(t, joinTags(defaultAgentTagsMap), fmt.Sprintf("%s=%s,%s=%s,%s=%s,%s=%s,%s=%s,%s=%s",
"cluster", "undefined", // this value isn't currently available
"container.name", "only_container",
"deployment.name", "deploy",
"host.ip", "0.0.0.0",
"pod.name", "pod_name",
"pod.namespace", "ns",
))
}