Skip to content

Commit

Permalink
fix: commands in main
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Oct 24, 2024
1 parent 50e25fa commit 954f3c1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.tools/
website/site/
kyverno-envoy-plugin
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ vet: ## Run go vet
@echo Go vet... >&2
@go vet ./...

#########
# BUILD #
#########

.PHONY: build
build: ## Build
build: fmt
build: vet
build:
@echo "Build..." >&2
@LD_FLAGS=$(LD_FLAGS) go build .

##############
# BUILD (KO) #
##############
Expand All @@ -118,8 +130,7 @@ build-ko: fmt
build-ko: vet
build-ko: $(KO)
@echo "Build Docker image with ko..." >&2
@LD_FLAGS=$(LD_FLAGS) KO_DOCKER_REPO=$(KO_REGISTRY) \
$(KO) build . --preserve-import-paths --tags=$(KO_TAGS)
@LD_FLAGS=$(LD_FLAGS) KO_DOCKER_REPO=$(KO_REGISTRY) $(KO) build . --preserve-import-paths --tags=$(KO_TAGS)

########
# TEST #
Expand Down
50 changes: 24 additions & 26 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,33 @@ import (
"github.com/spf13/cobra"
)

var policies []string
var address string
var healthaddress string

func init() {
serveCmd.Flags().StringSliceVar(&policies, "policy", nil, "Path to kyverno-json policies")
serveCmd.Flags().StringVar(&address, "address", ":9000", "Address to listen on")
serveCmd.Flags().StringVar(&healthaddress, "healthaddress", ":8181", "Address to listen on for health checks")
}

var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start the kyverno-envoy-plugin server",
Run: func(cmd *cobra.Command, args []string) {
srv := server.NewServers(policies, address, healthaddress)
server.StartServers(srv)
},
func main() {
root := setup()
if err := root.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func main() {
var rootCmd = &cobra.Command{
func setup() *cobra.Command {
var policies []string
var address string
var healthaddress string
serve := &cobra.Command{
Use: "serve",
Short: "Start the kyverno-envoy-plugin server",
Run: func(cmd *cobra.Command, args []string) {
srv := server.NewServers(policies, address, healthaddress)
server.StartServers(srv)
},
}
serve.Flags().StringSliceVar(&policies, "policy", nil, "Path to kyverno-json policies")
serve.Flags().StringVar(&address, "address", ":9000", "Address to listen on")
serve.Flags().StringVar(&healthaddress, "healthaddress", ":8181", "Address to listen on for health checks")
root := &cobra.Command{
Use: "kyverno-envoy-plugin",
Short: "kyverno-envoy-plugin is a plugin for Envoy",
}

rootCmd.AddCommand(serveCmd)

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
root.AddCommand(serve)
return root
}

0 comments on commit 954f3c1

Please sign in to comment.