2019-01-11 13:55:28 +00:00
/ *
2021-02-19 05:38:55 +00:00
Copyright 2019 - 2021 The Kubernetes Authors .
2019-01-11 13:55:28 +00:00
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
package main
import (
2021-02-19 05:38:55 +00:00
"flag"
2019-01-11 13:55:28 +00:00
"fmt"
2021-02-19 05:38:55 +00:00
"os"
2019-01-11 13:55:28 +00:00
"regexp"
2021-02-19 09:03:16 +00:00
"k8s.io/klog/v2"
2019-02-08 19:43:54 +00:00
master "sigs.k8s.io/node-feature-discovery/pkg/nfd-master"
2021-02-19 05:38:55 +00:00
"sigs.k8s.io/node-feature-discovery/pkg/utils"
2019-01-11 13:55:28 +00:00
"sigs.k8s.io/node-feature-discovery/pkg/version"
)
const (
// ProgramName is the canonical name of this program
ProgramName = "nfd-master"
)
func main ( ) {
2021-02-19 05:38:55 +00:00
flags := flag . NewFlagSet ( ProgramName , flag . ExitOnError )
printVersion := flags . Bool ( "version" , false , "Print version and exit." )
args := initFlags ( flags )
2021-02-19 09:03:16 +00:00
// Inject klog flags
klog . InitFlags ( flags )
2021-02-19 05:38:55 +00:00
_ = flags . Parse ( os . Args [ 1 : ] )
if len ( flags . Args ( ) ) > 0 {
2021-02-25 17:12:06 +00:00
fmt . Fprintf ( flags . Output ( ) , "unknown command line argument: %s\n" , flags . Args ( ) [ 0 ] )
2021-02-19 05:38:55 +00:00
flags . Usage ( )
os . Exit ( 2 )
}
if * printVersion {
fmt . Println ( ProgramName , version . Get ( ) )
os . Exit ( 0 )
}
2019-01-11 13:55:28 +00:00
// Assert that the version is known
2020-03-20 05:21:43 +00:00
if version . Undefined ( ) {
2021-02-25 16:15:17 +00:00
klog . Warningf ( "version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run." )
2019-01-11 13:55:28 +00:00
}
2021-03-05 12:44:44 +00:00
// Plug klog into grpc logging infrastructure
utils . ConfigureGrpcKlog ( )
2019-02-08 19:43:54 +00:00
// Get new NfdMaster instance
instance , err := master . NewNfdMaster ( args )
2019-01-11 13:55:28 +00:00
if err != nil {
2021-02-25 17:12:06 +00:00
klog . Exitf ( "failed to initialize NfdMaster instance: %v" , err )
2019-01-11 13:55:28 +00:00
}
2019-01-29 14:21:48 +00:00
2019-02-08 19:43:54 +00:00
if err = instance . Run ( ) ; err != nil {
2021-02-25 16:15:17 +00:00
klog . Exit ( err )
2019-01-29 14:21:48 +00:00
}
2019-01-11 13:55:28 +00:00
}
2021-02-19 05:38:55 +00:00
func initFlags ( flagset * flag . FlagSet ) * master . Args {
args := & master . Args {
LabelWhiteList : utils . RegexpVal { Regexp : * regexp . MustCompile ( "" ) } ,
2020-08-12 18:28:21 +00:00
}
2019-01-11 13:55:28 +00:00
2021-02-19 05:38:55 +00:00
flagset . StringVar ( & args . CaFile , "ca-file" , "" ,
"Root certificate for verifying connections" )
flagset . StringVar ( & args . CertFile , "cert-file" , "" ,
"Certificate used for authenticating connections" )
flagset . Var ( & args . ExtraLabelNs , "extra-label-ns" ,
"Comma separated list of allowed extra label namespaces" )
flagset . StringVar ( & args . Instance , "instance" , "" ,
"Instance name. Used to separate annotation namespaces for multiple parallel deployments." )
flagset . StringVar ( & args . KeyFile , "key-file" , "" ,
"Private key matching -cert-file" )
flagset . StringVar ( & args . Kubeconfig , "kubeconfig" , "" ,
"Kubeconfig to use" )
flagset . Var ( & args . LabelWhiteList , "label-whitelist" ,
"Regular expression to filter label names to publish to the Kubernetes API server. " +
"NB: the label namespace is omitted i.e. the filter is only applied to the name part after '/'." )
flagset . BoolVar ( & args . NoPublish , "no-publish" , false ,
"Do not publish feature labels" )
flagset . IntVar ( & args . Port , "port" , 8080 ,
"Port on which to listen for connections." )
flagset . BoolVar ( & args . Prune , "prune" , false ,
"Prune all NFD related attributes from all nodes of the cluaster and exit." )
flagset . Var ( & args . ResourceLabels , "resource-labels" ,
"Comma separated list of labels to be exposed as extended resources." )
flagset . BoolVar ( & args . VerifyNodeName , "verify-node-name" , false ,
2021-04-20 08:44:32 +00:00
"Verify worker node name against the worker's TLS certificate. " +
2021-02-19 05:38:55 +00:00
"Only takes effect when TLS authentication has been enabled." )
return args
2019-01-11 13:55:28 +00:00
}