mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-02 07:46:15 +00:00
fix: use kubeconfig file when user specify it (#605)
If user specify `--kubeconfig` when running k8sgpt, it should use the kubeconfig file to login the corresponding cluster instead of getting auth info via SA. Closes #604 Signed-off-by: Jian Zhang <jiazha@redhat.com>
This commit is contained in:
@@ -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 {
|
||||
var err error
|
||||
|
||||
if kubeconfig != "" {
|
||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
|
||||
if kubeconfig != "" {
|
||||
loadingRules.ExplicitPath = kubeconfig
|
||||
}
|
||||
|
||||
loadingRules.ExplicitPath = kubeconfig
|
||||
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
||||
loadingRules,
|
||||
&clientcmd.ConfigOverrides{
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user