Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance and efficiency improvements in daemon/server mode #1154

Merged
merged 13 commits into from
Sep 15, 2023
Merged
15 changes: 8 additions & 7 deletions pkg/k8sclient/k8sclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@s1061123 just want to make sure this approach works with your incoming changes?

}

// GetK8sClient gets client info from kubeconfig
Expand Down Expand Up @@ -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
Expand Down