From fff8519517e33d320c035fced3ab2690f5ab6ae5 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 8 Sep 2023 08:35:16 -0500 Subject: [PATCH] k8sclient: make InClusterK8sClient() call GetK8sClient() We want the in-cluster client that the multus server uses to use the same client config (QPS, protobuf, grpc, etc) as the regular client. Signed-off-by: Dan Williams --- pkg/k8sclient/k8sclient.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/k8sclient/k8sclient.go b/pkg/k8sclient/k8sclient.go index 5d5b4e154..7de8e79d0 100644 --- a/pkg/k8sclient/k8sclient.go +++ b/pkg/k8sclient/k8sclient.go @@ -396,13 +396,14 @@ func TryLoadPodDelegates(pod *v1.Pod, conf *types.NetConf, clientInfo *ClientInf // InClusterK8sClient returns the `k8s.ClientInfo` struct to use to connect to // the k8s API. func InClusterK8sClient() (*ClientInfo, error) { - config, err := rest.InClusterConfig() + clientInfo, err := GetK8sClient("", nil) if err != nil { return nil, err } - - logging.Debugf("InClusterK8sClient: in cluster config: %+v", config) - return NewClientInfo(config) + if clientInfo == nil { + return nil, fmt.Errorf("failed to create in-cluster kube client") + } + return clientInfo, err } // GetK8sClient gets client info from kubeconfig @@ -441,12 +442,12 @@ func GetK8sClient(kubeconfig string, kubeClient *ClientInfo) (*ClientInfo, error // Set the config timeout to one minute. config.Timeout = time.Minute - return NewClientInfo(config) + return newClientInfo(config) } -// NewClientInfo returns a `ClientInfo` from a configuration created from an +// newClientInfo returns a `ClientInfo` from a configuration created from an // existing kubeconfig file. -func NewClientInfo(config *rest.Config) (*ClientInfo, error) { +func newClientInfo(config *rest.Config) (*ClientInfo, error) { client, err := kubernetes.NewForConfig(config) if err != nil { return nil, err