diff --git a/cmd/flux/check.go b/cmd/flux/check.go index 4b553d22..42a48247 100644 --- a/cmd/flux/check.go +++ b/cmd/flux/check.go @@ -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 diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 47e1a401..fd38a9d9 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -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) }