diff --git a/pkg/cmd/start/main.go b/pkg/cmd/start/main.go index 839efd1a8..e5751a500 100644 --- a/pkg/cmd/start/main.go +++ b/pkg/cmd/start/main.go @@ -89,6 +89,10 @@ 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")) + 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 5b3fa10c9..66a95a1db 100644 --- a/pkg/strategy/controller.go +++ b/pkg/strategy/controller.go @@ -231,13 +231,15 @@ func enableLogOut(uiOpts map[string]interface{}, spec *v1.JaegerSpec) { return } - menuStr := `[ + docURL := viper.GetString("documentation-url") + + menuStr := fmt.Sprintf(`[ { "label": "About", "items": [ { "label": "Documentation", - "url": "https://www.jaegertracing.io/docs/latest" + "url": "%s" } ] }, @@ -246,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 e3c3596cb..4946483a2 100644 --- a/pkg/strategy/controller_test.go +++ b/pkg/strategy/controller_test.go @@ -384,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") @@ -407,6 +410,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}}) 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()) +}