Skip to content

Commit

Permalink
Merge pull request #1039 from tanjunchen/remove-master-flag
Browse files Browse the repository at this point in the history
⚠️ Remove deprecated "--master" flag
  • Loading branch information
k8s-ci-robot committed Aug 4, 2020
2 parents be832a1 + 339e946 commit cb7f858
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
13 changes: 4 additions & 9 deletions pkg/client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ import (
)

var (
kubeconfig, apiServerURL string
log = logf.RuntimeLog.WithName("client").WithName("config")
kubeconfig string
log = logf.RuntimeLog.WithName("client").WithName("config")
)

func init() {
// TODO: Fix this to allow double vendoring this library but still register flags on behalf of users
flag.StringVar(&kubeconfig, "kubeconfig", "",
"Paths to a kubeconfig. Only required if out-of-cluster.")

// This flag is deprecated, it'll be removed in a future iteration, please switch to --kubeconfig.
flag.StringVar(&apiServerURL, "master", "",
"(Deprecated: switch to `--kubeconfig`) The address of the Kubernetes API server. Overrides any value in kubeconfig. "+
"Only required if out-of-cluster.")
}

// GetConfig creates a *rest.Config for talking to a Kubernetes API server.
Expand Down Expand Up @@ -105,7 +100,7 @@ func loadConfig(context string) (*rest.Config, error) {

// If a flag is specified with the config location, use that
if len(kubeconfig) > 0 {
return loadConfigWithContext(apiServerURL, &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig}, context)
return loadConfigWithContext("", &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig}, context)
}

// If the recommended kubeconfig env variable is not specified,
Expand Down Expand Up @@ -134,7 +129,7 @@ func loadConfig(context string) (*rest.Config, error) {
loadingRules.Precedence = append(loadingRules.Precedence, path.Join(u.HomeDir, clientcmd.RecommendedHomeDir, clientcmd.RecommendedFileName))
}

return loadConfigWithContext(apiServerURL, loadingRules, context)
return loadConfigWithContext("", loadingRules, context)
}

func loadConfigWithContext(apiServerURL string, loader clientcmd.ClientConfigLoader, context string) (*rest.Config, error) {
Expand Down
11 changes: 0 additions & 11 deletions pkg/client/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

type testCase struct {
text string
apiServerURL string
context string
kubeconfigFlag string
kubeconfigEnv []string
Expand All @@ -56,7 +55,6 @@ var _ = Describe("Config", func() {
AfterEach(func() {
os.Unsetenv(clientcmd.RecommendedConfigPathEnvVar)
kubeconfig = ""
apiServerURL = ""
clientcmd.RecommendedHomeFile = origRecommendedHomeFile

err := os.RemoveAll(dir)
Expand Down Expand Up @@ -158,12 +156,6 @@ var _ = Describe("Config", func() {
kubeconfigEnv: []string{"kubeconfig-multi-context"},
wantHost: "from-multi-env-1",
},
{
text: "should allow overriding the API server URL",
apiServerURL: "override",
kubeconfigEnv: []string{"kubeconfig-multi-context"},
wantHost: "override",
},
{
text: "should allow overriding the context",
context: "from-multi-env-2",
Expand All @@ -183,9 +175,6 @@ var _ = Describe("Config", func() {
})

func setConfigs(tc testCase, dir string) {
// Set API Server URL
apiServerURL = tc.apiServerURL

// Set kubeconfig flag value
if len(tc.kubeconfigFlag) > 0 {
kubeconfig = filepath.Join(dir, tc.kubeconfigFlag)
Expand Down

0 comments on commit cb7f858

Please sign in to comment.