mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
kubectl config get-contexts: sort output
This commit is contained in:
parent
6000712803
commit
9f7468599e
@ -19,6 +19,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
@ -138,6 +139,7 @@ func (o GetContextsOptions) RunGetContexts() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Strings(toPrint)
|
||||||
for _, name := range toPrint {
|
for _, name := range toPrint {
|
||||||
err = printContext(name, config.Contexts[name], out, o.nameOnly, config.CurrentContext == name)
|
err = printContext(name, config.Contexts[name], out, o.nameOnly, config.CurrentContext == name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -66,6 +66,27 @@ func TestGetContextsAllNoHeader(t *testing.T) {
|
|||||||
test.run(t)
|
test.run(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetContextsAllSorted(t *testing.T) {
|
||||||
|
tconf := clientcmdapi.Config{
|
||||||
|
CurrentContext: "shaker-context",
|
||||||
|
Contexts: map[string]*clientcmdapi.Context{
|
||||||
|
"shaker-context": {AuthInfo: "blue-user", Cluster: "big-cluster", Namespace: "saw-ns"},
|
||||||
|
"abc": {AuthInfo: "blue-user", Cluster: "abc-cluster", Namespace: "kube-system"},
|
||||||
|
"xyz": {AuthInfo: "blue-user", Cluster: "xyz-cluster", Namespace: "default"}}}
|
||||||
|
test := getContextsTest{
|
||||||
|
startingConfig: tconf,
|
||||||
|
names: []string{},
|
||||||
|
noHeader: false,
|
||||||
|
nameOnly: false,
|
||||||
|
expectedOut: `CURRENT NAME CLUSTER AUTHINFO NAMESPACE
|
||||||
|
abc abc-cluster blue-user kube-system
|
||||||
|
* shaker-context big-cluster blue-user saw-ns
|
||||||
|
xyz xyz-cluster blue-user default
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
test.run(t)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetContextsAllName(t *testing.T) {
|
func TestGetContextsAllName(t *testing.T) {
|
||||||
tconf := clientcmdapi.Config{
|
tconf := clientcmdapi.Config{
|
||||||
Contexts: map[string]*clientcmdapi.Context{
|
Contexts: map[string]*clientcmdapi.Context{
|
||||||
|
Loading…
Reference in New Issue
Block a user