Skip to content

Commit

Permalink
filter lastAppliedConfig annotation for describe secret
Browse files Browse the repository at this point in the history
  • Loading branch information
ymqytw committed Oct 26, 2016
1 parent d5668d6 commit bd9e4f8
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/kubectl/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/kubernetes/federation/apis/federation"
fed_clientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/annotations"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/events"
"k8s.io/kubernetes/pkg/api/resource"
Expand Down Expand Up @@ -1380,7 +1381,8 @@ func describeSecret(secret *api.Secret) (string, error) {
fmt.Fprintf(out, "Name:\t%s\n", secret.Name)
fmt.Fprintf(out, "Namespace:\t%s\n", secret.Namespace)
printLabelsMultiline(out, "Labels", secret.Labels)
printLabelsMultiline(out, "Annotations", secret.Annotations)
skipMap := map[string]bool{annotations.LastAppliedConfigAnnotation: true}
printLabelsMultilineWithFilter(out, "Annotations", secret.Annotations, skipMap)

fmt.Fprintf(out, "\nType:\t%s\n", secret.Type)

Expand Down Expand Up @@ -2526,13 +2528,18 @@ func (fn typeFunc) Describe(exact interface{}, extra ...interface{}) (string, er
return s, err
}

// printLabelsMultilineWithFilter prints filtered multiple labels with a proper alignment.
func printLabelsMultilineWithFilter(out io.Writer, title string, labels map[string]string, skipMap map[string]bool) {
printLabelsMultilineWithIndent(out, "", title, "\t", labels, skipMap)
}

// printLabelsMultiline prints multiple labels with a proper alignment.
func printLabelsMultiline(out io.Writer, title string, labels map[string]string) {
printLabelsMultilineWithIndent(out, "", title, "\t", labels)
printLabelsMultilineWithIndent(out, "", title, "\t", labels, nil)
}

// printLabelsMultiline prints multiple labels with a user-defined alignment.
func printLabelsMultilineWithIndent(out io.Writer, initialIndent, title, innerIndent string, labels map[string]string) {
func printLabelsMultilineWithIndent(out io.Writer, initialIndent, title, innerIndent string, labels map[string]string, skipMap map[string]bool) {

fmt.Fprintf(out, "%s%s:%s", initialIndent, title, innerIndent)

Expand All @@ -2544,8 +2551,17 @@ func printLabelsMultilineWithIndent(out io.Writer, initialIndent, title, innerIn
// to print labels in the sorted order
keys := make([]string, 0, len(labels))
for key := range labels {
if skipMap != nil {
if _, skip := skipMap[key]; skip {
continue
}
}
keys = append(keys, key)
}
if len(keys) == 0 {
fmt.Fprintln(out, "<none>")
return
}
sort.Strings(keys)

for i, key := range keys {
Expand Down

0 comments on commit bd9e4f8

Please sign in to comment.