本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned/clientcmd.ConfigAccess类的典型用法代码示例。如果您正苦于以下问题:Golang ConfigAccess类的具体用法?Golang ConfigAccess怎么用?Golang ConfigAccess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigAccess类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runGetClusters
func runGetClusters(out io.Writer, configAccess clientcmd.ConfigAccess) error {
config, err := configAccess.GetStartingConfig()
if err != nil {
return err
}
fmt.Fprintf(out, "NAME\n")
for name := range config.Clusters {
fmt.Fprintf(out, "%s\n", name)
}
return nil
}
示例2: runDeleteContext
func runDeleteContext(out io.Writer, configAccess clientcmd.ConfigAccess, cmd *cobra.Command) error {
config, err := configAccess.GetStartingConfig()
if err != nil {
return err
}
args := cmd.Flags().Args()
if len(args) != 1 {
cmd.Help()
return nil
}
configFile := configAccess.GetDefaultFilename()
if configAccess.IsExplicitFile() {
configFile = configAccess.GetExplicitFile()
}
name := args[0]
_, ok := config.Contexts[name]
if !ok {
return fmt.Errorf("cannot delete context %s, not in %s", name, configFile)
}
delete(config.Contexts, name)
if err := clientcmd.ModifyConfig(configAccess, *config, true); err != nil {
return err
}
fmt.Fprintf(out, "deleted context %s from %s", name, configFile)
return nil
}
示例3: modifyConfig
func modifyConfig(configAccess clientcmd.ConfigAccess, suppliedConfig *clientcmdapi.Config) error {
config, err := configAccess.GetStartingConfig()
if err != nil {
return err
}
for name, authInfo := range suppliedConfig.AuthInfos {
initial, ok := config.AuthInfos[name]
if !ok {
initial = clientcmdapi.NewAuthInfo()
}
modifiedAuthInfo := *initial
var setToken, setBasic bool
if len(authInfo.ClientCertificate) > 0 {
modifiedAuthInfo.ClientCertificate = authInfo.ClientCertificate
}
if len(authInfo.ClientCertificateData) > 0 {
modifiedAuthInfo.ClientCertificateData = authInfo.ClientCertificateData
}
if len(authInfo.ClientKey) > 0 {
modifiedAuthInfo.ClientKey = authInfo.ClientKey
}
if len(authInfo.ClientKeyData) > 0 {
modifiedAuthInfo.ClientKeyData = authInfo.ClientKeyData
}
if len(authInfo.Token) > 0 {
modifiedAuthInfo.Token = authInfo.Token
setToken = len(modifiedAuthInfo.Token) > 0
}
if len(authInfo.Username) > 0 {
modifiedAuthInfo.Username = authInfo.Username
setBasic = setBasic || len(modifiedAuthInfo.Username) > 0
}
if len(authInfo.Password) > 0 {
modifiedAuthInfo.Password = authInfo.Password
setBasic = setBasic || len(modifiedAuthInfo.Password) > 0
}
// If any auth info was set, make sure any other existing auth types are cleared
if setToken || setBasic {
if !setToken {
modifiedAuthInfo.Token = ""
}
if !setBasic {
modifiedAuthInfo.Username = ""
modifiedAuthInfo.Password = ""
}
}
config.AuthInfos[name] = &modifiedAuthInfo
}
for name, cluster := range suppliedConfig.Clusters {
initial, ok := config.Clusters[name]
if !ok {
initial = clientcmdapi.NewCluster()
}
modifiedCluster := *initial
if len(cluster.Server) > 0 {
modifiedCluster.Server = cluster.Server
}
if cluster.InsecureSkipTLSVerify {
modifiedCluster.InsecureSkipTLSVerify = cluster.InsecureSkipTLSVerify
// Specifying insecure mode clears any certificate authority
if modifiedCluster.InsecureSkipTLSVerify {
modifiedCluster.CertificateAuthority = ""
modifiedCluster.CertificateAuthorityData = nil
}
}
if len(cluster.CertificateAuthorityData) > 0 {
modifiedCluster.CertificateAuthorityData = cluster.CertificateAuthorityData
modifiedCluster.InsecureSkipTLSVerify = false
}
if len(cluster.CertificateAuthority) > 0 {
modifiedCluster.CertificateAuthority = cluster.CertificateAuthority
modifiedCluster.InsecureSkipTLSVerify = false
}
config.Clusters[name] = &modifiedCluster
}
for name, context := range suppliedConfig.Contexts {
initial, ok := config.Contexts[name]
if !ok {
initial = clientcmdapi.NewContext()
}
modifiedContext := *initial
if len(context.Cluster) > 0 {
modifiedContext.Cluster = context.Cluster
}
if len(context.AuthInfo) > 0 {
modifiedContext.AuthInfo = context.AuthInfo
}
if len(context.Namespace) > 0 {
modifiedContext.Namespace = context.Namespace
//.........这里部分代码省略.........