2019-01-11 15:55:28 +02:00
/ *
2021-02-19 07:38:55 +02:00
Copyright 2019 - 2021 The Kubernetes Authors .
2019-01-11 15:55:28 +02: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 07:38:55 +02:00
"flag"
2019-01-11 15:55:28 +02:00
"fmt"
2021-02-19 07:38:55 +02:00
"os"
2023-04-15 16:11:59 +01:00
"time"
2019-01-11 15:55:28 +02:00
2021-02-19 11:03:16 +02:00
"k8s.io/klog/v2"
2019-02-08 21:43:54 +02:00
master "sigs.k8s.io/node-feature-discovery/pkg/nfd-master"
2021-02-19 07:38:55 +02:00
"sigs.k8s.io/node-feature-discovery/pkg/utils"
2019-01-11 15:55:28 +02: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 07:38:55 +02:00
flags := flag . NewFlagSet ( ProgramName , flag . ExitOnError )
printVersion := flags . Bool ( "version" , false , "Print version and exit." )
2023-03-05 22:56:46 +01:00
args , overrides := initFlags ( flags )
2021-02-19 11:03:16 +02:00
// Inject klog flags
klog . InitFlags ( flags )
2021-02-19 07:38:55 +02:00
_ = flags . Parse ( os . Args [ 1 : ] )
if len ( flags . Args ( ) ) > 0 {
2021-02-25 12:12:06 -05:00
fmt . Fprintf ( flags . Output ( ) , "unknown command line argument: %s\n" , flags . Args ( ) [ 0 ] )
2021-02-19 07:38:55 +02:00
flags . Usage ( )
os . Exit ( 2 )
}
2022-11-22 11:51:20 +02:00
// Check deprecated flags
flags . Visit ( func ( f * flag . Flag ) {
switch f . Name {
case "featurerules-controller" :
2023-04-28 09:23:38 +03:00
klog . InfoS ( "-featurerules-controller is deprecated, use '-crd-controller' flag instead" )
2023-03-05 22:56:46 +01:00
case "extra-label-ns" :
args . Overrides . ExtraLabelNs = overrides . ExtraLabelNs
case "deny-label-ns" :
args . Overrides . DenyLabelNs = overrides . DenyLabelNs
case "label-whitelist" :
args . Overrides . LabelWhiteList = overrides . LabelWhiteList
case "resource-labels" :
2023-04-28 09:23:38 +03:00
klog . InfoS ( "-resource-labels is deprecated, extended resources should be managed with NodeFeatureRule objects" )
2023-03-05 22:56:46 +01:00
args . Overrides . ResourceLabels = overrides . ResourceLabels
case "enable-taints" :
args . Overrides . EnableTaints = overrides . EnableTaints
case "no-publish" :
args . Overrides . NoPublish = overrides . NoPublish
2023-04-25 03:03:02 +02:00
case "resync-period" :
2023-04-15 16:11:59 +01:00
args . Overrides . ResyncPeriod = overrides . ResyncPeriod
2023-05-13 20:03:53 +01:00
case "nfd-api-parallelism" :
args . Overrides . NfdApiParallelism = overrides . NfdApiParallelism
2022-11-22 11:51:20 +02:00
}
} )
2021-02-19 07:38:55 +02:00
if * printVersion {
fmt . Println ( ProgramName , version . Get ( ) )
os . Exit ( 0 )
}
2019-01-11 15:55:28 +02:00
// Assert that the version is known
2020-03-20 07:21:43 +02:00
if version . Undefined ( ) {
2023-04-28 09:23:38 +03:00
klog . InfoS ( "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 15:55:28 +02:00
}
2021-03-05 14:44:44 +02:00
// Plug klog into grpc logging infrastructure
utils . ConfigureGrpcKlog ( )
2019-02-08 21:43:54 +02:00
// Get new NfdMaster instance
instance , err := master . NewNfdMaster ( args )
2019-01-11 15:55:28 +02:00
if err != nil {
2023-04-28 09:23:38 +03:00
klog . ErrorS ( err , "failed to initialize NfdMaster instance" )
os . Exit ( 1 )
2019-01-11 15:55:28 +02:00
}
2019-01-29 16:21:48 +02:00
2019-02-08 21:43:54 +02:00
if err = instance . Run ( ) ; err != nil {
2023-04-28 09:23:38 +03:00
klog . ErrorS ( err , "error while running" )
os . Exit ( 1 )
2019-01-29 16:21:48 +02:00
}
2019-01-11 15:55:28 +02:00
}
2023-03-05 22:56:46 +01:00
func initFlags ( flagset * flag . FlagSet ) ( * master . Args , * master . ConfigOverrideArgs ) {
args := & master . Args { }
2019-01-11 15:55:28 +02:00
2021-02-19 07:38:55 +02:00
flagset . StringVar ( & args . CaFile , "ca-file" , "" ,
"Root certificate for verifying connections" )
flagset . StringVar ( & args . CertFile , "cert-file" , "" ,
"Certificate used for authenticating connections" )
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" )
2023-03-05 22:56:46 +01:00
flagset . StringVar ( & args . ConfigFile , "config" , "/etc/kubernetes/node-feature-discovery/nfd-master.conf" ,
"Config file to use." )
2021-02-19 07:38:55 +02:00
flagset . StringVar ( & args . Kubeconfig , "kubeconfig" , "" ,
"Kubeconfig to use" )
2022-12-14 12:51:14 +02:00
flagset . BoolVar ( & args . EnableNodeFeatureApi , "enable-nodefeature-api" , false ,
2022-10-12 13:45:11 +03:00
"Enable the NodeFeature CRD API for receiving node features. This will automatically disable the gRPC communication." )
2022-11-22 11:51:20 +02:00
flagset . BoolVar ( & args . CrdController , "featurerules-controller" , true ,
"Enable NFD CRD API controller. DEPRECATED: use -crd-controller instead" )
flagset . BoolVar ( & args . CrdController , "crd-controller" , true ,
"Enable NFD CRD API controller for processing NodeFeature and NodeFeatureRule objects." )
2021-02-19 07:38:55 +02:00
flagset . IntVar ( & args . Port , "port" , 8080 ,
"Port on which to listen for connections." )
flagset . BoolVar ( & args . Prune , "prune" , false ,
2023-06-06 20:05:07 +02:00
"Prune all NFD related attributes from all nodes of the cluster and exit." )
2021-02-19 07:38:55 +02:00
flagset . BoolVar ( & args . VerifyNodeName , "verify-node-name" , false ,
2021-04-20 09:44:32 +01:00
"Verify worker node name against the worker's TLS certificate. " +
2021-02-19 07:38:55 +02:00
"Only takes effect when TLS authentication has been enabled." )
2023-03-05 22:56:46 +01:00
flagset . StringVar ( & args . Options , "options" , "" ,
"Specify config options from command line. Config options are specified " +
"in the same format as in the config file (i.e. json or yaml). These options" )
2023-05-05 12:01:32 +02:00
flagset . BoolVar ( & args . EnableLeaderElection , "enable-leader-election" , false ,
"Enables a leader election. Enable this when running more than one replica on nfd master." )
2023-03-05 22:56:46 +01:00
overrides := & master . ConfigOverrideArgs {
LabelWhiteList : & utils . RegexpVal { } ,
DenyLabelNs : & utils . StringSetVal { } ,
ExtraLabelNs : & utils . StringSetVal { } ,
ResourceLabels : & utils . StringSetVal { } ,
2023-04-15 16:11:59 +01:00
ResyncPeriod : & utils . DurationVal { Duration : time . Duration ( 1 ) * time . Hour } ,
2023-03-05 22:56:46 +01:00
}
flagset . Var ( overrides . ExtraLabelNs , "extra-label-ns" ,
"Comma separated list of allowed extra label namespaces" )
flagset . Var ( overrides . 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 '/'." )
overrides . EnableTaints = flagset . Bool ( "enable-taints" , false ,
"Enable node tainting feature" )
overrides . NoPublish = flagset . Bool ( "no-publish" , false ,
"Do not publish feature labels" )
flagset . Var ( overrides . DenyLabelNs , "deny-label-ns" ,
"Comma separated list of denied label namespaces" )
flagset . Var ( overrides . ResourceLabels , "resource-labels" ,
2023-04-13 11:14:43 +03:00
"Comma separated list of labels to be exposed as extended resources. DEPRECATED: use NodeFeatureRule objects instead" )
2023-04-15 16:11:59 +01:00
flagset . Var ( overrides . ResyncPeriod , "resync-period" ,
"Specify the NFD API controller resync period." +
"It has an effect when the NodeFeature API has been enabled (with -enable-nodefeature-api)." )
2023-05-13 20:03:53 +01:00
overrides . NfdApiParallelism = flagset . Int ( "nfd-api-parallelism" , 10 , "Defines the maximum number of goroutines responsible of updating nodes. " +
"Can be used for the throttling mechanism. It has effect only when -enable-nodefeature-api has been set." )
2023-03-05 22:56:46 +01:00
return args , overrides
2019-01-11 15:55:28 +02:00
}