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
e62bc0b7
Commit
e62bc0b7
authored
Sep 14, 2017
by
zhengjiajin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix issue(11233)enhance kubectl config command
parent
8b9f0ea5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
16 additions
and
22 deletions
+16
-22
config.go
pkg/kubectl/cmd/config/config.go
+7
-0
create_cluster.go
pkg/kubectl/cmd/config/create_cluster.go
+1
-2
create_context.go
pkg/kubectl/cmd/config/create_context.go
+1
-2
rename_context.go
pkg/kubectl/cmd/config/rename_context.go
+1
-2
set.go
pkg/kubectl/cmd/config/set.go
+1
-2
unset.go
pkg/kubectl/cmd/config/unset.go
+2
-7
use_context.go
pkg/kubectl/cmd/config/use_context.go
+3
-7
No files found.
pkg/kubectl/cmd/config/config.go
View file @
e62bc0b7
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
config
import
(
"fmt"
"io"
"path"
"strconv"
...
...
@@ -81,3 +82,9 @@ func toBool(propertyValue string) (bool, error) {
return
boolValue
,
nil
}
func
helpErrorf
(
cmd
*
cobra
.
Command
,
format
string
,
args
...
interface
{})
error
{
cmd
.
Help
()
msg
:=
fmt
.
Sprintf
(
format
,
args
...
)
return
fmt
.
Errorf
(
"%s
\n
"
,
msg
)
}
pkg/kubectl/cmd/config/create_cluster.go
View file @
e62bc0b7
...
...
@@ -150,8 +150,7 @@ func (o *createClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluste
func
(
o
*
createClusterOptions
)
complete
(
cmd
*
cobra
.
Command
)
error
{
args
:=
cmd
.
Flags
()
.
Args
()
if
len
(
args
)
!=
1
{
cmd
.
Help
()
return
fmt
.
Errorf
(
"Unexpected args: %v"
,
args
)
return
helpErrorf
(
cmd
,
"Unexpected args: %v"
,
args
)
}
o
.
name
=
args
[
0
]
...
...
pkg/kubectl/cmd/config/create_context.go
View file @
e62bc0b7
...
...
@@ -121,8 +121,7 @@ func (o *createContextOptions) modifyContext(existingContext clientcmdapi.Contex
func
(
o
*
createContextOptions
)
complete
(
cmd
*
cobra
.
Command
)
error
{
args
:=
cmd
.
Flags
()
.
Args
()
if
len
(
args
)
!=
1
{
cmd
.
Help
()
return
fmt
.
Errorf
(
"Unexpected args: %v"
,
args
)
return
helpErrorf
(
cmd
,
"Unexpected args: %v"
,
args
)
}
o
.
name
=
args
[
0
]
...
...
pkg/kubectl/cmd/config/rename_context.go
View file @
e62bc0b7
...
...
@@ -83,8 +83,7 @@ func NewCmdConfigRenameContext(out io.Writer, configAccess clientcmd.ConfigAcces
// Complete assigns RenameContextOptions from the args.
func
(
o
*
RenameContextOptions
)
Complete
(
cmd
*
cobra
.
Command
,
args
[]
string
,
out
io
.
Writer
)
error
{
if
len
(
args
)
!=
2
{
cmd
.
Help
()
return
fmt
.
Errorf
(
"Unexpected args: %v"
,
args
)
return
helpErrorf
(
cmd
,
"Unexpected args: %v"
,
args
)
}
o
.
contextName
=
args
[
0
]
...
...
pkg/kubectl/cmd/config/set.go
View file @
e62bc0b7
...
...
@@ -106,8 +106,7 @@ func (o setOptions) run() error {
func
(
o
*
setOptions
)
complete
(
cmd
*
cobra
.
Command
)
error
{
endingArgs
:=
cmd
.
Flags
()
.
Args
()
if
len
(
endingArgs
)
!=
2
{
cmd
.
Help
()
return
fmt
.
Errorf
(
"Unexpected args: %v"
,
endingArgs
)
return
helpErrorf
(
cmd
,
"Unexpected args: %v"
,
endingArgs
)
}
o
.
propertyValue
=
endingArgs
[
1
]
...
...
pkg/kubectl/cmd/config/unset.go
View file @
e62bc0b7
...
...
@@ -77,18 +77,13 @@ func (o unsetOptions) run() error {
return
err
}
if
err
:=
clientcmd
.
ModifyConfig
(
o
.
configAccess
,
*
config
,
false
);
err
!=
nil
{
return
err
}
return
nil
return
clientcmd
.
ModifyConfig
(
o
.
configAccess
,
*
config
,
false
)
}
func
(
o
*
unsetOptions
)
complete
(
cmd
*
cobra
.
Command
)
error
{
endingArgs
:=
cmd
.
Flags
()
.
Args
()
if
len
(
endingArgs
)
!=
1
{
cmd
.
Help
()
return
fmt
.
Errorf
(
"Unexpected args: %v"
,
endingArgs
)
return
helpErrorf
(
cmd
,
"Unexpected args: %v"
,
endingArgs
)
}
o
.
propertyName
=
endingArgs
[
0
]
...
...
pkg/kubectl/cmd/config/use_context.go
View file @
e62bc0b7
...
...
@@ -47,6 +47,7 @@ func NewCmdConfigUseContext(out io.Writer, configAccess clientcmd.ConfigAccess)
cmd
:=
&
cobra
.
Command
{
Use
:
"use-context CONTEXT_NAME"
,
Short
:
i18n
.
T
(
"Sets the current-context in a kubeconfig file"
),
Aliases
:
[]
string
{
"use"
},
Long
:
`Sets the current-context in a kubeconfig file`
,
Example
:
use_context_example
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -72,18 +73,13 @@ func (o useContextOptions) run() error {
config
.
CurrentContext
=
o
.
contextName
if
err
:=
clientcmd
.
ModifyConfig
(
o
.
configAccess
,
*
config
,
true
);
err
!=
nil
{
return
err
}
return
nil
return
clientcmd
.
ModifyConfig
(
o
.
configAccess
,
*
config
,
true
)
}
func
(
o
*
useContextOptions
)
complete
(
cmd
*
cobra
.
Command
)
error
{
endingArgs
:=
cmd
.
Flags
()
.
Args
()
if
len
(
endingArgs
)
!=
1
{
cmd
.
Help
()
return
fmt
.
Errorf
(
"Unexpected args: %v"
,
endingArgs
)
return
helpErrorf
(
cmd
,
"Unexpected args: %v"
,
endingArgs
)
}
o
.
contextName
=
endingArgs
[
0
]
...
...
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