forked from cnoe-io/idpbuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the cmd: get clusters to show the cluster and nodes and their…
… internal IP. Created a help function to create globally a kube client. cnoe-io#445 Signed-off-by: cmoulliard <[email protected]>
- Loading branch information
1 parent
8c6cd97
commit 7eee957
Showing
4 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package get | |
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/client-go/util/homedir" | ||
"path/filepath" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
var ( | ||
KubeConfigPath string | ||
scheme *runtime.Scheme | ||
) | ||
|
||
func GetKubeConfigPath() string { | ||
if KubeConfigPath == "" { | ||
return filepath.Join(homedir.HomeDir(), ".kube", "config") | ||
} else { | ||
return KubeConfigPath | ||
} | ||
} | ||
|
||
func GetKubeConfig() (*rest.Config, error) { | ||
kubeConfig, err := clientcmd.BuildConfigFromFlags("", GetKubeConfigPath()) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error building kubeconfig: %w", err) | ||
} | ||
return kubeConfig, nil | ||
} | ||
|
||
func GetKubeClient(kubeConfig *rest.Config) (client.Client, error) { | ||
kubeClient, err := client.New(kubeConfig, client.Options{Scheme: scheme}) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error creating kubernetes client: %w", err) | ||
} | ||
return kubeClient, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters