Skip to content

Commit 2c9d7c6

Browse files
authored
feat: allow end-users to adjust K8S client QPS and burst (aquasecurity#5910)
1 parent ffe2ca7 commit 2c9d7c6

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

docs/docs/references/configuration/cli/trivy_kubernetes.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ trivy kubernetes [flags] { cluster | all | specific resources like kubectl. eg:
2828

2929
```
3030
-A, --all-namespaces fetch resources from all cluster namespaces
31+
--burst int specify the maximum burst for throttle (default 10)
3132
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
3233
--cache-ttl duration cache TTL when using redis as cache backend
3334
--clear-cache clear image caches without scanning
@@ -72,6 +73,7 @@ trivy kubernetes [flags] { cluster | all | specific resources like kubectl. eg:
7273
--password strings password. Comma-separated passwords allowed. TRIVY_PASSWORD should be used for security reasons.
7374
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
7475
--policy-namespaces strings Rego namespaces
76+
--qps float specify the maximum QPS to the master from this client (default 5)
7577
--redis-ca string redis ca file location, if using redis as cache backend
7678
--redis-cert string redis certificate file location, if using redis as cache backend
7779
--redis-key string redis key file location, if using redis as cache backend

pkg/flag/kubernetes_flags.go

+20
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ var (
8888
Default: "ghcr.io/aquasecurity/node-collector:0.0.9",
8989
Usage: "indicate the image reference for the node-collector scan job",
9090
}
91+
QPS = Flag{
92+
Name: "qps",
93+
ConfigName: "kubernetes.qps",
94+
Default: 5.0,
95+
Usage: "specify the maximum QPS to the master from this client",
96+
}
97+
Burst = Flag{
98+
Name: "burst",
99+
ConfigName: "kubernetes.burst",
100+
Default: 10,
101+
Usage: "specify the maximum burst for throttle",
102+
}
91103
)
92104

93105
type K8sFlagGroup struct {
@@ -102,6 +114,8 @@ type K8sFlagGroup struct {
102114
NodeCollectorNamespace *Flag
103115
ExcludeOwned *Flag
104116
ExcludeNodes *Flag
117+
QPS *Flag
118+
Burst *Flag
105119
}
106120

107121
type K8sOptions struct {
@@ -116,6 +130,8 @@ type K8sOptions struct {
116130
NodeCollectorNamespace string
117131
ExcludeOwned bool
118132
ExcludeNodes map[string]string
133+
QPS float32
134+
Burst int
119135
}
120136

121137
func NewK8sFlagGroup() *K8sFlagGroup {
@@ -131,6 +147,8 @@ func NewK8sFlagGroup() *K8sFlagGroup {
131147
ExcludeOwned: &ExcludeOwned,
132148
ExcludeNodes: &ExcludeNodes,
133149
NodeCollectorImageRef: &NodeCollectorImageRef,
150+
QPS: &QPS,
151+
Burst: &Burst,
134152
}
135153
}
136154

@@ -151,6 +169,8 @@ func (f *K8sFlagGroup) Flags() []*Flag {
151169
f.ExcludeOwned,
152170
f.ExcludeNodes,
153171
f.NodeCollectorImageRef,
172+
f.QPS,
173+
f.Burst,
154174
}
155175
}
156176

pkg/k8s/commands/run.go

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func Run(ctx context.Context, args []string, opts flag.Options) error {
3030
cluster, err := k8s.GetCluster(
3131
k8s.WithContext(opts.K8sOptions.ClusterContext),
3232
k8s.WithKubeConfig(opts.K8sOptions.KubeConfig),
33+
k8s.WithBurst(opts.K8sOptions.Burst),
34+
k8s.WithQPS(opts.K8sOptions.QPS),
3335
)
3436
if err != nil {
3537
return xerrors.Errorf("failed getting k8s cluster: %w", err)

0 commit comments

Comments
 (0)