type Config struct {
Kube struct {
OutCluster bool `yaml:"outCluster" json:"outCluster"`
ConfigPath string `yaml:"configPath" json:"configPath" default:"kubeconfig.yaml"`
} `yaml:"kube" json:"kube"`
}
root@ubuntu:~/crd_demo# cat etc/config.yaml
kube:
outCluster: true
configPath: /etc/kubernetes/admin.conf
root@ubuntu:~/crd_demo#
if err := utils.LoadYAML(path, &cfg); err != nil {
return nil, err
}
kubeConfig, err := func() (*rest.Config, error) {
if !cfg.Kube.OutCluster {
return rest.InClusterConfig()
}
return clientcmd.BuildConfigFromFlags(
"", cfg.Kube.ConfigPath)
}()
(dlv) p cfg.Kube
struct { OutCluster bool "yaml:\"outCluster\" json:\"outCluster\""; ConfigPath string "yaml:\"configPath\" json:\"configPath\" default:\"kubeconfig.yaml\"" } {
OutCluster: true,
ConfigPath: "/etc/kubernetes/admin.conf",}
(dlv) quit
root@ubuntu:~/crd_demo# dlv exec ./igh
Type 'help' for list of commands.
(dlv) b kube/controller.go:76
Breakpoint 1 (enabled) set at 0xce713c for /kube.NewClient() ./kube/controller.go:76
(dlv) c
> /kube.NewClient() ./kube/controller.go:76 (hits goroutine(1):1 total:1) (PC: 0xce713c)
Warning: debugging optimized function
71: recorder record.EventRecorder
72: }
73:
74: func NewClient(ctx context.Context, path string) (*Client, error) {
75: var cfg Config
=> 76: if err := utils.LoadYAML(path, &cfg); err != nil {
77: return nil, err
78: }
79:
80: kubeConfig, err := func() (*rest.Config, error) {
81: if !cfg.Kube.OutCluster {
(dlv) n
> kube.NewClient() ./kube/controller.go:86 (PC: 0xce716c)
Warning: debugging optimized function
81: if !cfg.Kube.OutCluster {
82: return rest.InClusterConfig()
83: }
84: return clientcmd.BuildConfigFromFlags(
85: "", cfg.Kube.ConfigPath)
=> 86: }()
87: if err != nil {
88: return nil, err
89: }
90:
91: // client
(dlv) p cfg
kube.Config {
Kube: struct { OutCluster bool "yaml:\"outCluster\" json:\"outCluster\""; ConfigPath string "yaml:\"configPath\" json:\"configPath\" default:\"kubeconfig.yaml\"" } {
OutCluster: true,
ConfigPath: "/etc/kubernetes/admin.conf",},}
(dlv) p cfg.Kube
struct { OutCluster bool "yaml:\"outCluster\" json:\"outCluster\""; ConfigPath string "yaml:\"configPath\" json:\"configPath\" default:\"kubeconfig.yaml\"" } {
OutCluster: true,
ConfigPath: "/etc/kubernetes/admin.conf",}
(dlv)