1
0
mirror of https://github.com/rancher/steve.git synced 2025-07-08 04:19:06 +00:00
steve/pkg/debug/cli.go
Eric Promislow 06c2eb50d1
Index more sqlite cache fields (#271)
* Add more fields to index when sql-caching is on.

Misc changes:
- Use the builtin Event class, not events.k8s.io (by looking at the dashboard client code)
- Specify full path to the management.cattle.io fields.
- Map `Event.type` to `Event._type` for indexing.

Use a compound transform-func to first check for a "signal",
and then to run all the relevant transformers until either
one fails or the list is exhausted.

- Includes moving the fakeSummaryCache type into a common area.

Use a simpler way of running transforms.

* Inline the function to get the gvk key.

* Create a '--sql-cache' flag to turn on caching for the steve CLI.

* Improve error-handling in object transformer.

* Drop the 'GetTransform' function.

* Inline the code that transforms a payload into a k8s-unstructured object.
2024-10-18 11:06:29 -07:00

82 lines
1.4 KiB
Go

package debug
import (
"flag"
"fmt"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
cliv2 "github.com/urfave/cli/v2"
"k8s.io/klog"
)
type Config struct {
Debug bool
DebugLevel int
SQLCache bool
}
func (c *Config) MustSetupDebug() {
err := c.SetupDebug()
if err != nil {
panic("failed to setup debug logging: " + err.Error())
}
}
func (c *Config) SetupDebug() error {
logging := flag.NewFlagSet("", flag.PanicOnError)
klog.InitFlags(logging)
if c.Debug {
logrus.SetLevel(logrus.DebugLevel)
if err := logging.Parse([]string{
fmt.Sprintf("-v=%d", c.DebugLevel),
}); err != nil {
return err
}
} else {
if err := logging.Parse([]string{
"-v=0",
}); err != nil {
return err
}
}
return nil
}
func Flags(config *Config) []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: "debug",
Destination: &config.Debug,
},
cli.IntFlag{
Name: "debug-level",
Value: 7,
Destination: &config.DebugLevel,
},
cli.BoolFlag{
Name: "sql-cache",
Destination: &config.SQLCache,
},
}
}
func FlagsV2(config *Config) []cliv2.Flag {
return []cliv2.Flag{
&cliv2.BoolFlag{
Name: "debug",
Destination: &config.Debug,
},
&cliv2.IntFlag{
Name: "debug-level",
Value: 7,
Destination: &config.DebugLevel,
},
&cliv2.BoolFlag{
Name: "sql-cache",
Destination: &config.SQLCache,
},
}
}