mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #86173 from soltysh/cli_defaults
stop defaulting kubeconfig to http://localhost:8080
This commit is contained in:
commit
b5b675491b
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package genericclioptions
|
package genericclioptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -55,7 +56,17 @@ const (
|
|||||||
flagHTTPCacheDir = "cache-dir"
|
flagHTTPCacheDir = "cache-dir"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultCacheDir = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
|
var (
|
||||||
|
defaultCacheDir = filepath.Join(homedir.HomeDir(), ".kube", "http-cache")
|
||||||
|
|
||||||
|
ErrEmptyConfig = errors.New(`Missing or incomplete configuration info. Please point to an existing, complete config file:
|
||||||
|
|
||||||
|
1. Via the command-line flag --kubeconfig
|
||||||
|
2. Via the KUBECONFIG environment variable
|
||||||
|
3. In your home directory as ~/.kube/config
|
||||||
|
|
||||||
|
To view or setup config directly use the 'config' command.`)
|
||||||
|
)
|
||||||
|
|
||||||
// RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands
|
// RESTClientGetter is an interface that the ConfigFlags describe to provide an easier way to mock for commands
|
||||||
// and eliminate the direct coupling to a struct type. Users may wish to duplicate this type in their own packages
|
// and eliminate the direct coupling to a struct type. Users may wish to duplicate this type in their own packages
|
||||||
@ -110,7 +121,12 @@ type ConfigFlags struct {
|
|||||||
// to a .kubeconfig file, loading rules, and config flag overrides.
|
// to a .kubeconfig file, loading rules, and config flag overrides.
|
||||||
// Expects the AddFlags method to have been called.
|
// Expects the AddFlags method to have been called.
|
||||||
func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
|
func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
|
||||||
return f.ToRawKubeConfigLoader().ClientConfig()
|
config, err := f.ToRawKubeConfigLoader().ClientConfig()
|
||||||
|
// replace client-go's ErrEmptyConfig error with our custom, more verbose version
|
||||||
|
if clientcmd.IsEmptyConfig(err) {
|
||||||
|
return nil, ErrEmptyConfig
|
||||||
|
}
|
||||||
|
return config, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToRawKubeConfigLoader binds config flag values to config overrides
|
// ToRawKubeConfigLoader binds config flag values to config overrides
|
||||||
|
@ -35,7 +35,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
// ClusterDefaults has the same behavior as the old EnvVar and DefaultCluster fields
|
// ClusterDefaults has the same behavior as the old EnvVar and DefaultCluster fields
|
||||||
// DEPRECATED will be replaced
|
// DEPRECATED will be replaced
|
||||||
ClusterDefaults = clientcmdapi.Cluster{Server: getDefaultServer()}
|
ClusterDefaults = clientcmdapi.Cluster{Server: os.Getenv("KUBERNETES_MASTER")}
|
||||||
// DefaultClientConfig represents the legacy behavior of this package for defaulting
|
// DefaultClientConfig represents the legacy behavior of this package for defaulting
|
||||||
// DEPRECATED will be replace
|
// DEPRECATED will be replace
|
||||||
DefaultClientConfig = DirectClientConfig{*clientcmdapi.NewConfig(), "", &ConfigOverrides{
|
DefaultClientConfig = DirectClientConfig{*clientcmdapi.NewConfig(), "", &ConfigOverrides{
|
||||||
@ -43,15 +43,6 @@ var (
|
|||||||
}, nil, NewDefaultClientConfigLoadingRules(), promptedCredentials{}}
|
}, nil, NewDefaultClientConfigLoadingRules(), promptedCredentials{}}
|
||||||
)
|
)
|
||||||
|
|
||||||
// getDefaultServer returns a default setting for DefaultClientConfig
|
|
||||||
// DEPRECATED
|
|
||||||
func getDefaultServer() string {
|
|
||||||
if server := os.Getenv("KUBERNETES_MASTER"); len(server) > 0 {
|
|
||||||
return server
|
|
||||||
}
|
|
||||||
return "http://localhost:8080"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
type ClientConfig interface {
|
type ClientConfig interface {
|
||||||
// RawConfig returns the merged result of all overrides
|
// RawConfig returns the merged result of all overrides
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoContext = errors.New("no context chosen")
|
ErrNoContext = errors.New("no context chosen")
|
||||||
ErrEmptyConfig = errors.New("no configuration has been provided")
|
ErrEmptyConfig = errors.New("no configuration has been provided, try setting KUBERNETES_MASTER environment variable")
|
||||||
// message is for consistency with old behavior
|
// message is for consistency with old behavior
|
||||||
ErrEmptyCluster = errors.New("cluster has no server defined")
|
ErrEmptyCluster = errors.New("cluster has no server defined")
|
||||||
)
|
)
|
||||||
|
@ -325,6 +325,7 @@ runTests() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
kube::log::status "Checking kubectl version"
|
kube::log::status "Checking kubectl version"
|
||||||
|
export KUBERNETES_MASTER=http://127.0.0.1:${API_PORT}
|
||||||
kubectl version
|
kubectl version
|
||||||
|
|
||||||
# Generate a random namespace name, based on the current time (to make
|
# Generate a random namespace name, based on the current time (to make
|
||||||
|
Loading…
Reference in New Issue
Block a user