Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QPS and Burst options #484

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
41 changes: 41 additions & 0 deletions pkg/tools/k8s/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 - QPS indicates the maximum QPS to the master from this client.
// See: https://github.com/kubernetes/client-go/blob/v0.28.3/rest/config.go#L116
func WithQPS(q float32) Option {
glazychev-art marked this conversation as resolved.
Show resolved Hide resolved
return func(o *options) {
o.qps = q
}
}

// WithBurst - sets maximum burst for throttle
// See: https://github.com/kubernetes/client-go/blob/v0.28.3/rest/config.go#L120
func WithBurst(b int) Option {
glazychev-art marked this conversation as resolved.
Show resolved Hide resolved
return func(o *options) {
o.burst = b
}
}
Loading