mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
scaffolding for zrok gc (#75)
This commit is contained in:
parent
5edea66578
commit
abe8d3e153
38
cmd/zrok/gc.go
Normal file
38
cmd/zrok/gc.go
Normal file
@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/cf"
|
||||
"github.com/openziti-test-kitchen/zrok/controller"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(newGcCmd().cmd)
|
||||
}
|
||||
|
||||
type gcCmd struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newGcCmd() *gcCmd {
|
||||
cmd := &cobra.Command{
|
||||
Use: "gc <configPath>",
|
||||
Short: "Garbage collect a zrok instance",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
c := &gcCmd{cmd: cmd}
|
||||
cmd.Run = c.run
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *gcCmd) run(_ *cobra.Command, args []string) {
|
||||
cfg, err := controller.LoadConfig(args[0])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logrus.Infof(cf.Dump(cfg, cf.DefaultOptions()))
|
||||
if err := controller.GC(cfg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var str *store.Store
|
||||
@ -55,6 +56,20 @@ func Run(cfg *Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GC(cfg *Config) error {
|
||||
if v, err := store.Open(cfg.Store); err == nil {
|
||||
str = v
|
||||
} else {
|
||||
return errors.Wrap(err, "error opening store")
|
||||
}
|
||||
defer func() {
|
||||
if err := str.Close(); err != nil {
|
||||
logrus.Errorf("error closing store: %v", err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
func versionHandler(_ metadata.VersionParams) middleware.Responder {
|
||||
return metadata.NewVersionOK().WithPayload(version)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user