From 74514eaeb1a0fa189a31548c0aa0eac9b8741bf8 Mon Sep 17 00:00:00 2001 From: johanavril Date: Wed, 28 Oct 2020 22:18:30 +0700 Subject: [PATCH] use new admin port flag will check the new flag for retrieving admin port and if not available will use the old one instead Signed-off-by: johanavril --- pkg/deployment/agent.go | 2 +- pkg/deployment/all_in_one.go | 2 +- pkg/deployment/collector.go | 2 +- pkg/deployment/ingester.go | 2 +- pkg/deployment/query.go | 2 +- pkg/inject/sidecar.go | 2 +- pkg/util/util.go | 13 +++++++++++++ pkg/util/util_test.go | 36 ++++++++++++++++++++++++++++++++++++ 8 files changed, 55 insertions(+), 6 deletions(-) diff --git a/pkg/deployment/agent.go b/pkg/deployment/agent.go index 629e39c05..c6b90da39 100644 --- a/pkg/deployment/agent.go +++ b/pkg/deployment/agent.go @@ -58,7 +58,7 @@ func (a *Agent) Get() *appsv1.DaemonSet { configRest := util.GetPort("--http-server.host-port=", args, 5778) jgCompactTrft := util.GetPort("--processor.jaeger-compact.server-host-port=", args, 6831) jgBinaryTrft := util.GetPort("--processor.jaeger-binary.server-host-port=", args, 6832) - adminPort := util.GetPort("--admin-http-port=", args, 14271) + adminPort := util.GetAdminPort(args, 14271) trueVar := true falseVar := false diff --git a/pkg/deployment/all_in_one.go b/pkg/deployment/all_in_one.go index 561e42127..290062475 100644 --- a/pkg/deployment/all_in_one.go +++ b/pkg/deployment/all_in_one.go @@ -42,7 +42,7 @@ func (a *AllInOne) Get() *appsv1.Deployment { args := append(a.jaeger.Spec.AllInOne.Options.ToArgs()) - adminPort := util.GetPort("--admin-http-port=", args, 14269) + adminPort := util.GetAdminPort(args, 14269) baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ diff --git a/pkg/deployment/collector.go b/pkg/deployment/collector.go index 918a5c9fb..44121f6b4 100644 --- a/pkg/deployment/collector.go +++ b/pkg/deployment/collector.go @@ -43,7 +43,7 @@ func (c *Collector) Get() *appsv1.Deployment { args := append(c.jaeger.Spec.Collector.Options.ToArgs()) - adminPort := util.GetPort("--admin-http-port=", args, 14269) + adminPort := util.GetAdminPort(args, 14269) baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ diff --git a/pkg/deployment/ingester.go b/pkg/deployment/ingester.go index c11eea7cf..0b7890b1a 100644 --- a/pkg/deployment/ingester.go +++ b/pkg/deployment/ingester.go @@ -49,7 +49,7 @@ func (i *Ingester) Get() *appsv1.Deployment { args := append(i.jaeger.Spec.Ingester.Options.ToArgs()) - adminPort := util.GetPort("--admin-http-port=", args, 14270) + adminPort := util.GetAdminPort(args, 14270) baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ diff --git a/pkg/deployment/query.go b/pkg/deployment/query.go index a94b4bf4b..16d117a69 100644 --- a/pkg/deployment/query.go +++ b/pkg/deployment/query.go @@ -38,7 +38,7 @@ func (q *Query) Get() *appsv1.Deployment { args := append(q.jaeger.Spec.Query.Options.ToArgs()) - adminPort := util.GetPort("--admin-http-port=", args, 16687) + adminPort := util.GetAdminPort(args, 16687) baseCommonSpec := v1.JaegerCommonSpec{ Annotations: map[string]string{ diff --git a/pkg/inject/sidecar.go b/pkg/inject/sidecar.go index faee9e54a..f356073f8 100644 --- a/pkg/inject/sidecar.go +++ b/pkg/inject/sidecar.go @@ -184,7 +184,7 @@ func container(jaeger *v1.Jaeger, dep *appsv1.Deployment) corev1.Container { configRest := util.GetPort("--http-server.host-port=", args, 5778) jgCompactTrft := util.GetPort("--processor.jaeger-compact.server-host-port=", args, 6831) jgBinaryTrft := util.GetPort("--processor.jaeger-binary.server-host-port=", args, 6832) - adminPort := util.GetPort("--admin-http-port=", args, 14271) + 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", diff --git a/pkg/util/util.go b/pkg/util/util.go index a9b0a55c3..d1b5bd4cf 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -225,6 +225,19 @@ func GetPort(arg string, args []string, port int32) int32 { return port } +// GetAdminPort returns a port, either from supplied default port, or extracted from supplied arg value. +// If new admin port flag exists, it will extracted from the new flag, otherwise will try to extract +// from deprecated flag. +func GetAdminPort(args []string, port int32) int32 { + if portArg := FindItem("--admin.http.host-port=", args); len(portArg) > 0 { + port = GetPort("--admin.http.host-port=", args, port) + } else { + port = GetPort("--admin-http-port=", args, port) + } + + return port +} + // InitObjectMeta will set the required default settings to // kubernetes objects metadata if is required. func InitObjectMeta(obj metav1.Object) { diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 5af76ba80..9f87d5bde 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -353,6 +353,42 @@ func TestGetPortSpecified(t *testing.T) { assert.Equal(t, int32(6831), GetPort("--processor.jaeger-compact.server-host-port=", args, 1234)) } +func TestGetAdminPort(t *testing.T) { + tests := map[string]struct { + opts v1.Options + defaultPort int32 + expectedPort int32 + }{ + "Use default port when no admin port flag provided": { + opts: v1.NewOptions(map[string]interface{}{}), + defaultPort: 1234, + expectedPort: 1234, + }, + "Use deprecated flag when new flag not provided and deprecated flag provided": { + opts: v1.NewOptions(map[string]interface{}{ + "admin-http-port": ":1111", + }), + defaultPort: 1234, + expectedPort: 1111, + }, + "Use new flag when provided": { + opts: v1.NewOptions(map[string]interface{}{ + "admin-http-port": ":1111", + "admin.http.host-port": ":2222", + }), + defaultPort: 1234, + expectedPort: 2222, + }, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + args := test.opts.ToArgs() + assert.Equal(t, test.expectedPort, GetAdminPort(args, test.defaultPort)) + }) + } +} + func TestInitObjectMeta(t *testing.T) { tests := map[string]struct { obj metav1.Object