1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-23 04:19:37 +00:00
Files
steve/pkg/server/cli/clicontext.go
Tom Lebreux 127d37391d Better gc (#717)
* More error wrapping for SQL cache

* Use context.Context instead of stopCh

* Move CacheFor to Info log level

* Implement time-based GC

* Set default GC param when running standalone steve
2025-07-11 12:48:19 -04:00

94 lines
2.1 KiB
Go

package cli
import (
"context"
"time"
steveauth "github.com/rancher/steve/pkg/auth"
authcli "github.com/rancher/steve/pkg/auth/cli"
"github.com/rancher/steve/pkg/server"
"github.com/rancher/steve/pkg/sqlcache/informer/factory"
"github.com/rancher/steve/pkg/ui"
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
"github.com/rancher/wrangler/v3/pkg/ratelimit"
"github.com/urfave/cli/v2"
)
type Config struct {
KubeConfig string
Context string
HTTPSListenPort int
HTTPListenPort int
UIPath string
WebhookConfig authcli.WebhookConfig
}
func (c *Config) MustServer(ctx context.Context) *server.Server {
cc, err := c.ToServer(ctx, false)
if err != nil {
panic(err)
}
return cc
}
func (c *Config) ToServer(ctx context.Context, sqlCache bool) (*server.Server, error) {
var (
auth steveauth.Middleware
)
restConfig, err := kubeconfig.GetNonInteractiveClientConfigWithContext(c.KubeConfig, c.Context).ClientConfig()
if err != nil {
return nil, err
}
restConfig.RateLimiter = ratelimit.None
if c.WebhookConfig.WebhookAuthentication {
auth, err = c.WebhookConfig.WebhookMiddleware()
if err != nil {
return nil, err
}
}
return server.New(ctx, restConfig, &server.Options{
AuthMiddleware: auth,
Next: ui.New(c.UIPath),
SQLCache: sqlCache,
SQLCacheFactoryOptions: factory.CacheFactoryOptions{
GCInterval: 15 * time.Minute,
GCKeepCount: 1000,
},
})
}
func Flags(config *Config) []cli.Flag {
flags := []cli.Flag{
&cli.StringFlag{
Name: "kubeconfig",
EnvVars: []string{"KUBECONFIG"},
Destination: &config.KubeConfig,
},
&cli.StringFlag{
Name: "context",
EnvVars: []string{"CONTEXT"},
Destination: &config.Context,
},
&cli.StringFlag{
Name: "ui-path",
Destination: &config.UIPath,
},
&cli.IntFlag{
Name: "https-listen-port",
Value: 9443,
Destination: &config.HTTPSListenPort,
},
&cli.IntFlag{
Name: "http-listen-port",
Value: 9080,
Destination: &config.HTTPListenPort,
},
}
return append(flags, authcli.Flags(&config.WebhookConfig)...)
}