Skip to content

Commit

Permalink
Configurable QPS and Burst for k8s clients
Browse files Browse the repository at this point in the history
  • Loading branch information
RaunakShah committed Jul 15, 2020
1 parent 9b4fc92 commit e365448
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
22 changes: 21 additions & 1 deletion cmd/csi-resizer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"context"
"flag"
"fmt"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"os"
"time"

Expand Down Expand Up @@ -54,6 +57,9 @@ var (
metricsAddress = flag.String("metrics-address", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")

kubeAPIQPS = flag.Float64("kube-api-qps", 5, "QPS to use while communicating with the kubernetes apiserver. Defaults to 5.0.")
kubeAPIBurst = flag.Int("kube-api-burst", 10, "Burst to use while communicating with the kubernetes apiserver. Defaults to 10.")

handleVolumeInUseError = flag.Bool("handle-volume-inuse-error", true, "Flag to turn on/off capability to handle volume in use error in resizer controller. Defaults to true if not set.")

version = "unknown"
Expand All @@ -70,7 +76,21 @@ func main() {
}
klog.Infof("Version : %s", version)

kubeClient, err := util.NewK8sClient(*master, *kubeConfig)
var config *rest.Config
var err error
if *master != "" || *kubeConfig != "" {
config, err = clientcmd.BuildConfigFromFlags(*master, *kubeConfig)
} else {
config, err = rest.InClusterConfig()
}
if err != nil {
klog.Fatal(err.Error())
}

config.QPS = float32(*kubeAPIQPS)
config.Burst = *kubeAPIBurst

kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
klog.Fatal(err.Error())
}
Expand Down
23 changes: 1 addition & 22 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,21 @@ import (
"fmt"
"regexp"

v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

var knownResizeConditions = map[v1.PersistentVolumeClaimConditionType]bool{
v1.PersistentVolumeClaimResizing: true,
v1.PersistentVolumeClaimFileSystemResizePending: true,
}

// NewK8sClient is an utility function used to create a kubernetes sdk client.
func NewK8sClient(master, kubeConfig string) (kubernetes.Interface, error) {
var config *rest.Config
var err error
if master != "" || kubeConfig != "" {
config, err = clientcmd.BuildConfigFromFlags(master, kubeConfig)
} else {
config, err = rest.InClusterConfig()
}
if err != nil {
return nil, fmt.Errorf("failed to create config: %v", err)
}
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("failed to create client: %v", err)
}
return kubeClient, nil
}

// PVCKey returns an unique key of a PVC object,
func PVCKey(pvc *v1.PersistentVolumeClaim) string {
return fmt.Sprintf("%s/%s", pvc.Namespace, pvc.Name)
Expand Down

0 comments on commit e365448

Please sign in to comment.