mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 05:30:26 +00:00
Allow --output formatting of kubectl config view, make merge default
This commit is contained in:
@@ -338,7 +338,7 @@ Usage:
|
|||||||
kubectl config [command]
|
kubectl config [command]
|
||||||
|
|
||||||
Available Commands:
|
Available Commands:
|
||||||
view displays the specified .kubeconfig file or a merged result
|
view displays merged .kubeconfig settings or a specified .kubeconfig file.
|
||||||
set-cluster name [--server=server] [--certificate-authority=path/to/certficate/authority] [--api-version=apiversion] [--insecure-skip-tls-verify=true] Sets a cluster entry in .kubeconfig
|
set-cluster name [--server=server] [--certificate-authority=path/to/certficate/authority] [--api-version=apiversion] [--insecure-skip-tls-verify=true] Sets a cluster entry in .kubeconfig
|
||||||
set-credentials name [--auth-path=path/to/auth/file] [--client-certificate=path/to/certficate/file] [--client-key=path/to/key/file] [--token=bearer_token_string] Sets a user entry in .kubeconfig
|
set-credentials name [--auth-path=path/to/auth/file] [--client-certificate=path/to/certficate/file] [--client-key=path/to/key/file] [--token=bearer_token_string] Sets a user entry in .kubeconfig
|
||||||
set-context name [--cluster=cluster-nickname] [--user=user-nickname] [--namespace=namespace] Sets a context entry in .kubeconfig
|
set-context name [--cluster=cluster-nickname] [--user=user-nickname] [--namespace=namespace] Sets a context entry in .kubeconfig
|
||||||
@@ -395,7 +395,13 @@ Use "kubectl help [command]" for more information about that command.
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### config view
|
#### config view
|
||||||
displays the specified .kubeconfig file or a merged result
|
displays merged .kubeconfig settings or a specified .kubeconfig file.
|
||||||
|
Examples:
|
||||||
|
// Show merged .kubeconfig settings.
|
||||||
|
$ kubectl config view
|
||||||
|
|
||||||
|
// Show only local ./.kubeconfig settings
|
||||||
|
$ kubectl config view --local
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
```
|
```
|
||||||
@@ -421,10 +427,14 @@ Usage:
|
|||||||
--log_flush_frequency=5s: Maximum number of seconds between log flushes
|
--log_flush_frequency=5s: Maximum number of seconds between log flushes
|
||||||
--logtostderr=true: log to standard error instead of files
|
--logtostderr=true: log to standard error instead of files
|
||||||
--match-server-version=false: Require server version to match client version
|
--match-server-version=false: Require server version to match client version
|
||||||
--merge=false: merge together the full hierarchy of .kubeconfig files
|
--merge=true: merge together the full hierarchy of .kubeconfig files
|
||||||
--namespace="": If present, the namespace scope for this CLI request.
|
--namespace="": If present, the namespace scope for this CLI request.
|
||||||
|
--no-headers=false: When using the default output, don't print headers
|
||||||
|
-o, --output="": Output format: json|yaml|template|templatefile
|
||||||
|
--output-version="": Output the formatted object with the given version (default api-version)
|
||||||
-s, --server="": The address of the Kubernetes API server
|
-s, --server="": The address of the Kubernetes API server
|
||||||
--stderrthreshold=2: logs at or above this threshold go to stderr
|
--stderrthreshold=2: logs at or above this threshold go to stderr
|
||||||
|
-t, --template="": Template string or path to template file to use when -o=template or -o=templatefile.
|
||||||
--token="": Bearer token for authentication to the API server.
|
--token="": Bearer token for authentication to the API server.
|
||||||
--user="": The name of the kubeconfig user to use
|
--user="": The name of the kubeconfig user to use
|
||||||
--v=0: log level for V logs
|
--v=0: log level for V logs
|
||||||
|
@@ -21,11 +21,12 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/golang/glog"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
|
||||||
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type viewOptions struct {
|
type viewOptions struct {
|
||||||
@@ -38,40 +39,45 @@ func NewCmdConfigView(out io.Writer, pathOptions *pathOptions) *cobra.Command {
|
|||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "view",
|
Use: "view",
|
||||||
Short: "displays the specified .kubeconfig file or a merged result",
|
Short: "displays merged .kubeconfig settings or a specified .kubeconfig file.",
|
||||||
Long: `displays the specified .kubeconfig file or a merged result`,
|
Long: `displays merged .kubeconfig settings or a specified .kubeconfig file.
|
||||||
|
Examples:
|
||||||
|
// Show merged .kubeconfig settings.
|
||||||
|
$ kubectl config view
|
||||||
|
|
||||||
|
// Show only local ./.kubeconfig settings
|
||||||
|
$ kubectl config view --local`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
err := options.run()
|
printer, _, err := util.PrinterForCommand(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%v\n", err)
|
glog.FatalDepth(1, err)
|
||||||
|
}
|
||||||
|
config, err := options.loadConfig()
|
||||||
|
if err != nil {
|
||||||
|
glog.FatalDepth(1, err)
|
||||||
|
}
|
||||||
|
err = printer.PrintObj(config, out)
|
||||||
|
if err != nil {
|
||||||
|
glog.FatalDepth(1, err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Flags().BoolVar(&options.merge, "merge", false, "merge together the full hierarchy of .kubeconfig files")
|
util.AddPrinterFlags(cmd)
|
||||||
|
// Default to yaml
|
||||||
|
cmd.Flags().Set("output", "yaml")
|
||||||
|
cmd.Flags().BoolVar(&options.merge, "merge", true, "merge together the full hierarchy of .kubeconfig files")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o viewOptions) run() error {
|
func (o viewOptions) loadConfig() (*clientcmdapi.Config, error) {
|
||||||
err := o.validate()
|
err := o.validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
config, _, err := o.getStartingConfig()
|
config, _, err := o.getStartingConfig()
|
||||||
if err != nil {
|
return config, err
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
content, err := yaml.Marshal(config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("%v", string(content))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o viewOptions) validate() error {
|
func (o viewOptions) validate() error {
|
||||||
|
Reference in New Issue
Block a user