mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #52019 from zjj2wry/kubectl-config-use
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.. fix issue(11233)enhance kubectl config command **What this PR does / why we need it**: Fixes #11233 **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
2f64309d0d
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -81,3 +82,9 @@ func toBool(propertyValue string) (bool, error) {
|
|||||||
|
|
||||||
return boolValue, nil
|
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)
|
||||||
|
}
|
||||||
|
@ -150,8 +150,7 @@ func (o *createClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluste
|
|||||||
func (o *createClusterOptions) complete(cmd *cobra.Command) error {
|
func (o *createClusterOptions) complete(cmd *cobra.Command) error {
|
||||||
args := cmd.Flags().Args()
|
args := cmd.Flags().Args()
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
cmd.Help()
|
return helpErrorf(cmd, "Unexpected args: %v", args)
|
||||||
return fmt.Errorf("Unexpected args: %v", args)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
o.name = args[0]
|
o.name = args[0]
|
||||||
|
@ -121,8 +121,7 @@ func (o *createContextOptions) modifyContext(existingContext clientcmdapi.Contex
|
|||||||
func (o *createContextOptions) complete(cmd *cobra.Command) error {
|
func (o *createContextOptions) complete(cmd *cobra.Command) error {
|
||||||
args := cmd.Flags().Args()
|
args := cmd.Flags().Args()
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
cmd.Help()
|
return helpErrorf(cmd, "Unexpected args: %v", args)
|
||||||
return fmt.Errorf("Unexpected args: %v", args)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
o.name = args[0]
|
o.name = args[0]
|
||||||
|
@ -83,8 +83,7 @@ func NewCmdConfigRenameContext(out io.Writer, configAccess clientcmd.ConfigAcces
|
|||||||
// Complete assigns RenameContextOptions from the args.
|
// Complete assigns RenameContextOptions from the args.
|
||||||
func (o *RenameContextOptions) Complete(cmd *cobra.Command, args []string, out io.Writer) error {
|
func (o *RenameContextOptions) Complete(cmd *cobra.Command, args []string, out io.Writer) error {
|
||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
cmd.Help()
|
return helpErrorf(cmd, "Unexpected args: %v", args)
|
||||||
return fmt.Errorf("Unexpected args: %v", args)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
o.contextName = args[0]
|
o.contextName = args[0]
|
||||||
|
@ -106,8 +106,7 @@ func (o setOptions) run() error {
|
|||||||
func (o *setOptions) complete(cmd *cobra.Command) error {
|
func (o *setOptions) complete(cmd *cobra.Command) error {
|
||||||
endingArgs := cmd.Flags().Args()
|
endingArgs := cmd.Flags().Args()
|
||||||
if len(endingArgs) != 2 {
|
if len(endingArgs) != 2 {
|
||||||
cmd.Help()
|
return helpErrorf(cmd, "Unexpected args: %v", endingArgs)
|
||||||
return fmt.Errorf("Unexpected args: %v", endingArgs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
o.propertyValue = endingArgs[1]
|
o.propertyValue = endingArgs[1]
|
||||||
|
@ -77,18 +77,13 @@ func (o unsetOptions) run() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := clientcmd.ModifyConfig(o.configAccess, *config, false); err != nil {
|
return clientcmd.ModifyConfig(o.configAccess, *config, false)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *unsetOptions) complete(cmd *cobra.Command) error {
|
func (o *unsetOptions) complete(cmd *cobra.Command) error {
|
||||||
endingArgs := cmd.Flags().Args()
|
endingArgs := cmd.Flags().Args()
|
||||||
if len(endingArgs) != 1 {
|
if len(endingArgs) != 1 {
|
||||||
cmd.Help()
|
return helpErrorf(cmd, "Unexpected args: %v", endingArgs)
|
||||||
return fmt.Errorf("Unexpected args: %v", endingArgs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
o.propertyName = endingArgs[0]
|
o.propertyName = endingArgs[0]
|
||||||
|
@ -47,6 +47,7 @@ func NewCmdConfigUseContext(out io.Writer, configAccess clientcmd.ConfigAccess)
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "use-context CONTEXT_NAME",
|
Use: "use-context CONTEXT_NAME",
|
||||||
Short: i18n.T("Sets the current-context in a kubeconfig file"),
|
Short: i18n.T("Sets the current-context in a kubeconfig file"),
|
||||||
|
Aliases: []string{"use"},
|
||||||
Long: `Sets the current-context in a kubeconfig file`,
|
Long: `Sets the current-context in a kubeconfig file`,
|
||||||
Example: use_context_example,
|
Example: use_context_example,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
@ -72,18 +73,13 @@ func (o useContextOptions) run() error {
|
|||||||
|
|
||||||
config.CurrentContext = o.contextName
|
config.CurrentContext = o.contextName
|
||||||
|
|
||||||
if err := clientcmd.ModifyConfig(o.configAccess, *config, true); err != nil {
|
return clientcmd.ModifyConfig(o.configAccess, *config, true)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *useContextOptions) complete(cmd *cobra.Command) error {
|
func (o *useContextOptions) complete(cmd *cobra.Command) error {
|
||||||
endingArgs := cmd.Flags().Args()
|
endingArgs := cmd.Flags().Args()
|
||||||
if len(endingArgs) != 1 {
|
if len(endingArgs) != 1 {
|
||||||
cmd.Help()
|
return helpErrorf(cmd, "Unexpected args: %v", endingArgs)
|
||||||
return fmt.Errorf("Unexpected args: %v", endingArgs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
o.contextName = endingArgs[0]
|
o.contextName = endingArgs[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user