diff --git a/pkg/apihelper/k8shelpers.go b/pkg/apihelper/k8shelpers.go index ee9838fa6..4943f0fb9 100644 --- a/pkg/apihelper/k8shelpers.go +++ b/pkg/apihelper/k8shelpers.go @@ -26,7 +26,6 @@ import ( "k8s.io/apimachinery/pkg/types" k8sclient "k8s.io/client-go/kubernetes" restclient "k8s.io/client-go/rest" - "k8s.io/client-go/tools/clientcmd" ) // K8sHelpers implements APIHelpers @@ -110,11 +109,3 @@ func (h K8sHelpers) GetPod(cli *k8sclient.Clientset, namespace string, podName s return pod, nil } - -// GetKubeconfig returns the kubeconfig for the cluster -func GetKubeconfig(path string) (*restclient.Config, error) { - if path == "" { - return restclient.InClusterConfig() - } - return clientcmd.BuildConfigFromFlags("", path) -} diff --git a/pkg/nfd-gc/nfd-gc.go b/pkg/nfd-gc/nfd-gc.go index ac48805ab..00cc33e10 100644 --- a/pkg/nfd-gc/nfd-gc.go +++ b/pkg/nfd-gc/nfd-gc.go @@ -31,7 +31,6 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" - "sigs.k8s.io/node-feature-discovery/pkg/apihelper" nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1" nfdclientset "sigs.k8s.io/node-feature-discovery/pkg/generated/clientset/versioned" "sigs.k8s.io/node-feature-discovery/pkg/utils" @@ -59,7 +58,7 @@ type nfdGarbageCollector struct { } func New(args *Args) (NfdGarbageCollector, error) { - kubeconfig, err := apihelper.GetKubeconfig(args.Kubeconfig) + kubeconfig, err := utils.GetKubeconfig(args.Kubeconfig) if err != nil { return nil, err } diff --git a/pkg/nfd-master/nfd-master.go b/pkg/nfd-master/nfd-master.go index ae501a6cf..168867d2b 100644 --- a/pkg/nfd-master/nfd-master.go +++ b/pkg/nfd-master/nfd-master.go @@ -1140,7 +1140,7 @@ func (m *nfdMaster) updateNodeObject(cli *kubernetes.Clientset, nodeName string, func (m *nfdMaster) getKubeconfig() (*restclient.Config, error) { var err error if m.kubeconfig == nil { - m.kubeconfig, err = apihelper.GetKubeconfig(m.args.Kubeconfig) + m.kubeconfig, err = utils.GetKubeconfig(m.args.Kubeconfig) } return m.kubeconfig, err } diff --git a/pkg/nfd-topology-updater/nfd-topology-updater.go b/pkg/nfd-topology-updater/nfd-topology-updater.go index 8ebd71fd5..102597d81 100644 --- a/pkg/nfd-topology-updater/nfd-topology-updater.go +++ b/pkg/nfd-topology-updater/nfd-topology-updater.go @@ -131,7 +131,7 @@ func (w *nfdTopologyUpdater) Run() error { return fmt.Errorf("failed to get PodResource Client: %w", err) } - kubeconfig, err := apihelper.GetKubeconfig(w.args.KubeConfigFile) + kubeconfig, err := utils.GetKubeconfig(w.args.KubeConfigFile) if err != nil { return err } diff --git a/pkg/nfd-worker/nfd-worker.go b/pkg/nfd-worker/nfd-worker.go index ed3dfbf55..99ee50859 100644 --- a/pkg/nfd-worker/nfd-worker.go +++ b/pkg/nfd-worker/nfd-worker.go @@ -42,7 +42,6 @@ import ( apiequality "k8s.io/apimachinery/pkg/api/equality" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/node-feature-discovery/pkg/apihelper" nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1" nfdclient "sigs.k8s.io/node-feature-discovery/pkg/generated/clientset/versioned" pb "sigs.k8s.io/node-feature-discovery/pkg/labeler" @@ -747,7 +746,7 @@ func (m *nfdWorker) getNfdClient() (*nfdclient.Clientset, error) { return m.nfdClient, nil } - kubeconfig, err := apihelper.GetKubeconfig(m.args.Kubeconfig) + kubeconfig, err := utils.GetKubeconfig(m.args.Kubeconfig) if err != nil { return nil, err } diff --git a/pkg/utils/kubernetes.go b/pkg/utils/kubernetes.go index 7601da0fc..13af9336d 100644 --- a/pkg/utils/kubernetes.go +++ b/pkg/utils/kubernetes.go @@ -19,6 +19,9 @@ package utils import ( "os" "strings" + + restclient "k8s.io/client-go/rest" + "k8s.io/client-go/tools/clientcmd" ) var nodeName string @@ -43,3 +46,11 @@ func GetKubernetesNamespace() string { } return os.Getenv("KUBERNETES_NAMESPACE") } + +// GetKubeconfig returns the kubeconfig for the cluster +func GetKubeconfig(path string) (*restclient.Config, error) { + if path == "" { + return restclient.InClusterConfig() + } + return clientcmd.BuildConfigFromFlags("", path) +}