forked from kubernetes-retired/bootkube
/
start.go
58 lines (49 loc) · 1.41 KB
/
start.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"errors"
"github.com/spf13/cobra"
"github.com/kubernetes-incubator/bootkube/pkg/bootkube"
)
var (
cmdStart = &cobra.Command{
Use: "start",
Short: "Start the bootkube service",
Long: "",
PreRunE: validateStartOpts,
RunE: runCmdStart,
SilenceUsage: true,
}
startOpts struct {
assetDir string
podManifestPath string
}
)
func init() {
cmdRoot.AddCommand(cmdStart)
cmdStart.Flags().StringVar(&startOpts.assetDir, "asset-dir", "", "Path to the cluster asset directory. Expected layout genereted by the `bootkube render` command.")
cmdStart.Flags().StringVar(&startOpts.podManifestPath, "pod-manifest-path", "/etc/kubernetes/manifests", "The location where the kubelet is configured to look for static pod manifests.")
}
func runCmdStart(cmd *cobra.Command, args []string) error {
bk, err := bootkube.NewBootkube(bootkube.Config{
AssetDir: startOpts.assetDir,
PodManifestPath: startOpts.podManifestPath,
})
if err != nil {
return err
}
err = bk.Run()
if err != nil {
// Always report errors.
bootkube.UserOutput("Error: %v\n", err)
}
return err
}
func validateStartOpts(cmd *cobra.Command, args []string) error {
if startOpts.podManifestPath == "" {
return errors.New("missing required flag: --pod-manifest-path")
}
if startOpts.assetDir == "" {
return errors.New("missing required flag: --asset-dir")
}
return nil
}