mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
Make clientcmd defaulting a function of ConfigOverrides and LoadingRules
This commit moves away from using a global variable for default configuration checking, and instead exposes a method on LoadingRules to determine whether a particular restclient.Config should be considered "default". This allows kubectl to provide its own defaults (the same as before, KUBERNETES_MASTER and the static localhost:8080 values) while allowing other clients to avoid defining them. In-cluster config defaulting is now easier to read.
This commit is contained in:
@@ -34,7 +34,6 @@ import (
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/emicklei/go-restful/swagger"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
@@ -1161,11 +1160,13 @@ func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
|
||||
// exists and is not a directory.
|
||||
func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
|
||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
// use the standard defaults for this client command
|
||||
// DEPRECATED: remove and replace with something more accurate
|
||||
loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig
|
||||
|
||||
flags.StringVar(&loadingRules.ExplicitPath, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests.")
|
||||
|
||||
overrides := &clientcmd.ConfigOverrides{}
|
||||
// use the standard defaults for this client config
|
||||
mergo.Merge(&overrides.ClusterDefaults, clientcmd.DefaultCluster)
|
||||
overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clientcmd.ClusterDefaults}
|
||||
|
||||
flagNames := clientcmd.RecommendedConfigOverrideFlags("")
|
||||
// short flagnames are disabled by default. These are here for compatibility with existing scripts
|
||||
|
||||
Reference in New Issue
Block a user