mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
[bug] Update DefaultObjectDescriber to handle interface params (#118190)
* Update DefaultObjectDescriber to handle interface params Signed-off-by: Vihang Mehta <vihang@pixielabs.ai> * Minor test cleanup for more descriptive errors Signed-off-by: Vihang Mehta <vihang@pixielabs.ai> --------- Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>
This commit is contained in:
parent
55fb1805a1
commit
56cb4c9391
@ -5030,8 +5030,12 @@ func (fn typeFunc) Matches(types []reflect.Type) bool {
|
|||||||
// Describe invokes the nested function with the exact number of arguments.
|
// Describe invokes the nested function with the exact number of arguments.
|
||||||
func (fn typeFunc) Describe(exact interface{}, extra ...interface{}) (string, error) {
|
func (fn typeFunc) Describe(exact interface{}, extra ...interface{}) (string, error) {
|
||||||
values := []reflect.Value{reflect.ValueOf(exact)}
|
values := []reflect.Value{reflect.ValueOf(exact)}
|
||||||
for _, obj := range extra {
|
for i, obj := range extra {
|
||||||
values = append(values, reflect.ValueOf(obj))
|
if obj != nil {
|
||||||
|
values = append(values, reflect.ValueOf(obj))
|
||||||
|
} else {
|
||||||
|
values = append(values, reflect.New(fn.Extra[i]).Elem())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out := fn.Fn.Call(values)
|
out := fn.Fn.Call(values)
|
||||||
s := out[0].Interface().(string)
|
s := out[0].Interface().(string)
|
||||||
|
@ -1254,7 +1254,7 @@ func TestDefaultDescribers(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(out, "foo") {
|
if !strings.Contains(out, "foo") {
|
||||||
t.Errorf("unexpected output: %s", out)
|
t.Errorf("missing Pod `foo` in output: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err = DefaultObjectDescriber.DescribeObject(&corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
|
out, err = DefaultObjectDescriber.DescribeObject(&corev1.Service{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
|
||||||
@ -1262,18 +1262,18 @@ func TestDefaultDescribers(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(out, "foo") {
|
if !strings.Contains(out, "foo") {
|
||||||
t.Errorf("unexpected output: %s", out)
|
t.Errorf("missing Service `foo` in output: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err = DefaultObjectDescriber.DescribeObject(&corev1.ReplicationController{
|
out, err = DefaultObjectDescriber.DescribeObject(&corev1.ReplicationController{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
|
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
|
||||||
Spec: corev1.ReplicationControllerSpec{Replicas: utilpointer.Int32Ptr(1)},
|
Spec: corev1.ReplicationControllerSpec{Replicas: utilpointer.Int32(1)},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(out, "foo") {
|
if !strings.Contains(out, "foo") {
|
||||||
t.Errorf("unexpected output: %s", out)
|
t.Errorf("missing Replication Controller `foo` in output: %s", out)
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err = DefaultObjectDescriber.DescribeObject(&corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
|
out, err = DefaultObjectDescriber.DescribeObject(&corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: "foo"}})
|
||||||
@ -1281,7 +1281,18 @@ func TestDefaultDescribers(t *testing.T) {
|
|||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if !strings.Contains(out, "foo") {
|
if !strings.Contains(out, "foo") {
|
||||||
t.Errorf("unexpected output: %s", out)
|
t.Errorf("missing Node `foo` output: %s", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err = DefaultObjectDescriber.DescribeObject(&appsv1.StatefulSet{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
|
||||||
|
Spec: appsv1.StatefulSetSpec{Replicas: utilpointer.Int32(1)},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if !strings.Contains(out, "foo") {
|
||||||
|
t.Errorf("missing StatefulSet `foo` in output: %s", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user