Skip to content

Commit

Permalink
chore: add function to combine multiple functions
Browse files Browse the repository at this point in the history
  • Loading branch information
thapabishwa committed Dec 9, 2023
1 parent 68e40eb commit 6483593
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions examples/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,34 @@ import (
"context"
)

func WithQPSBurst(qps float32, burst int) k8s.ClusterOption {
func WithQPS(qps float32) k8s.ClusterOption {
return func(o *genericclioptions.ConfigFlags) {
o.WrapConfigFn = func(c *rest.Config) *rest.Config {
o.WrapConfigFn = combineConfigFns(o.WrapConfigFn, func(c *rest.Config) *rest.Config {
c.QPS = qps
return c
})
}
}

func WithBurst(burst int) k8s.ClusterOption {
return func(o *genericclioptions.ConfigFlags) {
o.WrapConfigFn = combineConfigFns(o.WrapConfigFn, func(c *rest.Config) *rest.Config {
c.Burst = burst
return c
})
}
}

// Helper function to combine multiple config functions
func combineConfigFns(existing, newFn func(*rest.Config) *rest.Config) func(*rest.Config) *rest.Config {
if existing == nil {
return newFn
}
return func(c *rest.Config) *rest.Config {
if modified := existing(c); modified != nil {
return newFn(modified)
}
return newFn(c)
}
}

Expand All @@ -36,7 +57,7 @@ func main() {

ctx := context.Background()

cluster, err := k8s.GetCluster(WithQPSBurst(10000, 10000))
cluster, err := k8s.GetCluster(WithBurst(100), WithQPS(100))
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 6483593

Please sign in to comment.