describe allowedTopologies

pull/8/head
lichuqiang 2018-08-15 17:16:39 +08:00
parent 795b213455
commit eefd337ba0
2 changed files with 68 additions and 1 deletions

View File

@ -3474,6 +3474,9 @@ func describeStorageClass(sc *storage.StorageClass, events *api.EventList) (stri
if sc.VolumeBindingMode != nil {
w.Write(LEVEL_0, "VolumeBindingMode:\t%s\n", *sc.VolumeBindingMode)
}
if sc.AllowedTopologies != nil {
printAllowedTopologies(w, sc.AllowedTopologies)
}
if events != nil {
DescribeEvents(events, w)
}
@ -3482,6 +3485,38 @@ func describeStorageClass(sc *storage.StorageClass, events *api.EventList) (stri
})
}
func printAllowedTopologies(w PrefixWriter, topologies []api.TopologySelectorTerm) {
w.Write(LEVEL_0, "AllowedTopologies:\t")
if len(topologies) == 0 {
w.WriteLine("<none>")
return
}
w.WriteLine("")
for i, term := range topologies {
printTopologySelectorTermsMultilineWithIndent(w, LEVEL_1, fmt.Sprintf("Term %d", i), "\t", term.MatchLabelExpressions)
}
}
func printTopologySelectorTermsMultilineWithIndent(w PrefixWriter, indentLevel int, title, innerIndent string, reqs []api.TopologySelectorLabelRequirement) {
w.Write(indentLevel, "%s:%s", title, innerIndent)
if len(reqs) == 0 {
w.WriteLine("<none>")
return
}
for i, req := range reqs {
if i != 0 {
w.Write(indentLevel, "%s", innerIndent)
}
exprStr := fmt.Sprintf("%s %s", req.Key, "in")
if len(req.Values) > 0 {
exprStr = fmt.Sprintf("%s [%s]", exprStr, strings.Join(req.Values, ", "))
}
w.Write(LEVEL_0, "%s\n", exprStr)
}
}
type PodDisruptionBudgetDescriber struct {
clientset.Interface
}

View File

@ -1433,6 +1433,32 @@ func TestDescribeStorageClass(t *testing.T) {
},
ReclaimPolicy: &reclaimPolicy,
VolumeBindingMode: &bindingMode,
AllowedTopologies: []api.TopologySelectorTerm{
{
MatchLabelExpressions: []api.TopologySelectorLabelRequirement{
{
Key: "failure-domain.beta.kubernetes.io/zone",
Values: []string{"zone1"},
},
{
Key: "kubernetes.io/hostname",
Values: []string{"node1"},
},
},
},
{
MatchLabelExpressions: []api.TopologySelectorLabelRequirement{
{
Key: "failure-domain.beta.kubernetes.io/zone",
Values: []string{"zone2"},
},
{
Key: "kubernetes.io/hostname",
Values: []string{"node2"},
},
},
},
},
})
s := StorageClassDescriber{f}
out, err := s.Describe("", "foo", printers.DescriberSettings{ShowEvents: true})
@ -1446,7 +1472,13 @@ func TestDescribeStorageClass(t *testing.T) {
!strings.Contains(out, "value1") ||
!strings.Contains(out, "value2") ||
!strings.Contains(out, "Retain") ||
!strings.Contains(out, "bindingmode") {
!strings.Contains(out, "bindingmode") ||
!strings.Contains(out, "failure-domain.beta.kubernetes.io/zone") ||
!strings.Contains(out, "zone1") ||
!strings.Contains(out, "kubernetes.io/hostname") ||
!strings.Contains(out, "node1") ||
!strings.Contains(out, "zone2") ||
!strings.Contains(out, "node2") {
t.Errorf("unexpected out: %s", out)
}
}