mirror of https://github.com/k3s-io/k3s
kubectl print ingress add column labels
parent
d28ac1f88b
commit
f6b5eca11c
|
@ -968,6 +968,9 @@ func printIngress(ingress *extensions.Ingress, w io.Writer, options PrintOptions
|
|||
loadBalancerStatusStringer(ingress.Status.LoadBalancer)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprint(w, appendLabels(ingress.Labels, options.ColumnLabels)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := fmt.Fprint(w, appendAllLabels(options.ShowLabels, ingress.Labels)); err != nil {
|
||||
return err
|
||||
|
|
|
@ -35,6 +35,7 @@ import (
|
|||
"k8s.io/kubernetes/pkg/runtime"
|
||||
yamlserializer "k8s.io/kubernetes/pkg/runtime/serializer/yaml"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
"k8s.io/kubernetes/pkg/util/intstr"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
|
@ -641,6 +642,41 @@ func contains(fields []string, field string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func TestPrintHunmanReadableIngressWithColumnLabels(t *testing.T) {
|
||||
ingress := extensions.Ingress{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "test1",
|
||||
CreationTimestamp: unversioned.Time{Time: time.Now().AddDate(-10, 0, 0)},
|
||||
Labels: map[string]string{
|
||||
"app_name": "kubectl_test_ingress",
|
||||
},
|
||||
},
|
||||
Spec: extensions.IngressSpec{
|
||||
Backend: &extensions.IngressBackend{
|
||||
ServiceName: "svc",
|
||||
ServicePort: intstr.FromInt(93),
|
||||
},
|
||||
},
|
||||
Status: extensions.IngressStatus{
|
||||
LoadBalancer: api.LoadBalancerStatus{
|
||||
Ingress: []api.LoadBalancerIngress{
|
||||
{
|
||||
IP: "2.3.4.5",
|
||||
Hostname: "localhost.localdomain",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
buff := bytes.Buffer{}
|
||||
printIngress(&ingress, &buff, PrintOptions{false, false, false, false, false, false, []string{"app_name"}})
|
||||
output := string(buff.Bytes())
|
||||
appName := ingress.ObjectMeta.Labels["app_name"]
|
||||
if !strings.Contains(output, appName) {
|
||||
t.Errorf("expected to container app_name label value %s, but doesn't %s", appName, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintHumanReadableService(t *testing.T) {
|
||||
tests := []api.Service{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue