mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #90243 from soltysh/issue90074
Revert "stop defaulting kubeconfig to http://localhost:8080"
This commit is contained in:
commit
e95106106b
@ -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: os.Getenv("KUBERNETES_MASTER")}
|
ClusterDefaults = clientcmdapi.Cluster{Server: getDefaultServer()}
|
||||||
// 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,6 +43,15 @@ 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
|
||||||
|
@ -27,6 +27,7 @@ go_test(
|
|||||||
deps = [
|
deps = [
|
||||||
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
|
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
|
||||||
"//staging/src/k8s.io/kubectl/pkg/cmd/util:go_default_library",
|
"//staging/src/k8s.io/kubectl/pkg/cmd/util:go_default_library",
|
||||||
|
"//vendor/github.com/spf13/cobra:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||||
)
|
)
|
||||||
@ -27,9 +29,17 @@ import (
|
|||||||
func TestNewCmdVersionWithoutConfigFile(t *testing.T) {
|
func TestNewCmdVersionWithoutConfigFile(t *testing.T) {
|
||||||
tf := cmdutil.NewFactory(&genericclioptions.ConfigFlags{})
|
tf := cmdutil.NewFactory(&genericclioptions.ConfigFlags{})
|
||||||
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||||
cmd := NewCmdVersion(tf, streams)
|
o := NewOptions(streams)
|
||||||
cmd.SetOutput(buf)
|
if err := o.Complete(tf, &cobra.Command{}); err != nil {
|
||||||
if err := cmd.Execute(); err != nil {
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if err := o.Validate(); err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
// FIXME soltysh:
|
||||||
|
// since we have defaulting to localhost:8080 in staging/src/k8s.io/client-go/tools/clientcmd/client_config.go#getDefaultServer
|
||||||
|
// we need to ignore the localhost:8080 server, when above gets removed this should be dropped too
|
||||||
|
if err := o.Run(); err != nil && !strings.Contains(err.Error(), "localhost:8080") {
|
||||||
t.Errorf("Cannot execute version command: %v", err)
|
t.Errorf("Cannot execute version command: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(buf.String(), "Client Version") {
|
if !strings.Contains(buf.String(), "Client Version") {
|
||||||
|
@ -324,7 +324,6 @@ 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