Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/utils: move GetKubeconfig from pkg/apihelper here #1562

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions pkg/apihelper/k8shelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions pkg/nfd-gc/nfd-gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"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"
Expand Down Expand Up @@ -59,7 +58,7 @@
}

func New(args *Args) (NfdGarbageCollector, error) {
kubeconfig, err := apihelper.GetKubeconfig(args.Kubeconfig)
kubeconfig, err := utils.GetKubeconfig(args.Kubeconfig)

Check warning on line 61 in pkg/nfd-gc/nfd-gc.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-gc/nfd-gc.go#L61

Added line #L61 was not covered by tests
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@
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)

Check warning on line 1143 in pkg/nfd-master/nfd-master.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-master/nfd-master.go#L1143

Added line #L1143 was not covered by tests
}
return m.kubeconfig, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/nfd-topology-updater/nfd-topology-updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
return fmt.Errorf("failed to get PodResource Client: %w", err)
}

kubeconfig, err := apihelper.GetKubeconfig(w.args.KubeConfigFile)
kubeconfig, err := utils.GetKubeconfig(w.args.KubeConfigFile)

Check warning on line 134 in pkg/nfd-topology-updater/nfd-topology-updater.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-topology-updater/nfd-topology-updater.go#L134

Added line #L134 was not covered by tests
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/nfd-worker/nfd-worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

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"
Expand Down Expand Up @@ -747,7 +746,7 @@
return m.nfdClient, nil
}

kubeconfig, err := apihelper.GetKubeconfig(m.args.Kubeconfig)
kubeconfig, err := utils.GetKubeconfig(m.args.Kubeconfig)

Check warning on line 749 in pkg/nfd-worker/nfd-worker.go

View check run for this annotation

Codecov / codecov/patch

pkg/nfd-worker/nfd-worker.go#L749

Added line #L749 was not covered by tests
if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/utils/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import (
"os"
"strings"

restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

var nodeName string
Expand All @@ -43,3 +46,11 @@
}
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)

Check warning on line 55 in pkg/utils/kubernetes.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/kubernetes.go#L51-L55

Added lines #L51 - L55 were not covered by tests
}