Skip to content

Commit

Permalink
Add QPS and Burst options
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art committed Jan 18, 2024
1 parent 23dd1a0 commit 785fac1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/tools/k8s/kubeutils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -34,7 +34,12 @@ import (

// NewClientSetConfig creates ClientSetConfig from config file.
// If config file path not provided via env variable KUBECONFIG, default path "HOME/.kube/config" will be used
func NewClientSetConfig() (*rest.Config, error) {
func NewClientSetConfig(opts ...Option) (*rest.Config, error) {
o := &options{}
for _, opt := range opts {
opt(o)
}

configPath := os.Getenv("KUBECONFIG")
if configPath == "" {
configPath = filepath.Join(os.Getenv("HOME"), ".kube", "config")
Expand All @@ -48,13 +53,15 @@ func NewClientSetConfig() (*rest.Config, error) {
return nil, errors.Wrapf(err, "failed to build a config from a %s", configPath)
}
}
config.QPS = o.qps
config.Burst = o.burst

return config, nil
}

// NewVersionedClient creates a new networkservicemesh.io ClietSet for the default kubernetes config.
func NewVersionedClient() (versioned.Interface, *rest.Config, error) {
config, err := NewClientSetConfig()
func NewVersionedClient(opts ...Option) (versioned.Interface, *rest.Config, error) {
config, err := NewClientSetConfig(opts...)
if err != nil {
return nil, nil, err
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/tools/k8s/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package k8s

type options struct {
qps float32
burst int
}

// Option is an option pattern for NSM kubeutils
type Option func(o *options)

// WithQPS - sets k8s QPS
func WithQPS(q float32) Option {
return func(o *options) {
o.qps = q
}
}

// WithBurst - sets k8s burst
func WithBurst(b int) Option {
return func(o *options) {
o.burst = b
}
}

0 comments on commit 785fac1

Please sign in to comment.