scaffolding for zrok gc (#75)

This commit is contained in:
Michael Quigley 2022-10-06 13:24:15 -04:00
parent 5edea66578
commit abe8d3e153
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 53 additions and 0 deletions

38
cmd/zrok/gc.go Normal file
View 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)
}
}

View File

@ -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)
}