func getImageUsage(g graph.Graph, node *imagegraph.ImageNode) []string { usage := []string{} for _, e := range g.InboundEdges(node, PodImageEdgeKind) { podNode, ok := e.From().(*kubegraph.PodNode) if !ok { continue } usage = append(usage, getController(podNode.Pod)) } return usage }
func getImageParents(g graph.Graph, node *imagegraph.ImageNode) []string { parents := []string{} for _, e := range g.InboundEdges(node, ParentImageEdgeKind) { imageNode, ok := e.From().(*imagegraph.ImageNode) if !ok { continue } parents = append(parents, imageNode.Image.Name) } return parents }
func getImageStreamTags(g graph.Graph, node *imagegraph.ImageNode) []string { istags := []string{} for _, e := range g.InboundEdges(node, ImageStreamImageEdgeKind) { streamNode, ok := e.From().(*imagegraph.ImageStreamNode) if !ok { continue } stream := streamNode.ImageStream tags := getTags(stream, node.Image) istags = append(istags, fmt.Sprintf("%s/%s (%s)", stream.Namespace, stream.Name, strings.Join(tags, ","))) } return istags }
func markParentsInGraph(g graph.Graph) { imageNodes := getImageNodes(g.Nodes()) for _, in := range imageNodes { // find image's top layer, should be just one for _, e := range g.OutboundEdges(in, ImageTopLayerEdgeKind) { layerNode, _ := e.To().(*imagegraph.ImageLayerNode) // find image's containing this layer but not being their top layer for _, ed := range g.InboundEdges(layerNode, ImageLayerEdgeKind) { childNode, _ := ed.From().(*imagegraph.ImageNode) if in.ID() == childNode.ID() { // don't add self edge, otherwise gonum/graph will panic continue } g.AddEdge(in, childNode, ParentImageEdgeKind) } // TODO: Find image's containing THIS layer being their top layer, // this happens when image contents is not being changed. // TODO: If two layers have exactly the same contents the current // mechanism might trip over that as well. We should check for // a series of layers when checking for parents. } } }