-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add playground command Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * codegen Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * rm wasm Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * mkdocs nav Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * workflows Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Jim Bugwadia <jim@nirmata.com>
- Loading branch information
1 parent
8165d6b
commit 08cdc4d
Showing
48 changed files
with
1,525 additions
and
221 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
/kyverno-json | ||
website/site | ||
website/playground/assets/main.wasm | ||
pkg/server/ui/dist/assets/main.wasm |
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,28 @@ | ||
## kyverno-json playground | ||
|
||
playground | ||
|
||
### Synopsis | ||
|
||
Serve playground | ||
|
||
``` | ||
kyverno-json playground [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
--gin-cors enable gin cors (default true) | ||
--gin-log enable gin logger (default true) | ||
--gin-max-body-size int gin max body size (default 2097152) | ||
--gin-mode string gin run mode (default "release") | ||
-h, --help help for playground | ||
--server-host string server host (default "0.0.0.0") | ||
--server-port int server port (default 8080) | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kyverno-json](kyverno-json.md) - kyverno-json is a CLI tool to apply policies to json 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,27 @@ | ||
package playground | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func Command(parents ...string) *cobra.Command { | ||
var command options | ||
cmd := &cobra.Command{ | ||
Use: "playground", | ||
Short: "playground", | ||
Long: "Serve playground", | ||
Args: cobra.NoArgs, | ||
SilenceUsage: true, | ||
RunE: command.Run, | ||
} | ||
// server flags | ||
cmd.Flags().StringVar(&command.serverFlags.host, "server-host", "0.0.0.0", "server host") | ||
cmd.Flags().IntVar(&command.serverFlags.port, "server-port", 8080, "server port") | ||
// gin flags | ||
cmd.Flags().StringVar(&command.ginFlags.mode, "gin-mode", gin.ReleaseMode, "gin run mode") | ||
cmd.Flags().BoolVar(&command.ginFlags.log, "gin-log", true, "enable gin logger") | ||
cmd.Flags().BoolVar(&command.ginFlags.cors, "gin-cors", true, "enable gin cors") | ||
cmd.Flags().IntVar(&command.ginFlags.maxBodySize, "gin-max-body-size", 2*1024*1024, "gin max body size") | ||
return cmd | ||
} |
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,60 @@ | ||
package playground | ||
|
||
import ( | ||
"context" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/kyverno/kyverno-json/pkg/server" | ||
"github.com/kyverno/kyverno-json/pkg/server/ui" | ||
"github.com/loopfz/gadgeto/tonic" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type options struct { | ||
serverFlags serverFlags | ||
ginFlags ginFlags | ||
} | ||
|
||
type serverFlags struct { | ||
host string | ||
port int | ||
} | ||
|
||
type ginFlags struct { | ||
mode string | ||
log bool | ||
cors bool | ||
maxBodySize int | ||
} | ||
|
||
func (c *options) Run(_ *cobra.Command, _ []string) error { | ||
// initialise gin framework | ||
gin.SetMode(c.ginFlags.mode) | ||
tonic.SetBindHook(tonic.DefaultBindingHookMaxBodyBytes(int64(c.ginFlags.maxBodySize))) | ||
// create router | ||
router, err := server.New(c.ginFlags.log, c.ginFlags.cors) | ||
if err != nil { | ||
return err | ||
} | ||
// register api routes | ||
if err := ui.AddRoutes(router); err != nil { | ||
return err | ||
} | ||
// run server | ||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) | ||
defer stop() | ||
shutdown := server.Run(ctx, router, c.serverFlags.host, c.serverFlags.port) | ||
<-ctx.Done() | ||
stop() | ||
if shutdown != nil { | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
if err := shutdown(ctx); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.