1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

nfd-master: add --kubeconfig flag

Useful with --prune and for development purposes.
This commit is contained in:
Markus Lehtonen 2020-05-28 17:43:43 +03:00
parent 4669770020
commit 458dd8dc58
3 changed files with 17 additions and 2 deletions

View file

@ -66,6 +66,7 @@ func argsParse(argv []string) (master.Args, error) {
%s [--prune] [--no-publish] [--label-whitelist=<pattern>] [--port=<port>] %s [--prune] [--no-publish] [--label-whitelist=<pattern>] [--port=<port>]
[--ca-file=<path>] [--cert-file=<path>] [--key-file=<path>] [--ca-file=<path>] [--cert-file=<path>] [--key-file=<path>]
[--verify-node-name] [--extra-label-ns=<list>] [--resource-labels=<list>] [--verify-node-name] [--extra-label-ns=<list>] [--resource-labels=<list>]
[--kubeconfig=<path>]
%s -h | --help %s -h | --help
%s --version %s --version
@ -74,6 +75,8 @@ func argsParse(argv []string) (master.Args, error) {
--version Output version and exit. --version Output version and exit.
--prune Prune all NFD related attributes from all nodes --prune Prune all NFD related attributes from all nodes
of the cluster and exit. of the cluster and exit.
--kubeconfig=<path> Kubeconfig to use [Default: ]
of the cluster and exit.
--port=<port> Port on which to listen for connections. --port=<port> Port on which to listen for connections.
[Default: 8080] [Default: 8080]
--ca-file=<path> Root certificate for verifying connections --ca-file=<path> Root certificate for verifying connections
@ -122,6 +125,7 @@ func argsParse(argv []string) (master.Args, error) {
args.ExtraLabelNs = strings.Split(arguments["--extra-label-ns"].(string), ",") args.ExtraLabelNs = strings.Split(arguments["--extra-label-ns"].(string), ",")
args.ResourceLabels = strings.Split(arguments["--resource-labels"].(string), ",") args.ResourceLabels = strings.Split(arguments["--resource-labels"].(string), ",")
args.Prune = arguments["--prune"].(bool) args.Prune = arguments["--prune"].(bool)
args.Kubeconfig = arguments["--kubeconfig"].(string)
return args, nil return args, nil
} }

View file

@ -24,18 +24,28 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
k8sclient "k8s.io/client-go/kubernetes" k8sclient "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
) )
// Implements APIHelpers // Implements APIHelpers
type K8sHelpers struct { type K8sHelpers struct {
Kubeconfig string
} }
func (h K8sHelpers) GetClient() (*k8sclient.Clientset, error) { func (h K8sHelpers) GetClient() (*k8sclient.Clientset, error) {
// Set up an in-cluster K8S client. // Set up an in-cluster K8S client.
config, err := restclient.InClusterConfig() var config *restclient.Config
var err error
if h.Kubeconfig == "" {
config, err = restclient.InClusterConfig()
} else {
config, err = clientcmd.BuildConfigFromFlags("", h.Kubeconfig)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
clientset, err := k8sclient.NewForConfig(config) clientset, err := k8sclient.NewForConfig(config)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -70,6 +70,7 @@ type Args struct {
CertFile string CertFile string
ExtraLabelNs []string ExtraLabelNs []string
KeyFile string KeyFile string
Kubeconfig string
LabelWhiteList *regexp.Regexp LabelWhiteList *regexp.Regexp
NoPublish bool NoPublish bool
Port int Port int
@ -124,7 +125,7 @@ func NewNfdMaster(args Args) (NfdMaster, error) {
} }
// Initialize Kubernetes API helpers // Initialize Kubernetes API helpers
nfd.apihelper = apihelper.K8sHelpers{} nfd.apihelper = apihelper.K8sHelpers{Kubeconfig: args.Kubeconfig}
return nfd, nil return nfd, nil
} }