mirror of
https://github.com/kyverno/policy-reporter.git
synced 2024-12-14 11:57:32 +00:00
Configure K8s Client QPS and Burst
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
This commit is contained in:
parent
6f55d5cfbf
commit
3426a95c98
7 changed files with 34 additions and 13 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
.go-version
|
||||
.deploy
|
||||
.vscode
|
||||
/config.yaml
|
||||
build
|
||||
/test.yaml
|
||||
|
|
|
@ -26,8 +26,8 @@ func newRunCMD() *cobra.Command {
|
|||
}
|
||||
|
||||
var k8sConfig *rest.Config
|
||||
if c.Kubeconfig != "" {
|
||||
k8sConfig, err = clientcmd.BuildConfigFromFlags("", c.Kubeconfig)
|
||||
if c.K8sClient.Kubeconfig != "" {
|
||||
k8sConfig, err = clientcmd.BuildConfigFromFlags("", c.K8sClient.Kubeconfig)
|
||||
} else {
|
||||
k8sConfig, err = rest.InClusterConfig()
|
||||
}
|
||||
|
@ -35,6 +35,9 @@ func newRunCMD() *cobra.Command {
|
|||
return err
|
||||
}
|
||||
|
||||
k8sConfig.QPS = c.K8sClient.QPS
|
||||
k8sConfig.Burst = c.K8sClient.Burst
|
||||
|
||||
resolver := config.NewResolver(c, k8sConfig)
|
||||
|
||||
client, err := resolver.PolicyReportClient()
|
||||
|
@ -125,6 +128,8 @@ func newRunCMD() *cobra.Command {
|
|||
cmd.PersistentFlags().Bool("profile", false, "Enable application profiling with pprof")
|
||||
cmd.PersistentFlags().String("lease-name", "policy-reporter", "name of the LeaseLock")
|
||||
cmd.PersistentFlags().Int("worker", 5, "amount of queue worker")
|
||||
cmd.PersistentFlags().Float32("qps", 20, "K8s RESTClient QPS")
|
||||
cmd.PersistentFlags().Int("burst", 50, "K8s RESTClient burst")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ func NewSummaryCMD() *cobra.Command {
|
|||
}
|
||||
|
||||
var k8sConfig *rest.Config
|
||||
if c.Kubeconfig != "" {
|
||||
k8sConfig, err = clientcmd.BuildConfigFromFlags("", c.Kubeconfig)
|
||||
if c.K8sClient.Kubeconfig != "" {
|
||||
k8sConfig, err = clientcmd.BuildConfigFromFlags("", c.K8sClient.Kubeconfig)
|
||||
} else {
|
||||
k8sConfig, err = rest.InClusterConfig()
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ func NewViolationsCMD() *cobra.Command {
|
|||
}
|
||||
|
||||
var k8sConfig *rest.Config
|
||||
if c.Kubeconfig != "" {
|
||||
k8sConfig, err = clientcmd.BuildConfigFromFlags("", c.Kubeconfig)
|
||||
if c.K8sClient.Kubeconfig != "" {
|
||||
k8sConfig, err = clientcmd.BuildConfigFromFlags("", c.K8sClient.Kubeconfig)
|
||||
} else {
|
||||
k8sConfig, err = rest.InClusterConfig()
|
||||
}
|
||||
|
|
|
@ -255,6 +255,13 @@ type LeaderElection struct {
|
|||
Enabled bool `mapstructure:"enabled"`
|
||||
}
|
||||
|
||||
// K8sClient config struct
|
||||
type K8sClient struct {
|
||||
QPS float32 `mapstructure:"qps"`
|
||||
Burst int `mapstructure:"burst"`
|
||||
Kubeconfig string `mapstructure:"kubeconfig"`
|
||||
}
|
||||
|
||||
// Config of the PolicyReporter
|
||||
type Config struct {
|
||||
Namespace string `mapstructure:"namespace"`
|
||||
|
@ -268,7 +275,6 @@ type Config struct {
|
|||
UI UI `mapstructure:"ui"`
|
||||
Webhook Webhook `mapstructure:"webhook"`
|
||||
API API `mapstructure:"api"`
|
||||
Kubeconfig string `mapstructure:"kubeconfig"`
|
||||
WorkerCount int `mapstructure:"worker"`
|
||||
DBFile string `mapstructure:"dbfile"`
|
||||
Metrics Metrics `mapstructure:"metrics"`
|
||||
|
@ -279,4 +285,5 @@ type Config struct {
|
|||
Profiling Profiling `mapstructure:"profiling"`
|
||||
EmailReports EmailReports `mapstructure:"emailReports"`
|
||||
LeaderElection LeaderElection `mapstructure:"leaderElection"`
|
||||
K8sClient K8sClient `mapstructure:"k8sClient"`
|
||||
}
|
||||
|
|
|
@ -37,14 +37,22 @@ func Load(cmd *cobra.Command) (*Config, error) {
|
|||
log.Println("[INFO] No configuration file found")
|
||||
}
|
||||
|
||||
if flag := cmd.Flags().Lookup("kubeconfig"); flag != nil {
|
||||
v.BindPFlag("kubeconfig", flag)
|
||||
}
|
||||
|
||||
if flag := cmd.Flags().Lookup("worker"); flag != nil {
|
||||
v.BindPFlag("worker", flag)
|
||||
}
|
||||
|
||||
if flag := cmd.Flags().Lookup("kubeconfig"); flag != nil {
|
||||
v.BindPFlag("k8sClient.kubeconfig", flag)
|
||||
}
|
||||
|
||||
if flag := cmd.Flags().Lookup("qps"); flag != nil {
|
||||
v.BindPFlag("k8sClient.qps", flag)
|
||||
}
|
||||
|
||||
if flag := cmd.Flags().Lookup("burst"); flag != nil {
|
||||
v.BindPFlag("k8sClient.burst", flag)
|
||||
}
|
||||
|
||||
if flag := cmd.Flags().Lookup("port"); flag != nil {
|
||||
v.BindPFlag("api.port", flag)
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ func Test_Load(t *testing.T) {
|
|||
t.Errorf("Unexpected Error: %s", err)
|
||||
}
|
||||
|
||||
if c.Kubeconfig != "./config" {
|
||||
t.Errorf("Unexpected TemplateDir Config: %s", c.Kubeconfig)
|
||||
if c.K8sClient.Kubeconfig != "./config" {
|
||||
t.Errorf("Unexpected TemplateDir Config: %s", c.K8sClient.Kubeconfig)
|
||||
}
|
||||
if c.API.Port != 8081 {
|
||||
t.Errorf("Unexpected Port Config: %d", c.API.Port)
|
||||
|
|
Loading…
Reference in a new issue