// AddInputOutputEdges links the build config to other nodes for the images and source repositories it depends on. func AddInputOutputEdges(g osgraph.MutableUniqueGraph, node *buildgraph.BuildConfigNode) *buildgraph.BuildConfigNode { output := node.BuildConfig.Spec.Output to := output.To switch { case to == nil: case to.Kind == "DockerImage": out := imagegraph.EnsureDockerRepositoryNode(g, to.Name, "") g.AddEdge(node, out, BuildOutputEdgeKind) case to.Kind == "ImageStreamTag": out := imagegraph.FindOrCreateSyntheticImageStreamTagNode(g, imagegraph.MakeImageStreamTagObjectMeta2(defaultNamespace(to.Namespace, node.BuildConfig.Namespace), to.Name)) g.AddEdge(node, out, BuildOutputEdgeKind) } if in := buildgraph.EnsureSourceRepositoryNode(g, node.BuildConfig.Spec.Source); in != nil { g.AddEdge(in, node, BuildInputEdgeKind) } from := buildutil.GetImageStreamForStrategy(node.BuildConfig.Spec.Strategy) if from != nil { switch from.Kind { case "DockerImage": if ref, err := imageapi.ParseDockerImageReference(from.Name); err == nil { tag := ref.Tag ref.Tag = "" in := imagegraph.EnsureDockerRepositoryNode(g, ref.String(), tag) g.AddEdge(in, node, BuildInputImageEdgeKind) } case "ImageStream": in := imagegraph.FindOrCreateSyntheticImageStreamTagNode(g, imagegraph.MakeImageStreamTagObjectMeta(defaultNamespace(from.Namespace, node.BuildConfig.Namespace), from.Name, imageapi.DefaultImageTag)) g.AddEdge(in, node, BuildInputImageEdgeKind) case "ImageStreamTag": in := imagegraph.FindOrCreateSyntheticImageStreamTagNode(g, imagegraph.MakeImageStreamTagObjectMeta2(defaultNamespace(from.Namespace, node.BuildConfig.Namespace), from.Name)) g.AddEdge(in, node, BuildInputImageEdgeKind) case "ImageStreamImage": in := imagegraph.FindOrCreateSyntheticImageStreamImageNode(g, imagegraph.MakeImageStreamImageObjectMeta(defaultNamespace(from.Namespace, node.BuildConfig.Namespace), from.Name)) g.AddEdge(in, node, BuildInputImageEdgeKind) } } return node }
func imageRefNode(g osgraph.MutableUniqueGraph, ref *kapi.ObjectReference, bc *buildapi.BuildConfig) graph.Node { if ref == nil { return nil } switch ref.Kind { case "DockerImage": if ref, err := imageapi.ParseDockerImageReference(ref.Name); err == nil { tag := ref.Tag ref.Tag = "" return imagegraph.EnsureDockerRepositoryNode(g, ref.String(), tag) } case "ImageStream": return imagegraph.FindOrCreateSyntheticImageStreamTagNode(g, imagegraph.MakeImageStreamTagObjectMeta(defaultNamespace(ref.Namespace, bc.Namespace), ref.Name, imageapi.DefaultImageTag)) case "ImageStreamTag": return imagegraph.FindOrCreateSyntheticImageStreamTagNode(g, imagegraph.MakeImageStreamTagObjectMeta2(defaultNamespace(ref.Namespace, bc.Namespace), ref.Name)) case "ImageStreamImage": return imagegraph.FindOrCreateSyntheticImageStreamImageNode(g, imagegraph.MakeImageStreamImageObjectMeta(defaultNamespace(ref.Namespace, bc.Namespace), ref.Name)) } return nil }
// RunBuildChain contains all the necessary functionality for the OpenShift // experimental build-chain command func (o *BuildChainOptions) RunBuildChain() error { ist := imagegraph.MakeImageStreamTagObjectMeta2(o.defaultNamespace, o.name) desc, err := describe.NewChainDescriber(o.c, o.namespaces, o.output).Describe(ist, !o.triggerOnly, o.reverse) if err != nil { if _, isNotFoundErr := err.(describe.NotFoundErr); isNotFoundErr { name, tag, _ := imageapi.SplitImageStreamTag(o.name) // Try to get the imageStreamTag via a direct GET if _, getErr := o.t.ImageStreamTags(o.defaultNamespace).Get(name, tag); getErr != nil { return getErr } fmt.Printf("Image stream tag %q in %q doesn't have any dependencies.\n", o.name, o.defaultNamespace) return nil } return err } fmt.Println(desc) return nil }