github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/cmd/server.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "io" 6 7 "github.com/apprenda/kismatic/pkg/inspector" 8 "github.com/spf13/cobra" 9 ) 10 11 var serverExample = `# Run the inspector in server mode 12 kismatic-inspector server --node-roles master,worker 13 14 # Run the inspector in server mode, in a specific port 15 kismatic-inspector server --port 9000 --node-roles master 16 ` 17 18 type serverOpts struct { 19 commandName string 20 port int 21 nodeRoles string 22 packageInstallationDisabled bool 23 dockerInstallationDisabled bool 24 disconnectedInstallation bool 25 } 26 27 // NewCmdServer returns the "server" command 28 func NewCmdServer(out io.Writer) *cobra.Command { 29 opts := serverOpts{} 30 cmd := &cobra.Command{ 31 Use: "server", 32 Short: "Stand up the inspector server for running checks remotely", 33 Example: serverExample, 34 RunE: func(cmd *cobra.Command, args []string) error { 35 opts.commandName = cmd.Parent().Name() 36 return runServer(out, opts) 37 }, 38 } 39 cmd.Flags().IntVar(&opts.port, "port", 9090, "the port number for standing up the Inspector server") 40 cmd.Flags().StringVar(&opts.nodeRoles, "node-roles", "", "comma-separated list of the node's roles. Valid roles are 'etcd', 'master', 'worker', 'ingress', 'storage'") 41 cmd.Flags().BoolVar(&opts.packageInstallationDisabled, "pkg-installation-disabled", false, "when true, the inspector will ensure that the necessary packages are installed on the node") 42 cmd.Flags().BoolVar(&opts.dockerInstallationDisabled, "docker-installation-disabled", false, "when true, the inspector will check for docker packages to be installed") 43 cmd.Flags().BoolVar(&opts.disconnectedInstallation, "disconnected-installation", false, "when true will check for the required packages needed during a disconnected install") 44 return cmd 45 } 46 47 func runServer(out io.Writer, opts serverOpts) error { 48 if opts.nodeRoles == "" { 49 return fmt.Errorf("--node-roles is required") 50 } 51 nodeFacts, err := getNodeRoles(opts.nodeRoles) 52 if err != nil { 53 return err 54 } 55 if opts.disconnectedInstallation { 56 nodeFacts = append(nodeFacts, "disconnected") 57 } 58 s, err := inspector.NewServer(nodeFacts, opts.port, opts.packageInstallationDisabled, opts.dockerInstallationDisabled, opts.disconnectedInstallation) 59 if err != nil { 60 return fmt.Errorf("error starting up inspector server: %v", err) 61 } 62 fmt.Fprintf(out, "Inspector is listening on port %d\n", opts.port) 63 fmt.Fprintf(out, "Node roles: %s\n", opts.nodeRoles) 64 fmt.Fprintf(out, "Package installation disabled: %v\n", opts.packageInstallationDisabled) 65 fmt.Fprintf(out, "Docker installation disabled: %v\n", opts.dockerInstallationDisabled) 66 fmt.Fprintf(out, "Disconnected installation: %v\n", opts.disconnectedInstallation) 67 fmt.Fprintf(out, "Run %s from another node to run checks remotely: %[1]s client [NODE_IP]:%d\n", opts.commandName, opts.port) 68 return s.Start() 69 }