Skip to content

Commit

Permalink
[ plat-2298 ] add headlamp
Browse files Browse the repository at this point in the history
  • Loading branch information
wenn committed Jan 14, 2025
1 parent 0cd3801 commit ab9d7bf
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 35 deletions.
26 changes: 14 additions & 12 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ DESCRIPTION
command shorthand description
help h show the help message.
up u spin up an orchestra sandbox.
down tear down an orchestra sandbox.
name n show the sandbox name.
dash d open the dashboard in a browser.
logs l open the logs in a browser.
web w open the site in a browser.
graphiql g open graphql user interface in a browser.
version v show the version of the sbx cli.
info i show the summary of the sandbox.
progress p open deployment progress in a browser.
help shows the help message.
up u spins up an orchestra sandbox.
down tears down an orchestra sandbox.
name n shows the sandbox name.
dash d opens the dashboard in a browser.
logs l opens the logs in a browser.
web w opens the site in a browser.
graphiql g opens graphql user interface in a browser.
version v shows the version of the sbx cli.
info i shows the summary of the sandbox.
progress p opens deployment progress in a browser.
headlamp h opens headlamp ( kubernetes dashboard ) in a browser.
USAGE:
Expand All @@ -62,7 +63,6 @@ func Commands() map[string]RunFn {
"up": up.Run,
"u": up.Run,
"help": help,
"h": help,
"name": name.Run,
"n": name.Run,
"web": web.Open,
Expand All @@ -80,5 +80,7 @@ func Commands() map[string]RunFn {
"l": logs.Run,
"info": summary.Run,
"i": summary.Run,
"headlamp": web.OpenHeadlamp,
"h": web.OpenHeadlamp,
}
}
11 changes: 8 additions & 3 deletions summary/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"github.com/reverbdotcom/sbx/commit"
"github.com/reverbdotcom/sbx/name"
"github.com/reverbdotcom/sbx/run"
"github.com/reverbdotcom/sbx/web"
)

const template = "https://%s.int.orchestra.rvb.ai/"
const summary = `»»»
Name: %s
SHA: %s
Expand All @@ -17,6 +17,7 @@ Host: %s
Site: sbx w | sbx web
Graphiql: sbx g | sbx graphiql
Headlamp: sbx h | sbx headlamp
Dash: sbx d | sbx dash
Logs: sbx l | sbx logs
Deployment: sbx p | sbx progress
Expand Down Expand Up @@ -46,7 +47,6 @@ func Print(name string) error {

var htmlUrl = run.HtmlUrl
var headSHA = commit.HeadSHA
var webUrl = web.Url

func printSummary(name string) (string, error) {
sha, err := headSHA()
Expand All @@ -59,6 +59,11 @@ func printSummary(name string) (string, error) {
summary,
name,
sha,
webUrl(),
url(),
), nil
}

func url() string {
name, _ := name.Name()
return fmt.Sprintf(template, name)
}
5 changes: 2 additions & 3 deletions summary/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ func TestPrint(t *testing.T) {
name := "sandbox-blake-julian-kevin"

headSHA = func() (string, error) { return "head.sha", nil }
webUrl = func() string { return "web.url" }

got, err := printSummary(name)

if err != nil {
Expand All @@ -21,12 +19,13 @@ func TestPrint(t *testing.T) {
want := `»»»
Name: sandbox-blake-julian-kevin
SHA: head.sha
Host: web.url
Host: https://sandbox-lorraine-francisco-jonathan.int.orchestra.rvb.ai/
»»»
Site: sbx w | sbx web
Graphiql: sbx g | sbx graphiql
Headlamp: sbx h | sbx headlamp
Dash: sbx d | sbx dash
Logs: sbx l | sbx logs
Deployment: sbx p | sbx progress
Expand Down
16 changes: 13 additions & 3 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (
)

const template = "https://%s.int.orchestra.rvb.ai/"
const headlampTemplate = "https://headlamp.int.preprod.reverb.rvb.ai/c/main/deployments?namespace=%s"

var openURL = open.Open

func Open() (string, error) {
err := openURL(Url())
name, _ := nameFn()
url := fmt.Sprintf(template, name)
err := openURL(url)

if err != nil {
return "", err
Expand All @@ -39,7 +42,14 @@ func OpenProgress() (string, error) {

var nameFn = name.Name

func Url() string {
func OpenHeadlamp() (string, error) {
name, _ := nameFn()
return fmt.Sprintf(template, name)
url := fmt.Sprintf(headlampTemplate, name)
err := openURL(url)

if err != nil {
return "", err
}

return "", nil
}
50 changes: 36 additions & 14 deletions web/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ import (
"testing"
)

func TestUrl(t *testing.T) {
name := "sandbox-foo-bar-baz"
nameFn = func() (string, error) { return name, nil }

t.Run("it returns url", func(t *testing.T) {
got := Url()
want := fmt.Sprintf(template, name)

if got != want {
t.Errorf("got %v, want %v", got, want)
}
})
}

func TestOpen(t *testing.T) {
name := "sandbox-foo-bar-baz"
nameFn = func() (string, error) { return name, nil }
Expand Down Expand Up @@ -113,3 +99,39 @@ func TestOpenProgress(t *testing.T) {
}
})
}

func TestOpenHeadlamp(t *testing.T) {
name := "sandbox-foo-bar-baz"
nameFn = func() (string, error) { return name, nil }

t.Run("it opens url", func(t *testing.T) {
want := fmt.Sprintf(headlampTemplate, name)

openURL = func(got string) error {
if got != want {
t.Errorf("got %v, want %v", got, want)
}

return nil
}

_, err := OpenHeadlamp()

if err != nil {
t.Errorf("got %v, want nil", err)
}
})

t.Run("it returns err", func(t *testing.T) {
openURL = func(_ string) error {
return errors.New("open error")
}

_, err := OpenHeadlamp()

want := "open error"
if err.Error() != want {
t.Errorf("got %v, want %v", err, want)
}
})
}

0 comments on commit ab9d7bf

Please sign in to comment.