github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/cmd/ndm_daemonset/app/command/start.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 "fmt" 22 "os" 23 24 "github.com/openebs/node-disk-manager/cmd/ndm_daemonset/controller" 25 "github.com/openebs/node-disk-manager/cmd/ndm_daemonset/filter" 26 "github.com/openebs/node-disk-manager/cmd/ndm_daemonset/grpc" 27 "github.com/openebs/node-disk-manager/cmd/ndm_daemonset/probe" 28 "github.com/openebs/node-disk-manager/pkg/features" 29 30 "github.com/spf13/cobra" 31 "github.com/spf13/pflag" 32 ) 33 34 //NewCmdStart starts the ndm controller 35 func NewCmdStart() *cobra.Command { 36 37 //var target string 38 getCmd := &cobra.Command{ 39 Use: "start", 40 Short: "Node disk controller", 41 Long: ` watches for ndm custom resources via "ndm start" command `, 42 Run: func(cmd *cobra.Command, args []string) { 43 ctrl, err := controller.NewController() 44 if err != nil { 45 fmt.Println(err) 46 os.Exit(1) 47 } 48 49 isAPIServiceEnabled := features.FeatureGates.IsEnabled(features.APIService) 50 if isAPIServiceEnabled { 51 go grpc.Start() 52 } 53 // set the NDM config from the options 54 err = ctrl.SetControllerOptions(options) 55 if err != nil { 56 fmt.Println(err) 57 os.Exit(1) 58 } 59 // Broadcast starts broadcasting controller pointer. Using this 60 // each probe and filter registers themselves. 61 ctrl.Broadcast() 62 // Start starts registering of filters present in RegisteredFilters 63 filter.Start(filter.RegisteredFilters) 64 // Start starts registering of probes present in RegisteredProbes 65 probe.Start(probe.RegisteredProbes) 66 ctrl.Start() 67 68 }, 69 } 70 pflag.CommandLine.AddGoFlagSet(goflag.CommandLine) 71 getCmd.PersistentFlags().StringVar(&grpc.Address, "api-service-address", 72 grpc.DefaultAddress, 73 "Address(ip:port) for api service") 74 75 return getCmd 76 }