Support check command with multiple config files
Resolves: #472 Signed-off-by: Alexei Ledenev <alexei.led@gmail.com>
This commit is contained in:
@@ -28,7 +28,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
var checkCmd = &cobra.Command{
|
||||
@@ -133,7 +132,7 @@ func kubectlCheck(ctx context.Context, version string) bool {
|
||||
}
|
||||
|
||||
func kubernetesCheck(version string) bool {
|
||||
cfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
|
||||
cfg, err := utils.KubeConfig(kubeconfig, kubecontext)
|
||||
if err != nil {
|
||||
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
|
||||
return false
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
apiruntime "k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/kustomize/api/filesys"
|
||||
@@ -134,7 +135,7 @@ func ExecTemplate(obj interface{}, tmpl, filename string) error {
|
||||
return file.Sync()
|
||||
}
|
||||
|
||||
func KubeClient(kubeConfigPath string, kubeContext string) (client.Client, error) {
|
||||
func KubeConfig(kubeConfigPath string, kubeContext string) (*rest.Config, error) {
|
||||
configFiles := SplitKubeConfigPath(kubeConfigPath)
|
||||
configOverrides := clientcmd.ConfigOverrides{}
|
||||
|
||||
@@ -147,6 +148,15 @@ func KubeClient(kubeConfigPath string, kubeContext string) (client.Client, error
|
||||
&configOverrides,
|
||||
).ClientConfig()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("kubernetes configuration load failed: %w", err)
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func KubeClient(kubeConfigPath string, kubeContext string) (client.Client, error) {
|
||||
cfg, err := KubeConfig(kubeConfigPath, kubeContext)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("kubernetes client initialization failed: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user