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 <dcbw@redhat.com>
This commit is contained in:
Dan Williams
2023-09-08 08:35:16 -05:00
parent 02ce071abb
commit fff8519517

View File

@@ -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 // InClusterK8sClient returns the `k8s.ClientInfo` struct to use to connect to
// the k8s API. // the k8s API.
func InClusterK8sClient() (*ClientInfo, error) { func InClusterK8sClient() (*ClientInfo, error) {
config, err := rest.InClusterConfig() clientInfo, err := GetK8sClient("", nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if clientInfo == nil {
logging.Debugf("InClusterK8sClient: in cluster config: %+v", config) return nil, fmt.Errorf("failed to create in-cluster kube client")
return NewClientInfo(config) }
return clientInfo, err
} }
// GetK8sClient gets client info from kubeconfig // 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. // Set the config timeout to one minute.
config.Timeout = time.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. // existing kubeconfig file.
func NewClientInfo(config *rest.Config) (*ClientInfo, error) { func newClientInfo(config *rest.Config) (*ClientInfo, error) {
client, err := kubernetes.NewForConfig(config) client, err := kubernetes.NewForConfig(config)
if err != nil { if err != nil {
return nil, err return nil, err