-
Notifications
You must be signed in to change notification settings - Fork 88
/
api.go
47 lines (38 loc) · 1.07 KB
/
api.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
package cli
import (
"os"
"strings"
"github.com/replicatedhq/kots/pkg/apiserver"
"github.com/replicatedhq/kots/pkg/buildversion"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/util"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func APICmd() *cobra.Command {
cmd := &cobra.Command{
Use: "api",
Short: "Starts the API server",
Long: ``,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
if v.GetString("log-level") == "debug" {
logger.SetDebug()
}
util.PodNamespace = os.Getenv("POD_NAMESPACE")
util.KotsadmTargetNamespace = os.Getenv("KOTSADM_TARGET_NAMESPACE")
params := apiserver.APIServerParams{
Version: buildversion.Version(),
RqliteURI: os.Getenv("RQLITE_URI"),
AutocreateClusterToken: os.Getenv("AUTO_CREATE_CLUSTER_TOKEN"),
}
apiserver.Start(¶ms)
return nil
},
}
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
return cmd
}