zoukankan      html  css  js  c++  java
  • 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) 
  • 相关阅读:
    Java系列: JAVA字符串格式化-String.format()的使用(zz)
    Eclipse系列: 在Eclipse中用TODO标签管理任务(Task)(ZZ)
    JNDI全面总结(zz)
    Java Platform Standard Edition 8 Documentation
    JAVA NIO是什么(zz)
    Java NIO框架Mina、Netty、Grizzly介绍与对比(zz)
    Bootstrap系列 -- 25. 下拉菜单分割线
    Bootstrap系列 -- 24. 下拉菜单基本用法
    Bootstrap系列 -- 23. 图片
    Bootstrap系列 -- 22. 按钮详解
  • 原文地址:https://www.cnblogs.com/dream397/p/15224731.html
Copyright © 2011-2022 走看看