mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 07:57:07 +00:00
* feat: add dynamic client support to internal cmd package Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * Update cmd/internal/client.go Signed-off-by: shuting <shutting06@gmail.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: shuting <shutting06@gmail.com> Co-authored-by: shuting <shutting06@gmail.com>
79 lines
1.4 KiB
Go
79 lines
1.4 KiB
Go
package internal
|
|
|
|
import "flag"
|
|
|
|
type Configuration interface {
|
|
UsesMetrics() bool
|
|
UsesTracing() bool
|
|
UsesProfiling() bool
|
|
UsesKubeconfig() bool
|
|
FlagSets() []*flag.FlagSet
|
|
}
|
|
|
|
func NewConfiguration(options ...ConfigurationOption) Configuration {
|
|
c := &configuration{}
|
|
for _, option := range options {
|
|
option(c)
|
|
}
|
|
return c
|
|
}
|
|
|
|
type ConfigurationOption func(c *configuration)
|
|
|
|
func WithMetrics() ConfigurationOption {
|
|
return func(c *configuration) {
|
|
c.usesMetrics = true
|
|
}
|
|
}
|
|
|
|
func WithTracing() ConfigurationOption {
|
|
return func(c *configuration) {
|
|
c.usesTracing = true
|
|
}
|
|
}
|
|
|
|
func WithProfiling() ConfigurationOption {
|
|
return func(c *configuration) {
|
|
c.usesProfiling = true
|
|
}
|
|
}
|
|
|
|
func WithKubeconfig() ConfigurationOption {
|
|
return func(c *configuration) {
|
|
c.usesKubeconfig = true
|
|
}
|
|
}
|
|
|
|
func WithFlagSets(flagsets ...*flag.FlagSet) ConfigurationOption {
|
|
return func(c *configuration) {
|
|
c.flagSets = append(c.flagSets, flagsets...)
|
|
}
|
|
}
|
|
|
|
type configuration struct {
|
|
usesMetrics bool
|
|
usesTracing bool
|
|
usesProfiling bool
|
|
usesKubeconfig bool
|
|
flagSets []*flag.FlagSet
|
|
}
|
|
|
|
func (c *configuration) UsesMetrics() bool {
|
|
return c.usesMetrics
|
|
}
|
|
|
|
func (c *configuration) UsesTracing() bool {
|
|
return c.usesTracing
|
|
}
|
|
|
|
func (c *configuration) UsesProfiling() bool {
|
|
return c.usesProfiling
|
|
}
|
|
|
|
func (c *configuration) UsesKubeconfig() bool {
|
|
return c.usesKubeconfig
|
|
}
|
|
|
|
func (c *configuration) FlagSets() []*flag.FlagSet {
|
|
return c.flagSets
|
|
}
|