change kubeconfig loading order

This commit is contained in:
deads2k
2015-04-10 08:54:22 -04:00
parent b59266ad84
commit de4be5422c
50 changed files with 446 additions and 409 deletions

View File

@@ -32,10 +32,10 @@ import (
)
type ViewOptions struct {
PathOptions *PathOptions
Merge util.BoolFlag
Flatten bool
Minify bool
ConfigAccess ConfigAccess
Merge util.BoolFlag
Flatten bool
Minify bool
}
const (
@@ -52,8 +52,8 @@ $ kubectl config view --local
$ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2e" }}{{ index .user.password }}{{end}}{{end}}'`
)
func NewCmdConfigView(out io.Writer, PathOptions *PathOptions) *cobra.Command {
options := &ViewOptions{PathOptions: PathOptions}
func NewCmdConfigView(out io.Writer, ConfigAccess ConfigAccess) *cobra.Command {
options := &ViewOptions{ConfigAccess: ConfigAccess}
cmd := &cobra.Command{
Use: "view",
@@ -116,7 +116,7 @@ func (o ViewOptions) Run(out io.Writer, printer kubectl.ResourcePrinter) error {
func (o *ViewOptions) Complete() bool {
// if --kubeconfig, --global, or --local is specified, then merging doesn't make sense since you're declaring precise intent
if o.PathOptions.Global || o.PathOptions.Local || o.PathOptions.UseEnvVar {
if o.ConfigAccess.IsExplicitFile() {
if !o.Merge.Provided() {
o.Merge.Set("false")
}
@@ -136,32 +136,20 @@ func (o ViewOptions) loadConfig() (*clientcmdapi.Config, error) {
}
func (o ViewOptions) Validate() error {
return o.PathOptions.Validate()
if !o.Merge.Value() && !o.ConfigAccess.IsExplicitFile() {
return errors.New("if merge==false a precise file must to specified")
}
return nil
}
// 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
func (o *ViewOptions) getStartingConfig() (*clientcmdapi.Config, error) {
switch {
case !o.Merge.Value():
switch {
case len(o.PathOptions.LoadingRules.ExplicitPath) > 0:
return clientcmd.LoadFromFile(o.PathOptions.LoadingRules.ExplicitPath)
case o.PathOptions.Global:
return clientcmd.LoadFromFile(o.PathOptions.GlobalFile)
case o.PathOptions.UseEnvVar:
return clientcmd.LoadFromFile(o.PathOptions.EnvVarFile)
case o.PathOptions.Local:
return clientcmd.LoadFromFile(o.PathOptions.LocalFile)
default:
return nil, errors.New("if Merge==false a precise file must to specified")
}
return clientcmd.LoadFromFile(o.ConfigAccess.GetExplicitFile())
default:
return o.PathOptions.getStartingConfig()
return o.ConfigAccess.GetStartingConfig()
}
}