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) 
  • 相关阅读:
    ORA-00119: invalid specification for system parameter REMOTE_LISTENER
    Standby Redo Log 的设定原则、创建、删除、查看、归档位置
    dataguard类型转换与模式转化
    Restore Points 制定回退方案
    11g dataguard 类型、保护模式、服务
    [置顶] 设计模式系列4-抽象工厂模式
    MediaInfo源代码分析 4:Inform()函数
    Codeforces Beta Round #51 D. Beautiful numbers
    如何将ER图转换成关系模式集
    建立简单的服务器端程序
  • 原文地址:https://www.cnblogs.com/dream397/p/15224731.html
Copyright © 2011-2022 走看看