mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
add resource handling before printing
Resources are currently filtered (in order to prevent printing) at print time in their HumanReadablePrinter handlers. This design makes it not possible to filter objects when they are printed using any other printer, such as YAML, JSON, or the NamePrinter. This patch removes any filters previously added at the printer level for pods and adds a way to define resource-specific filters before they are sent to a printer handler. A woking filter handler for pods has also been implemented. Filters affect resources being printed through the HumanReadablePrinter, YAML, JSON, and `--template` printers.
This commit is contained in:
@@ -1148,7 +1148,7 @@ func TestPrintPod(t *testing.T) {
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
printer := HumanReadablePrinter{hiddenObjNum: 0}
|
||||
printer := HumanReadablePrinter{}
|
||||
for _, test := range tests {
|
||||
printer.printPod(&test.pod, buf, PrintOptions{false, false, false, false, true, false, false, "", []string{}})
|
||||
// We ignore time
|
||||
@@ -1157,9 +1157,6 @@ func TestPrintPod(t *testing.T) {
|
||||
}
|
||||
buf.Reset()
|
||||
}
|
||||
if printer.hiddenObjNum > 0 {
|
||||
t.Fatalf("Expected hidden pods: 0, got: %d", printer.hiddenObjNum)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintNonTerminatedPod(t *testing.T) {
|
||||
@@ -1245,7 +1242,7 @@ func TestPrintNonTerminatedPod(t *testing.T) {
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
printer := HumanReadablePrinter{hiddenObjNum: 0}
|
||||
printer := HumanReadablePrinter{}
|
||||
for _, test := range tests {
|
||||
printer.printPod(&test.pod, buf, PrintOptions{false, false, false, false, false, false, false, "", []string{}})
|
||||
// We ignore time
|
||||
@@ -1254,9 +1251,6 @@ func TestPrintNonTerminatedPod(t *testing.T) {
|
||||
}
|
||||
buf.Reset()
|
||||
}
|
||||
if printer.hiddenObjNum != 2 {
|
||||
t.Fatalf("Expected hidden pods: 2, got: %d", printer.hiddenObjNum)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintPodWithLabels(t *testing.T) {
|
||||
@@ -1309,7 +1303,7 @@ func TestPrintPodWithLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
printer := HumanReadablePrinter{hiddenObjNum: 0}
|
||||
printer := HumanReadablePrinter{}
|
||||
for _, test := range tests {
|
||||
printer.printPod(&test.pod, buf, PrintOptions{false, false, false, false, false, false, false, "", test.labelColumns})
|
||||
// We ignore time
|
||||
@@ -1318,9 +1312,6 @@ func TestPrintPodWithLabels(t *testing.T) {
|
||||
}
|
||||
buf.Reset()
|
||||
}
|
||||
if printer.hiddenObjNum > 0 {
|
||||
t.Fatalf("Expected hidden pods: 0, got: %d", printer.hiddenObjNum)
|
||||
}
|
||||
}
|
||||
|
||||
type stringTestList []struct {
|
||||
@@ -1519,7 +1510,7 @@ func TestPrintPodShowLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
printer := HumanReadablePrinter{hiddenObjNum: 0}
|
||||
printer := HumanReadablePrinter{}
|
||||
|
||||
for _, test := range tests {
|
||||
printer.printPod(&test.pod, buf, PrintOptions{false, false, false, false, false, test.showLabels, false, "", []string{}})
|
||||
@@ -1529,7 +1520,4 @@ func TestPrintPodShowLabels(t *testing.T) {
|
||||
}
|
||||
buf.Reset()
|
||||
}
|
||||
if printer.hiddenObjNum > 0 {
|
||||
t.Fatalf("Expected hidden pods: 0, got: %d", printer.hiddenObjNum)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user