github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/cmd/ndm_daemonset/app/command/commands.go (about)

     1  /*
     2  Copyright 2018 The OpenEBS Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package command
    18  
    19  import (
    20  	goflag "flag"
    21  
    22  	"github.com/openebs/node-disk-manager/cmd/ndm_daemonset/controller"
    23  	"github.com/openebs/node-disk-manager/pkg/features"
    24  	"github.com/openebs/node-disk-manager/pkg/util"
    25  	"github.com/openebs/node-disk-manager/pkg/version"
    26  
    27  	"github.com/spf13/cobra"
    28  	"github.com/spf13/pflag"
    29  	"k8s.io/klog/v2"
    30  )
    31  
    32  // options is the options with which the daemon is to be run
    33  var options controller.NDMOptions
    34  
    35  // NewNodeDiskManager creates a new ndm.
    36  func NewNodeDiskManager() (*cobra.Command, error) {
    37  
    38  	// Create a new command
    39  	cmd := &cobra.Command{
    40  		Use:   "ndm",
    41  		Short: "ndm controls the Node-Disk-Manager ",
    42  		PersistentPreRun: func(cmd *cobra.Command, args []string) {
    43  			util.CheckErr(RunNodeDiskManager(cmd), util.Fatal)
    44  
    45  			// set the feature gates on NDM daemon
    46  			err := features.FeatureGates.SetFeatureFlag(options.FeatureGate)
    47  			if err != nil {
    48  				klog.Fatalf("error setting feature gate: %v", err)
    49  			}
    50  		},
    51  	}
    52  
    53  	pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
    54  	cmd.PersistentFlags().StringVar(&options.ConfigFilePath, "config",
    55  		controller.DefaultConfigFilePath,
    56  		"Path to config file")
    57  	cmd.PersistentFlags().StringSliceVar(&options.FeatureGate, "feature-gates",
    58  		nil,
    59  		"FeatureGates to be enabled or disabled")
    60  	_ = goflag.CommandLine.Parse([]string{})
    61  
    62  	cmd.AddCommand(
    63  		NewCmdBlockDevice(), //Add new command on block device
    64  		NewCmdStart(),       //Add new command to start the ndm controller
    65  	)
    66  
    67  	return cmd, nil
    68  }
    69  
    70  // RunNodeDiskManager logs the starting of NDM daemon
    71  func RunNodeDiskManager(cmd *cobra.Command) error {
    72  	klog.Infof("Starting Node Device Manager Daemon...")
    73  	klog.Infof("Version Tag : %s", version.GetVersion())
    74  	klog.Infof("GitCommit : %s", version.GetGitCommit())
    75  	return nil
    76  }