Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9d58c8fb
Unverified
Commit
9d58c8fb
authored
Jan 19, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Jan 19, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #71117 from dixudx/read_kubeconfig_once
loads kubeconfig only once
parents
e31ecf82
4b524ef9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
cmd.go
pkg/kubectl/cmd/cmd.go
+1
-1
config_flags.go
.../k8s.io/cli-runtime/pkg/genericclioptions/config_flags.go
+31
-1
ns.go
staging/src/k8s.io/sample-cli-plugin/pkg/cmd/ns.go
+1
-1
No files found.
pkg/kubectl/cmd/cmd.go
View file @
9d58c8fb
...
@@ -423,7 +423,7 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
...
@@ -423,7 +423,7 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
addProfilingFlags
(
flags
)
addProfilingFlags
(
flags
)
kubeConfigFlags
:=
genericclioptions
.
NewConfigFlags
()
kubeConfigFlags
:=
genericclioptions
.
NewConfigFlags
(
true
)
kubeConfigFlags
.
AddFlags
(
flags
)
kubeConfigFlags
.
AddFlags
(
flags
)
matchVersionKubeConfigFlags
:=
cmdutil
.
NewMatchVersionFlags
(
kubeConfigFlags
)
matchVersionKubeConfigFlags
:=
cmdutil
.
NewMatchVersionFlags
(
kubeConfigFlags
)
matchVersionKubeConfigFlags
.
AddFlags
(
cmds
.
PersistentFlags
())
matchVersionKubeConfigFlags
.
AddFlags
(
cmds
.
PersistentFlags
())
...
...
staging/src/k8s.io/cli-runtime/pkg/genericclioptions/config_flags.go
View file @
9d58c8fb
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"strings"
"strings"
"sync"
"time"
"time"
"github.com/spf13/pflag"
"github.com/spf13/pflag"
...
@@ -92,6 +93,13 @@ type ConfigFlags struct {
...
@@ -92,6 +93,13 @@ type ConfigFlags struct {
Username
*
string
Username
*
string
Password
*
string
Password
*
string
Timeout
*
string
Timeout
*
string
clientConfig
clientcmd
.
ClientConfig
lock
sync
.
Mutex
// If set to true, will use persistent client config and
// propagate the config to the places that need it, rather than
// loading the config multiple times
usePersistentConfig
bool
}
}
// ToRESTConfig implements RESTClientGetter.
// ToRESTConfig implements RESTClientGetter.
...
@@ -106,6 +114,13 @@ func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
...
@@ -106,6 +114,13 @@ func (f *ConfigFlags) ToRESTConfig() (*rest.Config, error) {
// Returns an interactive clientConfig if the password flag is enabled,
// Returns an interactive clientConfig if the password flag is enabled,
// or a non-interactive clientConfig otherwise.
// or a non-interactive clientConfig otherwise.
func
(
f
*
ConfigFlags
)
ToRawKubeConfigLoader
()
clientcmd
.
ClientConfig
{
func
(
f
*
ConfigFlags
)
ToRawKubeConfigLoader
()
clientcmd
.
ClientConfig
{
if
f
.
usePersistentConfig
{
return
f
.
toRawKubePersistentConfigLoader
()
}
return
f
.
toRawKubeConfigLoader
()
}
func
(
f
*
ConfigFlags
)
toRawKubeConfigLoader
()
clientcmd
.
ClientConfig
{
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
loadingRules
:=
clientcmd
.
NewDefaultClientConfigLoadingRules
()
// use the standard defaults for this client command
// use the standard defaults for this client command
// DEPRECATED: remove and replace with something more accurate
// DEPRECATED: remove and replace with something more accurate
...
@@ -181,6 +196,19 @@ func (f *ConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig {
...
@@ -181,6 +196,19 @@ func (f *ConfigFlags) ToRawKubeConfigLoader() clientcmd.ClientConfig {
return
clientConfig
return
clientConfig
}
}
// toRawKubePersistentConfigLoader binds config flag values to config overrides
// Returns a persistent clientConfig for propagation.
func
(
f
*
ConfigFlags
)
toRawKubePersistentConfigLoader
()
clientcmd
.
ClientConfig
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
clientConfig
==
nil
{
f
.
clientConfig
=
f
.
toRawKubeConfigLoader
()
}
return
f
.
clientConfig
}
// ToDiscoveryClient implements RESTClientGetter.
// ToDiscoveryClient implements RESTClientGetter.
// Expects the AddFlags method to have been called.
// Expects the AddFlags method to have been called.
// Returns a CachedDiscoveryInterface using a computed RESTConfig.
// Returns a CachedDiscoveryInterface using a computed RESTConfig.
...
@@ -285,7 +313,7 @@ func (f *ConfigFlags) WithDeprecatedPasswordFlag() *ConfigFlags {
...
@@ -285,7 +313,7 @@ func (f *ConfigFlags) WithDeprecatedPasswordFlag() *ConfigFlags {
}
}
// NewConfigFlags returns ConfigFlags with default values set
// NewConfigFlags returns ConfigFlags with default values set
func
NewConfigFlags
()
*
ConfigFlags
{
func
NewConfigFlags
(
usePersistentConfig
bool
)
*
ConfigFlags
{
impersonateGroup
:=
[]
string
{}
impersonateGroup
:=
[]
string
{}
insecure
:=
false
insecure
:=
false
...
@@ -306,6 +334,8 @@ func NewConfigFlags() *ConfigFlags {
...
@@ -306,6 +334,8 @@ func NewConfigFlags() *ConfigFlags {
BearerToken
:
stringptr
(
""
),
BearerToken
:
stringptr
(
""
),
Impersonate
:
stringptr
(
""
),
Impersonate
:
stringptr
(
""
),
ImpersonateGroup
:
&
impersonateGroup
,
ImpersonateGroup
:
&
impersonateGroup
,
usePersistentConfig
:
usePersistentConfig
,
}
}
}
}
...
...
staging/src/k8s.io/sample-cli-plugin/pkg/cmd/ns.go
View file @
9d58c8fb
...
@@ -66,7 +66,7 @@ type NamespaceOptions struct {
...
@@ -66,7 +66,7 @@ type NamespaceOptions struct {
// NewNamespaceOptions provides an instance of NamespaceOptions with default values
// NewNamespaceOptions provides an instance of NamespaceOptions with default values
func
NewNamespaceOptions
(
streams
genericclioptions
.
IOStreams
)
*
NamespaceOptions
{
func
NewNamespaceOptions
(
streams
genericclioptions
.
IOStreams
)
*
NamespaceOptions
{
return
&
NamespaceOptions
{
return
&
NamespaceOptions
{
configFlags
:
genericclioptions
.
NewConfigFlags
(),
configFlags
:
genericclioptions
.
NewConfigFlags
(
true
),
IOStreams
:
streams
,
IOStreams
:
streams
,
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment