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

Enable the documentation URL in the default menu items to be configur… #666

Merged
merged 3 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/cmd/start/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/strategy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
},
Expand All @@ -246,7 +248,7 @@ func enableLogOut(uiOpts map[string]interface{}, spec *v1.JaegerSpec) {
"url": "/oauth/sign_in",
"anchorTarget": "_self"
}
]`
]`, docURL)

menuArray := make([]interface{}, 2)

Expand Down
32 changes: 32 additions & 0 deletions pkg/strategy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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}})
Expand Down
7 changes: 7 additions & 0 deletions pkg/version/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package version
import (
"fmt"
"runtime"
"strings"

sdkVersion "github.com/operator-framework/operator-sdk/version"
)
Expand Down Expand Up @@ -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, ".")]
}
11 changes: 11 additions & 0 deletions pkg/version/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package version

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDefaultJaegerMajorMinor(t *testing.T) {
assert.Equal(t, "0.0", DefaultJaegerMajorMinor())
}