From 86e5178c13fe2a6010a956bb30f22d932b3f1872 Mon Sep 17 00:00:00 2001 From: Gary Brown Date: Thu, 19 Sep 2019 12:08:01 +0100 Subject: [PATCH 1/3] Enable the documentation URL in the default menu items to be configured via the operator CLI Signed-off-by: Gary Brown --- pkg/cmd/start/main.go | 3 +++ pkg/strategy/controller.go | 7 ++++++- pkg/strategy/controller_test.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/start/main.go b/pkg/cmd/start/main.go index 839efd1a8..0c67f904d 100644 --- a/pkg/cmd/start/main.go +++ b/pkg/cmd/start/main.go @@ -89,6 +89,9 @@ func NewStartCommand() *cobra.Command { cmd.Flags().Int32("cr-metrics-port", 8686, "The metrics port for Operator and/or Custom Resource based metrics") viper.BindPFlag("cr-metrics-port", cmd.Flags().Lookup("cr-metrics-port")) + cmd.Flags().String("documentation-url", "https://www.jaegertracing.io/docs/latest", "The URL for the 'Documentation' menu item") + viper.BindPFlag("documentation-url", cmd.Flags().Lookup("documentation-url")) + return cmd } diff --git a/pkg/strategy/controller.go b/pkg/strategy/controller.go index 5b3fa10c9..6ba97d923 100644 --- a/pkg/strategy/controller.go +++ b/pkg/strategy/controller.go @@ -231,13 +231,18 @@ func enableLogOut(uiOpts map[string]interface{}, spec *v1.JaegerSpec) { return } + docURL := viper.GetString("documentation-url") + if docURL == "" { + docURL = "https://www.jaegertracing.io/docs/latest" + } + menuStr := `[ { "label": "About", "items": [ { "label": "Documentation", - "url": "https://www.jaegertracing.io/docs/latest" + "url": "` + docURL + `" } ] }, diff --git a/pkg/strategy/controller_test.go b/pkg/strategy/controller_test.go index e3c3596cb..7fe8e2cf7 100644 --- a/pkg/strategy/controller_test.go +++ b/pkg/strategy/controller_test.go @@ -407,6 +407,35 @@ func TestMenuWithSignOut(t *testing.T) { assert.Equal(t, uiOpts["menu"], expected) } +func TestMenuWithCustomDocURL(t *testing.T) { + docURL := "http://test/doc/url" + + viper.Set("documentation-url", docURL) + defer viper.Reset() + + uiOpts := map[string]interface{}{} + enableLogOut(uiOpts, &v1.JaegerSpec{Ingress: v1.JaegerIngressSpec{Security: v1.IngressSecurityOAuthProxy}}) + assert.Contains(t, uiOpts, "menu") + + expected := []interface{}{ + map[string]interface{}{ + "label": "About", + "items": []interface{}{ + map[string]interface{}{ + "label": "Documentation", + "url": docURL, + }, + }, + }, + map[string]interface{}{ + "label": "Log Out", + "url": "/oauth/sign_in", + "anchorTarget": "_self", + }, + } + assert.Equal(t, uiOpts["menu"], expected) +} + func TestMenuNoSignOutIngressSecurityNone(t *testing.T) { uiOpts := map[string]interface{}{} enableLogOut(uiOpts, &v1.JaegerSpec{Ingress: v1.JaegerIngressSpec{Security: v1.IngressSecurityNoneExplicit}}) From c27d5e7b428768d7b3c58cd69c0e92d07ec6892e Mon Sep 17 00:00:00 2001 From: Gary Brown Date: Thu, 19 Sep 2019 17:38:06 +0100 Subject: [PATCH 2/3] Added major.minor version to default doc URL, used viper set defaults in test Signed-off-by: Gary Brown --- pkg/cmd/start/main.go | 3 ++- pkg/strategy/controller.go | 9 +++------ pkg/strategy/controller_test.go | 12 ++++++++++++ pkg/version/main.go | 7 +++++++ pkg/version/main_test.go | 11 +++++++++++ 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 pkg/version/main_test.go diff --git a/pkg/cmd/start/main.go b/pkg/cmd/start/main.go index 0c67f904d..e5751a500 100644 --- a/pkg/cmd/start/main.go +++ b/pkg/cmd/start/main.go @@ -89,7 +89,8 @@ func NewStartCommand() *cobra.Command { cmd.Flags().Int32("cr-metrics-port", 8686, "The metrics port for Operator and/or Custom Resource based metrics") viper.BindPFlag("cr-metrics-port", cmd.Flags().Lookup("cr-metrics-port")) - cmd.Flags().String("documentation-url", "https://www.jaegertracing.io/docs/latest", "The URL for the 'Documentation' menu item") + docURL := fmt.Sprintf("https://www.jaegertracing.io/docs/%s", version.DefaultJaegerMajorMinor()) + cmd.Flags().String("documentation-url", docURL, "The URL for the 'Documentation' menu item") viper.BindPFlag("documentation-url", cmd.Flags().Lookup("documentation-url")) return cmd diff --git a/pkg/strategy/controller.go b/pkg/strategy/controller.go index 6ba97d923..66a95a1db 100644 --- a/pkg/strategy/controller.go +++ b/pkg/strategy/controller.go @@ -232,17 +232,14 @@ func enableLogOut(uiOpts map[string]interface{}, spec *v1.JaegerSpec) { } docURL := viper.GetString("documentation-url") - if docURL == "" { - docURL = "https://www.jaegertracing.io/docs/latest" - } - menuStr := `[ + menuStr := fmt.Sprintf(`[ { "label": "About", "items": [ { "label": "Documentation", - "url": "` + docURL + `" + "url": "%s" } ] }, @@ -251,7 +248,7 @@ func enableLogOut(uiOpts map[string]interface{}, spec *v1.JaegerSpec) { "url": "/oauth/sign_in", "anchorTarget": "_self" } - ]` + ]`, docURL) menuArray := make([]interface{}, 2) diff --git a/pkg/strategy/controller_test.go b/pkg/strategy/controller_test.go index 7fe8e2cf7..584065fcb 100644 --- a/pkg/strategy/controller_test.go +++ b/pkg/strategy/controller_test.go @@ -12,6 +12,18 @@ import ( v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" ) +func setDefaults() { + viper.SetDefault("documentation-url", "https://www.jaegertracing.io/docs/latest") +} + +func init() { + setDefaults() +} + +func reset() { + viper.Reset() + setDefaults() +} func TestNewControllerForAllInOneAsDefault(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestNewControllerForAllInOneAsDefault"}) diff --git a/pkg/version/main.go b/pkg/version/main.go index 33314620d..65bf1ff4e 100644 --- a/pkg/version/main.go +++ b/pkg/version/main.go @@ -3,6 +3,7 @@ package version import ( "fmt" "runtime" + "strings" sdkVersion "github.com/operator-framework/operator-sdk/version" ) @@ -54,3 +55,9 @@ func DefaultJaeger() string { // fallback value, useful for tests return "0.0.0" } + +// DefaultJaegerMajorMinor returns the major.minor format of the default Jaeger version +func DefaultJaegerMajorMinor() string { + version := DefaultJaeger() + return version[:strings.LastIndex(version, ".")] +} diff --git a/pkg/version/main_test.go b/pkg/version/main_test.go new file mode 100644 index 000000000..d3f7f8c34 --- /dev/null +++ b/pkg/version/main_test.go @@ -0,0 +1,11 @@ +package version + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDefaultJaegerMajorMinor(t *testing.T) { + assert.Equal(t, "0.0", DefaultJaegerMajorMinor()) +} From a49cfbfc0933b229a00b67f93b5d05bee9d0795d Mon Sep 17 00:00:00 2001 From: Gary Brown Date: Thu, 19 Sep 2019 18:08:49 +0100 Subject: [PATCH 3/3] Changed way default is set Signed-off-by: Gary Brown --- pkg/strategy/controller_test.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pkg/strategy/controller_test.go b/pkg/strategy/controller_test.go index 584065fcb..4946483a2 100644 --- a/pkg/strategy/controller_test.go +++ b/pkg/strategy/controller_test.go @@ -12,18 +12,6 @@ import ( v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1" ) -func setDefaults() { - viper.SetDefault("documentation-url", "https://www.jaegertracing.io/docs/latest") -} - -func init() { - setDefaults() -} - -func reset() { - viper.Reset() - setDefaults() -} func TestNewControllerForAllInOneAsDefault(t *testing.T) { jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestNewControllerForAllInOneAsDefault"}) @@ -396,6 +384,9 @@ func TestNormalizeUIDependenciesTab(t *testing.T) { } func TestMenuWithSignOut(t *testing.T) { + viper.SetDefault("documentation-url", "https://www.jaegertracing.io/docs/latest") + defer viper.Reset() + uiOpts := map[string]interface{}{} enableLogOut(uiOpts, &v1.JaegerSpec{Ingress: v1.JaegerIngressSpec{Security: v1.IngressSecurityOAuthProxy}}) assert.Contains(t, uiOpts, "menu")