Skip to content

Commit

Permalink
use KUBECONFIG when users specify it
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Zhang <jiazha@redhat.com>
  • Loading branch information
jianzhangbjz committed Aug 14, 2023
1 parent 1a0ae1a commit 612cab9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ func (c *Client) GetRestClient() rest.Interface {

func NewClient(kubecontext string, kubeconfig string) (*Client, error) {
var config *rest.Config
config, err := rest.InClusterConfig()
if err != nil {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()

if kubeconfig != "" {
loadingRules.ExplicitPath = kubeconfig
}
var err error

if kubeconfig != "" {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
loadingRules.ExplicitPath = kubeconfig
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
loadingRules,
&clientcmd.ConfigOverrides{
Expand All @@ -54,7 +51,13 @@ func NewClient(kubecontext string, kubeconfig string) (*Client, error) {
if err != nil {
return nil, err
}
} else {
config, err = rest.InClusterConfig()
if err != nil {
return nil, err
}
}

clientSet, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
Expand Down

0 comments on commit 612cab9

Please sign in to comment.