fix: fixup multi problem
This commit is contained in:
@@ -8,19 +8,18 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
metricsclient "k8s.io/metrics/pkg/client/clientset/versioned"
|
||||
)
|
||||
|
||||
func NewClient(cfg *config.Config) (*kubernetes.Clientset, error) {
|
||||
var (
|
||||
k8sCfg *rest.Config
|
||||
err error
|
||||
)
|
||||
|
||||
func restConfig(cfg *config.Config) (*rest.Config, error) {
|
||||
if cfg.Kubeconfig != "" {
|
||||
k8sCfg, err = clientcmd.BuildConfigFromFlags("", cfg.Kubeconfig)
|
||||
} else {
|
||||
k8sCfg, err = rest.InClusterConfig()
|
||||
return clientcmd.BuildConfigFromFlags("", cfg.Kubeconfig)
|
||||
}
|
||||
return rest.InClusterConfig()
|
||||
}
|
||||
|
||||
func NewClient(cfg *config.Config) (*kubernetes.Clientset, error) {
|
||||
k8sCfg, err := restConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("k8s config: %w", err)
|
||||
}
|
||||
@@ -32,3 +31,19 @@ func NewClient(cfg *config.Config) (*kubernetes.Clientset, error) {
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// NewMetricsClient crée un client pour l'API metrics.k8s.io (metrics-server),
|
||||
// utilisée pour lire l'usage CPU/mémoire en direct des pods.
|
||||
func NewMetricsClient(cfg *config.Config) (*metricsclient.Clientset, error) {
|
||||
k8sCfg, err := restConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("k8s config: %w", err)
|
||||
}
|
||||
|
||||
client, err := metricsclient.NewForConfig(k8sCfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("metrics clientset: %w", err)
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user