Skip to content

Commit e951061

Browse files
authored
Merge pull request kubernetes#90243 from soltysh/issue90074
Revert "stop defaulting kubeconfig to http://localhost:8080"
2 parents c70e3e9 + 3486577 commit e951061

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

staging/src/k8s.io/client-go/tools/clientcmd/client_config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,23 @@ import (
3535
var (
3636
// ClusterDefaults has the same behavior as the old EnvVar and DefaultCluster fields
3737
// DEPRECATED will be replaced
38-
ClusterDefaults = clientcmdapi.Cluster{Server: os.Getenv("KUBERNETES_MASTER")}
38+
ClusterDefaults = clientcmdapi.Cluster{Server: getDefaultServer()}
3939
// DefaultClientConfig represents the legacy behavior of this package for defaulting
4040
// DEPRECATED will be replace
4141
DefaultClientConfig = DirectClientConfig{*clientcmdapi.NewConfig(), "", &ConfigOverrides{
4242
ClusterDefaults: ClusterDefaults,
4343
}, nil, NewDefaultClientConfigLoadingRules(), promptedCredentials{}}
4444
)
4545

46+
// getDefaultServer returns a default setting for DefaultClientConfig
47+
// DEPRECATED
48+
func getDefaultServer() string {
49+
if server := os.Getenv("KUBERNETES_MASTER"); len(server) > 0 {
50+
return server
51+
}
52+
return "http://localhost:8080"
53+
}
54+
4655
// ClientConfig is used to make it easy to get an api server client
4756
type ClientConfig interface {
4857
// RawConfig returns the merged result of all overrides

staging/src/k8s.io/kubectl/pkg/cmd/version/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ go_test(
2727
deps = [
2828
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
2929
"//staging/src/k8s.io/kubectl/pkg/cmd/util:go_default_library",
30+
"//vendor/github.com/spf13/cobra:go_default_library",
3031
],
3132
)
3233

staging/src/k8s.io/kubectl/pkg/cmd/version/version_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,26 @@ import (
2020
"strings"
2121
"testing"
2222

23+
"github.com/spf13/cobra"
24+
2325
"k8s.io/cli-runtime/pkg/genericclioptions"
2426
cmdutil "k8s.io/kubectl/pkg/cmd/util"
2527
)
2628

2729
func TestNewCmdVersionWithoutConfigFile(t *testing.T) {
2830
tf := cmdutil.NewFactory(&genericclioptions.ConfigFlags{})
2931
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
30-
cmd := NewCmdVersion(tf, streams)
31-
cmd.SetOutput(buf)
32-
if err := cmd.Execute(); err != nil {
32+
o := NewOptions(streams)
33+
if err := o.Complete(tf, &cobra.Command{}); err != nil {
34+
t.Errorf("Unexpected error: %v", err)
35+
}
36+
if err := o.Validate(); err != nil {
37+
t.Errorf("Unexpected error: %v", err)
38+
}
39+
// FIXME soltysh:
40+
// since we have defaulting to localhost:8080 in staging/src/k8s.io/client-go/tools/clientcmd/client_config.go#getDefaultServer
41+
// we need to ignore the localhost:8080 server, when above gets removed this should be dropped too
42+
if err := o.Run(); err != nil && !strings.Contains(err.Error(), "localhost:8080") {
3343
t.Errorf("Cannot execute version command: %v", err)
3444
}
3545
if !strings.Contains(buf.String(), "Client Version") {

test/cmd/legacy-script.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ runTests() {
324324
exit 1
325325
fi
326326
kube::log::status "Checking kubectl version"
327-
export KUBERNETES_MASTER=http://127.0.0.1:${API_PORT}
328327
kubectl version
329328

330329
# Generate a random namespace name, based on the current time (to make

0 commit comments

Comments
 (0)