Change:
In 1.1, if you specify "current-context: i-do-not-exist" in a kubeconfig, and there's no matching context by that name in the contexts, kubelet silently uses what I assume is either an empty or a default configuration. This can result in hilarity like wondering why your kubelet isn't using the TLS settings you provided, and spending several hours debugging the whole stack only to discover that you typo'd current-context :). It would be better if kubelet and other users of errored out on such a misconfiguration, to make the failure obvious and trivial.
cc
I think kubelet silently uses an empty configuration. Guess we should give a waring here.
Did you start to work on this?
Below is related code: can you confirm this? Besides if we want to log a waring in kubelet, we may need to get in kubelet.
cc
cc
I believe kubelet already uses . Adding a check in that current context exists if specified sounds like the right approach.
Are there any backwards compatibility implications here? would this break users who have existing configs (that fallback to default namespace)? , Jeff Lowdermilk wrote:
I think kubelet directly use not . Also already checks whether the user-specified current context exists, the problem is that if not exist, we just skip. We need to do something if the current context not exist, like log a warning.
Erroring on a specified and bad seems reasonable. If it is not specified and there's only one option, I don't think we should fail.
yeap, the case is that user specify the but not exist, in such case we should just fail.
If no one is working on this I can take it.
I think this is the root cause. Basically we should error on this not exist context. If you have extra bandwidth, please go ahead :)
This is related to - the defaulting is what allows us to continue. When that merges, only kubectl will have the "use localhost:8080" as defaulting.

Discussion:
// but no errors in the sections requested or referenced.  It does not return early so that it can find as many errors as possible. func (config *DirectClientConfig) ConfirmUsable() error { validationErrors := make([]error, 0) <ins> var contextName string if len(config.contextName) != 0 { contextName = config.contextName } else { contextName = config.config.CurrentContext } if len(contextName) > 0 { _, exists := config.config.Contexts[contextName] if !exists { validationErrors = append(validationErrors, &errContextNotFound{contextName}) } } </ins> validationErrors = append(validationErrors, validateAuthInfo(config.getAuthInfoName(), config.getAuthInfo())...) validationErrors = append(validationErrors, validateClusterInfo(config.getClusterName(), config.getCluster())...) // when direct client config is specified, and our only error is that no server is defined, we should

"io/ioutil" "os" "reflect" <ins> "strings" </ins> "testing" "github.com/imdario/mergo" <del> "k8s.io/kubernetes/pkg/client/restclient" </del> clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api" )

t.Fatalf("Unexpected error: %v", err) } } func TestCreateMissingContext(t *testing.T) { <del> const expectedErrorContains = "Context was not found for specified context" </del> <ins> const expectedErrorContains = "context was not found for specified context: not-present" </ins> config := createValidTestConfig() clientBuilder := NewNonInteractiveClientConfig(*config, "not-present", &ConfigOverrides{ ClusterDefaults: DefaultCluster, }, nil) <del> clientConfig, err := clientBuilder.ClientConfig() if err != nil { t.Fatalf("Unexpected error: %v", err) </del> <ins> _, err := clientBuilder.ClientConfig() if err == nil { t.Fatalf("Expected error: %v", expectedErrorContains) </ins> } <del> expectedConfig := &restclient.Config{Host: clientConfig.Host} if !reflect.DeepEqual(expectedConfig, clientConfig) { t.Errorf("Expected %#v, got %#v", expectedConfig, clientConfig) </del> <ins> if !strings.Contains(err.Error(), expectedErrorContains) { t.Fatalf("Expected error: %v, but got %v", expectedErrorContains, err) </ins> } }

// Enable swagger api on master. components.KubeMaster.InstallSwaggerAPI() cluster := clientcmdapi.NewCluster() cluster.Server = components.ApiServer.URL cluster.InsecureSkipTLSVerify = true <ins> cfg.Contexts = map[string]*clientcmdapi.Context{"test": ctx} cfg.CurrentContext = "test" </ins> overrides := clientcmd.ConfigOverrides{ <del> ClusterInfo:    *cluster, Context:        *ctx, CurrentContext: "test", </del> <ins> ClusterInfo: *cluster, </ins> } cmdConfig := clientcmd.NewNonInteractiveClientConfig(*cfg, "test", &overrides, nil) factory := util.NewFactory(cmdConfig)