mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-09 09:26:54 +00:00
* refactor: use typed informers and add tombstone support to webhookconfig Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * refactor: remove unstructured usage from webhookconfig Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * refactor: cert manager controller Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * refactor: move config controller in controllers package Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
33 lines
946 B
Go
33 lines
946 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
|
|
rest "k8s.io/client-go/rest"
|
|
clientcmd "k8s.io/client-go/tools/clientcmd"
|
|
)
|
|
|
|
// CreateClientConfig creates client config and applies rate limit QPS and burst
|
|
func CreateClientConfig(kubeconfig string, qps float64, burst int) (*rest.Config, error) {
|
|
clientConfig, err := createClientConfig(kubeconfig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if qps > math.MaxFloat32 {
|
|
return nil, fmt.Errorf("client rate limit QPS must not be higher than %e", math.MaxFloat32)
|
|
}
|
|
clientConfig.Burst = burst
|
|
clientConfig.QPS = float32(qps)
|
|
return clientConfig, nil
|
|
}
|
|
|
|
// createClientConfig creates client config
|
|
func createClientConfig(kubeconfig string) (*rest.Config, error) {
|
|
if kubeconfig == "" {
|
|
logger.Info("Using in-cluster configuration")
|
|
return rest.InClusterConfig()
|
|
}
|
|
logger.V(4).Info("Using specified kubeconfig", "kubeconfig", kubeconfig)
|
|
return clientcmd.BuildConfigFromFlags("", kubeconfig)
|
|
}
|