-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kuma-cp) serve gui server (#410)
- Loading branch information
1 parent
c71ced8
commit 366106e
Showing
26 changed files
with
517 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package resources | ||
|
||
//go:generate go run github.com/shurcooL/vfsgen/cmd/vfsgendev -source="github.com/Kong/kuma/app/kuma-ui/pkg/resources".GuiDir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// +build dev | ||
|
||
package resources | ||
|
||
import ( | ||
"net/http" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
var GuiDir http.FileSystem = http.Dir(guiSrcDir()) | ||
|
||
func guiSrcDir() string { | ||
_, thisFile, _, _ := runtime.Caller(1) | ||
|
||
thisDir := filepath.Dir(thisFile) | ||
|
||
return filepath.Join(thisDir, "..", "..", "data", "resources") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package resources_test | ||
|
||
import ( | ||
"github.com/Kong/kuma/app/kuma-ui/pkg/resources" | ||
"github.com/Kong/kuma/pkg/test/vfsgen" | ||
"io/ioutil" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Gui Dir", func() { | ||
|
||
guiDir := filepath.Join("..", "..", "data", "resources") | ||
testEntries := vfsgen.GenerateEntries(guiDir) | ||
|
||
DescribeTable("generated Go code must be in sync with the original GUI dir", | ||
func(given vfsgen.FileTestCase) { | ||
// given compiled file | ||
file, err := resources.GuiDir.Open(given.Filename) | ||
// then | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// when | ||
actualContents, err := ioutil.ReadAll(file) | ||
// then | ||
Expect(err).ToNot(HaveOccurred()) | ||
// and | ||
Expect(string(actualContents)).To(Equal(string(given.ExpectedContents)), "generated Go code is no longer in sync with the original template files. To re-generate it, run `make generate/gui`") | ||
}, | ||
testEntries..., | ||
) | ||
|
||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package resources_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestGui(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "GUI Resources Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Kong/kuma/app/kuma-ui/pkg/resources" | ||
gui_server "github.com/Kong/kuma/pkg/config/gui-server" | ||
"github.com/Kong/kuma/pkg/core" | ||
core_runtime "github.com/Kong/kuma/pkg/core/runtime" | ||
"net/http" | ||
) | ||
|
||
var log = core.Log.WithName("gui-server") | ||
|
||
func SetupServer(rt core_runtime.Runtime) error { | ||
srv := Server{rt.Config().GuiServer} | ||
if err := core_runtime.Add(rt, &srv); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
type Server struct { | ||
Config *gui_server.GuiServerConfig | ||
} | ||
|
||
var _ core_runtime.Component = &Server{} | ||
|
||
func (g *Server) Start(stop <-chan struct{}) error { | ||
fileServer := http.FileServer(resources.GuiDir) | ||
|
||
guiServer := &http.Server{ | ||
Addr: fmt.Sprintf(":%d", g.Config.Port), | ||
Handler: fileServer, | ||
} | ||
|
||
errChan := make(chan error) | ||
|
||
go func() { | ||
defer close(errChan) | ||
if err := guiServer.ListenAndServe(); err != nil { | ||
if err != http.ErrServerClosed { | ||
log.Error(err, "terminated with an error") | ||
errChan <- err | ||
return | ||
} | ||
} | ||
log.Info("terminated normally") | ||
}() | ||
log.Info("starting", "port", g.Config.Port) | ||
|
||
select { | ||
case <-stop: | ||
log.Info("stopping") | ||
return guiServer.Shutdown(context.Background()) | ||
case err := <-errChan: | ||
return err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package server_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestGui(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "GUI Suite") | ||
} |
Oops, something went wrong.