-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
cruiser.go
43 lines (35 loc) · 804 Bytes
/
cruiser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dao
import (
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
)
func mustMap(o runtime.Object, field string) map[string]interface{} {
u, ok := o.(*unstructured.Unstructured)
if !ok {
panic("no unstructured")
}
m, ok := u.Object[field].(map[string]interface{})
if !ok {
panic(fmt.Sprintf("map extract failed for %q", field))
}
return m
}
func mustSlice(o runtime.Object, field string) []interface{} {
u, ok := o.(*unstructured.Unstructured)
if !ok {
return []interface{}{}
}
s, ok := u.Object[field].([]interface{})
if !ok {
return []interface{}{}
}
return s
}
func mustField(o map[string]interface{}, field string) interface{} {
f, ok := o[field]
if !ok {
panic(fmt.Sprintf("no field for %q", field))
}
return f
}