Skip to content

Commit

Permalink
feat: use in cluster config
Browse files Browse the repository at this point in the history
  • Loading branch information
vsukhin committed Mar 27, 2024
1 parent 54435a3 commit 425e197
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions pkg/api/v1/client/proxy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ import (

// GetClientSet configures Kube client set, can override host with local proxy
func GetClientSet(overrideHost string) (clientset kubernetes.Interface, err error) {
clcfg, err := clientcmd.NewDefaultClientConfigLoadingRules().Load()
if err != nil {
return clientset, errors.Wrap(err, "failed to get clientset config")
// creates the in-cluster config
restcfg, err := rest.InClusterConfig()
if err != nil && err != rest.ErrNotInCluster {
return clientset, errors.Wrap(err, "failed to get in cluster config")
}

restcfg, err := clientcmd.NewNonInteractiveClientConfig(
*clcfg, "", &clientcmd.ConfigOverrides{}, nil).ClientConfig()
if err != nil {
return clientset, errors.Wrap(err, "failed to get non-interactive client config")
}
clcfg, err := clientcmd.NewDefaultClientConfigLoadingRules().Load()
if err != nil {
return clientset, errors.Wrap(err, "failed to get clientset config")
}

// override host is needed to override kubeconfig kubernetes proxy host name
// to local proxy passed to API server run local proxy first by `make api-proxy`
if overrideHost != "" {
restcfg.Host = overrideHost
restcfg, err = clientcmd.NewNonInteractiveClientConfig(
*clcfg, "", &clientcmd.ConfigOverrides{}, nil).ClientConfig()
if err != nil {
return clientset, errors.Wrap(err, "failed to get non-interactive client config")
}

// override host is needed to override kubeconfig kubernetes proxy host name
// to local proxy passed to API server run local proxy first by `make api-proxy`
if overrideHost != "" {
restcfg.Host = overrideHost
}
}

return kubernetes.NewForConfig(restcfg)
Expand Down

0 comments on commit 425e197

Please sign in to comment.