ReadCacheSnapshot reads all objects owned by root object.
(transCtx graph.TransformContext, root client.Object, ml client.MatchingLabels, kinds ...client.ObjectList)
| 188 | |
| 189 | // ReadCacheSnapshot reads all objects owned by root object. |
| 190 | func ReadCacheSnapshot(transCtx graph.TransformContext, root client.Object, ml client.MatchingLabels, kinds ...client.ObjectList) (ObjectSnapshot, error) { |
| 191 | snapshot := make(ObjectSnapshot) |
| 192 | inNs := client.InNamespace(root.GetNamespace()) |
| 193 | for _, list := range kinds { |
| 194 | if err := transCtx.GetClient().List(transCtx.GetContext(), list, inNs, ml); err != nil { |
| 195 | return nil, err |
| 196 | } |
| 197 | // reflect get list.Items |
| 198 | items := reflect.ValueOf(list).Elem().FieldByName("Items") |
| 199 | l := items.Len() |
| 200 | for i := 0; i < l; i++ { |
| 201 | // get the underlying object |
| 202 | object := items.Index(i).Addr().Interface().(client.Object) |
| 203 | name, err := GetGVKName(object) |
| 204 | if err != nil { |
| 205 | return nil, err |
| 206 | } |
| 207 | snapshot[*name] = object |
| 208 | } |
| 209 | } |
| 210 | return snapshot, nil |
| 211 | } |
| 212 | |
| 213 | func DefaultLess(v1, v2 graph.Vertex) bool { |
| 214 | o1, ok1 := v1.(*ObjectVertex) |
no test coverage detected
searching dependent graphs…