Skip to content

Commit

Permalink
add options
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
  • Loading branch information
Pavel Okhlopkov committed Nov 6, 2024
1 parent 89d1fe8 commit aedb66a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,27 @@ const (
kubeNamespaceFilePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
)

// TODO: refactor with methods
func New(logger *log.Logger) *Client {
return &Client{
logger: logger.With("operator.component", "KubernetesAPIClient"),
type Option func(client *Client)

func WithLogger(logger *log.Logger) Option {
return func(client *Client) {
client.logger = logger.With("operator.component", "KubernetesAPIClient")
}
}

// TODO: refactor all "with" methods
func New(opts ...Option) *Client {
c := &Client{}

for _, fn := range opts {
fn(c)
}

if c.logger == nil {
c.logger = log.NewLogger(log.Options{}).Named("kubernetes-api-client").With("operator.component", "KubernetesAPIClient")
}

return c
}

func NewFake(gvr map[schema.GroupVersionResource]string) *Client {
Expand Down

0 comments on commit aedb66a

Please sign in to comment.