-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (56 loc) · 2.08 KB
/
main.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
59
60
61
62
63
64
package main
import (
"flag"
"fmt"
"os"
"github.com/devincd/coredns-hosts-api/pkg/installer"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/klog/v2"
)
var installerArgs = installer.NewEmptyArgs()
func main() {
cmd := newCommand()
if err := cmd.Execute(); err != nil {
klog.ErrorS(err, "Failed to execute the command")
os.Exit(-1)
}
}
func newCommand() *cobra.Command {
command := &cobra.Command{
Use: "coredns-hosts-install",
Short: "coredns web apis service for hosts",
Args: cobra.ExactArgs(0),
PreRunE: func(cmd *cobra.Command, args []string) error {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
printFlags(cmd)
s, err := installer.NewServer(installerArgs)
if err != nil {
return fmt.Errorf("failed to create server: %v", err)
}
if err := s.RunOnce(); err != nil {
return fmt.Errorf("failed to RunOnce server: %v", err)
}
return nil
},
}
addFlags(command)
return command
}
func addFlags(c *cobra.Command) {
klog.InitFlags(flag.CommandLine)
c.PersistentFlags().AddGoFlagSet(flag.CommandLine)
c.PersistentFlags().StringVar(&installerArgs.Kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
c.PersistentFlags().StringVar(&installerArgs.CoreDNSName, "coredns-name", "coredns", "the name of coreDNS component, including the Deployment and Service.")
c.PersistentFlags().StringVar(&installerArgs.CoreDNSNamespace, "coredns-namespace", "kube-system", "the namespace of coreDNS component, including the Deployment and Service.")
c.PersistentFlags().StringVar(&installerArgs.CoreDNSHostsServerVersion, "corednsHostsServer-version", "v1.0.0", "")
c.PersistentFlags().StringVar(&installerArgs.ServerArgs.Kubeconfig, "server-kubeconfig", "", "absolute path to the kubeconfig file of coredns-hosts-server component")
c.PersistentFlags().Int32Var(&installerArgs.ServerArgs.Port, "server-port", 9080, "the web service port of coredns-hosts-server component")
}
func printFlags(c *cobra.Command) {
c.PersistentFlags().VisitAll(func(flag *pflag.Flag) {
klog.Infof("FLAG: --%s=%q", flag.Name, flag.Value)
})
}