-
Notifications
You must be signed in to change notification settings - Fork 1
/
kubeproxy.go
58 lines (48 loc) · 1.22 KB
/
kubeproxy.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 (
"fmt"
"minik8s/config"
"minik8s/pkg/kubeproxy"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var ProxyCmd = &cobra.Command{
Use: "kubeproxy",
Short: "kubeproxy manages network",
Long: "kubeproxy manages network",
Run: runProxy,
}
var proxyConfigAddr string
var KubeproxyConfig = Config{
ApiserverAddr: "192.168.1.13:8080",
}
type Config struct {
ApiserverAddr string // 192.168.1.13:8080
}
func proxyInitConfig() {
//fmt.Println(configAddr)
viper.SetConfigFile(proxyConfigAddr)
err := viper.ReadInConfig()
if err == nil {
//panic(err)
if err := viper.Unmarshal(&KubeproxyConfig); err != nil {
//panic(err)
}
}
//if err,use default config
fmt.Println(KubeproxyConfig)
}
func init() {
cobra.OnInitialize(proxyInitConfig)
//RootCmd.Flags().StringVarP(&apiserverAddr, "apiserver-address", "a", utils.ApiServerIp, "kubelet (-a apiserver-address)")
ProxyCmd.PersistentFlags().StringVarP(&proxyConfigAddr, "config", "c", "./kubeproxy-config.yaml", "kubeproxy (-c config)")
}
func runProxy(cmd *cobra.Command, args []string) {
config.ApiServerIp = KubeproxyConfig.ApiserverAddr
kubeproxy.Run()
}
func main() {
if err := ProxyCmd.Execute(); err != nil {
fmt.Println(err.Error())
}
}