• golang yaml LoadYAML


    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) 
  • 相关阅读:
    Apache Airavata 0.6 发布
    Erebus 0.5 发布,2D 实时角色扮演游戏
    Pcompress 1.3.0 发布,性能大幅提升
    JasperStarter 1.0.1 发布
    Newscoop 4.1 发布,适合记者的 CMS 系统
    Wireshark 1.8.5 发布,网络协议检测程序
    Open Search Server 1.4 Beta2 发布
    Erlang/OTP R16A 发布
    Apache Derby 10.8.3.0 发布
    reading notes for solr source code
  • 原文地址:https://www.cnblogs.com/dream397/p/15224731.html
Copyright © 2020-2023  润新知