mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-26 13:29:11 +01:00
support client connection configuration to provide QPS and burst
This commit is contained in:
@@ -34,6 +34,7 @@ type DeschedulerConfiguration struct {
|
||||
|
||||
// KubeconfigFile is path to kubeconfig file with authorization and master
|
||||
// location information.
|
||||
// Deprecated: Use clientConnection.kubeConfig instead.
|
||||
KubeconfigFile string
|
||||
|
||||
// PolicyConfigFile is the filepath to the descheduler policy configuration.
|
||||
@@ -58,6 +59,10 @@ type DeschedulerConfiguration struct {
|
||||
LeaderElection componentbaseconfig.LeaderElectionConfiguration
|
||||
|
||||
// Logging specifies the options of logging.
|
||||
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/api/v1/options.go) for more information.
|
||||
// Refer to [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/api/v1/options.go) for more information.
|
||||
Logging registry.LoggingConfiguration
|
||||
|
||||
// ClientConnection specifies the kubeconfig file and client connection settings to use when communicating with the apiserver.
|
||||
// Refer to [ClientConnection](https://pkg.go.dev/k8s.io/kubernetes/pkg/apis/componentconfig#ClientConnectionConfiguration) for more information.
|
||||
ClientConnection componentbaseconfig.ClientConnectionConfiguration
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ type DeschedulerConfiguration struct {
|
||||
|
||||
// KubeconfigFile is path to kubeconfig file with authorization and master
|
||||
// location information.
|
||||
// Deprecated: Use clientConnection.kubeConfig instead.
|
||||
KubeconfigFile string `json:"kubeconfigFile"`
|
||||
|
||||
// PolicyConfigFile is the filepath to the descheduler policy configuration.
|
||||
@@ -58,6 +59,10 @@ type DeschedulerConfiguration struct {
|
||||
LeaderElection componentbaseconfig.LeaderElectionConfiguration `json:"leaderElection,omitempty"`
|
||||
|
||||
// Logging specifies the options of logging.
|
||||
// Refer [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/api/v1/options.go) for more information.
|
||||
// Refer to [Logs Options](https://github.com/kubernetes/component-base/blob/master/logs/api/v1/options.go) for more information.
|
||||
Logging registry.LoggingConfiguration `json:"logging,omitempty"`
|
||||
|
||||
// ClientConnection specifies the kubeconfig file and client connection settings to use when communicating with the apiserver.
|
||||
// Refer to [ClientConnection](https://pkg.go.dev/k8s.io/kubernetes/pkg/apis/componentconfig#ClientConnectionConfiguration) for more information.
|
||||
ClientConnection componentbaseconfig.ClientConnectionConfiguration `json:"clientConnection,omitempty"`
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ func autoConvert_v1alpha1_DeschedulerConfiguration_To_componentconfig_Deschedule
|
||||
out.IgnorePVCPods = in.IgnorePVCPods
|
||||
out.LeaderElection = in.LeaderElection
|
||||
out.Logging = in.Logging
|
||||
out.ClientConnection = in.ClientConnection
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -79,6 +80,7 @@ func autoConvert_componentconfig_DeschedulerConfiguration_To_v1alpha1_Deschedule
|
||||
out.IgnorePVCPods = in.IgnorePVCPods
|
||||
out.LeaderElection = in.LeaderElection
|
||||
out.Logging = in.Logging
|
||||
out.ClientConnection = in.ClientConnection
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ func (in *DeschedulerConfiguration) DeepCopyInto(out *DeschedulerConfiguration)
|
||||
out.TypeMeta = in.TypeMeta
|
||||
out.LeaderElection = in.LeaderElection
|
||||
in.Logging.DeepCopyInto(&out.Logging)
|
||||
out.ClientConnection = in.ClientConnection
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ func (in *DeschedulerConfiguration) DeepCopyInto(out *DeschedulerConfiguration)
|
||||
out.TypeMeta = in.TypeMeta
|
||||
out.LeaderElection = in.LeaderElection
|
||||
in.Logging.DeepCopyInto(&out.Logging)
|
||||
out.ClientConnection = in.ClientConnection
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -20,38 +20,43 @@ import (
|
||||
"fmt"
|
||||
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
|
||||
// Ensure to load all auth plugins.
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
func CreateClient(kubeconfig, userAgt string) (clientset.Interface, error) {
|
||||
func CreateClient(clientConnection componentbaseconfig.ClientConnectionConfiguration, userAgt string) (clientset.Interface, error) {
|
||||
var cfg *rest.Config
|
||||
if len(kubeconfig) != 0 {
|
||||
master, err := GetMasterFromKubeconfig(kubeconfig)
|
||||
if len(clientConnection.Kubeconfig) != 0 {
|
||||
master, err := GetMasterFromKubeconfig(clientConnection.Kubeconfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to parse kubeconfig file: %v ", err)
|
||||
return nil, fmt.Errorf("failed to parse kubeconfig file: %v ", err)
|
||||
}
|
||||
|
||||
cfg, err = clientcmd.BuildConfigFromFlags(master, kubeconfig)
|
||||
cfg, err = clientcmd.BuildConfigFromFlags(master, clientConnection.Kubeconfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to build config: %v", err)
|
||||
return nil, fmt.Errorf("unable to build config: %v", err)
|
||||
}
|
||||
|
||||
} else {
|
||||
var err error
|
||||
cfg, err = rest.InClusterConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unable to build in cluster config: %v", err)
|
||||
return nil, fmt.Errorf("unable to build in cluster config: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
cfg.Burst = int(clientConnection.Burst)
|
||||
cfg.QPS = clientConnection.QPS
|
||||
|
||||
if len(userAgt) != 0 {
|
||||
return clientset.NewForConfig(rest.AddUserAgent(cfg, userAgt))
|
||||
} else {
|
||||
return clientset.NewForConfig(cfg)
|
||||
cfg = rest.AddUserAgent(cfg, userAgt)
|
||||
}
|
||||
|
||||
return clientset.NewForConfig(cfg)
|
||||
}
|
||||
|
||||
func GetMasterFromKubeconfig(filename string) (string, error) {
|
||||
@@ -62,11 +67,11 @@ func GetMasterFromKubeconfig(filename string) (string, error) {
|
||||
|
||||
context, ok := config.Contexts[config.CurrentContext]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("Failed to get master address from kubeconfig")
|
||||
return "", fmt.Errorf("failed to get master address from kubeconfig")
|
||||
}
|
||||
|
||||
if val, ok := config.Clusters[context.Cluster]; ok {
|
||||
return val.Server, nil
|
||||
}
|
||||
return "", fmt.Errorf("Failed to get master address from kubeconfig")
|
||||
return "", fmt.Errorf("failed to get master address from kubeconfig")
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
@@ -52,7 +53,11 @@ import (
|
||||
func Run(ctx context.Context, rs *options.DeschedulerServer) error {
|
||||
metrics.Register()
|
||||
|
||||
rsclient, eventClient, err := createClients(rs.KubeconfigFile)
|
||||
clientConnection := rs.ClientConnection
|
||||
if rs.KubeconfigFile != "" && clientConnection.Kubeconfig == "" {
|
||||
clientConnection.Kubeconfig = rs.KubeconfigFile
|
||||
}
|
||||
rsclient, eventClient, err := createClients(clientConnection)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -425,13 +430,13 @@ func getPluginConfig(pluginName string, pluginConfigs []api.PluginConfig) *api.P
|
||||
return nil
|
||||
}
|
||||
|
||||
func createClients(kubeconfig string) (clientset.Interface, clientset.Interface, error) {
|
||||
kClient, err := client.CreateClient(kubeconfig, "descheduler")
|
||||
func createClients(clientConnection componentbaseconfig.ClientConnectionConfiguration) (clientset.Interface, clientset.Interface, error) {
|
||||
kClient, err := client.CreateClient(clientConnection, "descheduler")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
eventClient, err := client.CreateClient(kubeconfig, "")
|
||||
eventClient, err := client.CreateClient(clientConnection, "")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user