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) 
  • 相关阅读:
    The Lobo Project: Home of Lobo (Java Web Browser) and Cobra (HTML Rendering Engine)
    基于DOM树的网页相似度研究与应用《大连理工大学》2011年硕士论文
    学习用 c/c++写crawler
    终于用上gcc4.1编译的系统了
    Android 查找SDCard 下面的文件 函数
    对HTML5 Device API相关规范的解惑
    Windows Phone开发(14):数据模板
    Windows Phone开发(13):如何规范用户的输入行为
    InputScope的62个值
    转:Windows Phone 7 设计简介
  • 原文地址:https://www.cnblogs.com/dream397/p/15224731.html
Copyright © 2011-2022 走看看