// Where possible, yaml tags match the cli argument names.
// Where possible, json tags match the cli argument names.
// Top level config objects and all values required for proper functioning are not "omitempty". Any truly optional piece of config is allowed to be omitted.
// Top level config objects and all values required for proper functioning are not "omitempty". Any truly optional piece of config is allowed to be omitted.
// Config holds the information needed to build connect to remote kubernetes clusters as a given user
// Config holds the information needed to build connect to remote kubernetes clusters as a given user
typeConfigstruct{
typeConfigstruct{
api.TypeMeta`json:",inline"`
// Preferences holds general information to be use for cli interactions
// Preferences holds general information to be use for cli interactions
PreferencesPreferences`yaml:"preferences"`
PreferencesPreferences`json:"preferences"`
// Clusters is a map of referencable names to cluster configs
// Clusters is a map of referencable names to cluster configs
Clustersmap[string]Cluster`yaml:"clusters"`
Clustersmap[string]Cluster`json:"clusters"`
// AuthInfos is a map of referencable names to user configs
// AuthInfos is a map of referencable names to user configs
AuthInfosmap[string]AuthInfo`yaml:"users"`
AuthInfosmap[string]AuthInfo`json:"users"`
// Contexts is a map of referencable names to context configs
// Contexts is a map of referencable names to context configs
Contextsmap[string]Context`yaml:"contexts"`
Contextsmap[string]Context`json:"contexts"`
// CurrentContext is the name of the context that you would like to use by default
// CurrentContext is the name of the context that you would like to use by default
CurrentContextstring`yaml:"current-context"`
CurrentContextstring`json:"current-context"`
// Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
// Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
// Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
typeContextstruct{
typeContextstruct{
// Cluster is the name of the cluster for this context
// Cluster is the name of the cluster for this context
Clusterstring`yaml:"cluster"`
Clusterstring`json:"cluster"`
// AuthInfo is the name of the authInfo for this context
// AuthInfo is the name of the authInfo for this context
AuthInfostring`yaml:"user"`
AuthInfostring`json:"user"`
// Namespace is the default namespace to use on unspecified requests
// Namespace is the default namespace to use on unspecified requests
Namespacestring`yaml:"namespace,omitempty"`
Namespacestring`json:"namespace,omitempty"`
// Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
// Where possible, json tags match the cli argument names.
// Top level config objects and all values required for proper functioning are not "omitempty". Any truly optional piece of config is allowed to be omitted.
// Config holds the information needed to build connect to remote kubernetes clusters as a given user
typeConfigstruct{
v1beta3.TypeMeta`json:",inline"`
// Preferences holds general information to be use for cli interactions
PreferencesPreferences`json:"preferences"`
// Clusters is a map of referencable names to cluster configs
Clusters[]NamedCluster`json:"clusters"`
// AuthInfos is a map of referencable names to user configs
AuthInfos[]NamedAuthInfo`json:"users"`
// Contexts is a map of referencable names to context configs
Contexts[]NamedContext`json:"contexts"`
// CurrentContext is the name of the context that you would like to use by default
CurrentContextstring`json:"current-context"`
// Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
// Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
typeContextstruct{
// Cluster is the name of the cluster for this context
Clusterstring`json:"cluster"`
// AuthInfo is the name of the authInfo for this context
AuthInfostring`json:"user"`
// Namespace is the default namespace to use on unspecified requests
Namespacestring`json:"namespace,omitempty"`
// Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
// ClientConfig is used to make it easy to get an api server client
// ClientConfig is used to make it easy to get an api server client
typeClientConfiginterface{
typeClientConfiginterface{
RawConfig()(clientcmdapi.Config,error)
// ClientConfig returns a complete client config
// ClientConfig returns a complete client config
ClientConfig()(*client.Config,error)
ClientConfig()(*client.Config,error)
}
}
// DirectClientConfig is a ClientConfig interface that is backed by a Config, options overrides, and an optional fallbackReader for auth information
// DirectClientConfig is a ClientConfig interface that is backed by a clientcmdapi.Config, options overrides, and an optional fallbackReader for auth information
typeDirectClientConfigstruct{
typeDirectClientConfigstruct{
configConfig
configclientcmdapi.Config
contextNamestring
contextNamestring
overrides*ConfigOverrides
overrides*ConfigOverrides
fallbackReaderio.Reader
fallbackReaderio.Reader
}
}
// NewDefaultClientConfig creates a DirectClientConfig using the config.CurrentContext as the context name
// NewDefaultClientConfig creates a DirectClientConfig using the config.CurrentContext as the context name
// NewInteractiveClientConfig creates a DirectClientConfig using the passed context name and a reader in case auth information is not provided via files or flags
// NewInteractiveClientConfig creates a DirectClientConfig using the passed context name and a reader in case auth information is not provided via files or flags
flags.BoolVar(&clusterInfo.InsecureSkipTLSVerify,flagNames.InsecureSkipTLSVerify,false,"If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.")
flags.BoolVar(&clusterInfo.InsecureSkipTLSVerify,flagNames.InsecureSkipTLSVerify,false,"If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.")
}
}
// BindFlags is a convenience method to bind the specified flags to their associated variables
// BindOverrideFlags is a convenience method to bind the specified flags to their associated variables
// ConfirmUsable looks a particular context and determines if that particular part of the config is useable. There might still be errors in the config,
// ConfirmUsable looks a particular context and determines if that particular part of the config is useable. There might still be errors in the config,
// but no errors in the sections requested or referenced. It does not return early so that it can find as many errors as possible.
// but no errors in the sections requested or referenced. It does not return early so that it can find as many errors as possible.
// validateContext looks for errors in the context. It is not transitive, so errors in the reference authInfo or cluster configs are not included in this return
// validateContext looks for errors in the context. It is not transitive, so errors in the reference authInfo or cluster configs are not included in this return
// getConfigFromFileOrDie tries to read a kubeconfig file and if it can't, it calls exit. One exception, missing files result in empty configs, not an exit
Short:"displays the specified .kubeconfig file or a merged result",
Long:`displays the specified .kubeconfig file or a merged result`,
Run:func(cmd*cobra.Command,args[]string){
err:=options.run()
iferr!=nil{
fmt.Printf("%v\n",err)
}
},
}
cmd.Flags().BoolVar(&options.merge,"merge",false,"merge together the full hierarchy of .kubeconfig files")
returncmd
}
func(oviewOptions)run()error{
err:=o.validate()
iferr!=nil{
returnerr
}
config,_,err:=o.getStartingConfig()
iferr!=nil{
returnerr
}
content,err:=yaml.Marshal(config)
iferr!=nil{
returnerr
}
fmt.Printf("%v",string(content))
returnnil
}
func(oviewOptions)validate()error{
returnnil
}
// getStartingConfig returns the Config object built from the sources specified by the options, the filename read (only if it was a single file), and an error if something goes wrong