func tagReferenceToTagEvent(stream *api.ImageStream, tagRef api.TagReference, tagOrID string) (*api.TagEvent, error) { switch tagRef.From.Kind { case "DockerImage": return &api.TagEvent{ Created: unversioned.Now(), DockerImageReference: tagRef.From.Name, }, nil case "ImageStreamImage": ref, err := api.DockerImageReferenceForStream(stream) if err != nil { return nil, err } resolvedIDs := api.ResolveImageID(stream, tagOrID) switch len(resolvedIDs) { case 1: ref.ID = resolvedIDs.List()[0] return &api.TagEvent{ Created: unversioned.Now(), DockerImageReference: ref.String(), Image: ref.ID, }, nil case 0: return nil, fmt.Errorf("no images match the prefix %q", tagOrID) default: return nil, fmt.Errorf("multiple images match the prefix %q: %s", tagOrID, strings.Join(resolvedIDs.List(), ", ")) } case "ImageStreamTag": return api.LatestTaggedImage(stream, tagOrID), nil default: return nil, fmt.Errorf("invalid from.kind %q: it must be ImageStreamImage or ImageStreamTag", tagRef.From.Kind) } }
func tagReferenceToTagEvent(stream *api.ImageStream, tagRef api.TagReference, tagOrID string) (*api.TagEvent, error) { var ( event *api.TagEvent err error ) switch tagRef.From.Kind { case "DockerImage": event = &api.TagEvent{ Created: unversioned.Now(), DockerImageReference: tagRef.From.Name, } case "ImageStreamImage": event, err = api.ResolveImageID(stream, tagOrID) case "ImageStreamTag": event, err = api.LatestTaggedImage(stream, tagOrID), nil default: err = fmt.Errorf("invalid from.kind %q: it must be DockerImage, ImageStreamImage or ImageStreamTag", tagRef.From.Kind) } if err != nil { return nil, err } if event != nil && tagRef.Generation != nil { event.Generation = *tagRef.Generation } return event, nil }
// Get retrieves an image by ID that has previously been tagged into an image stream. // `id` is of the form <repo name>@<image id>. func (r *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) { name, imageID, err := ParseNameAndID(id) if err != nil { return nil, err } repo, err := r.imageStreamRegistry.GetImageStream(ctx, name) if err != nil { return nil, err } if repo.Status.Tags == nil { return nil, errors.NewNotFound("imageStreamImage", imageID) } set := api.ResolveImageID(repo, imageID) switch len(set) { case 1: imageName := set.List()[0] image, err := r.imageRegistry.GetImage(ctx, imageName) if err != nil { return nil, err } imageWithMetadata, err := api.ImageWithMetadata(*image) if err != nil { return nil, err } if d, err := digest.ParseDigest(imageName); err == nil { imageName = d.Hex() } if len(imageName) > 7 { imageName = imageName[:7] } isi := api.ImageStreamImage{ ObjectMeta: kapi.ObjectMeta{ Namespace: kapi.NamespaceValue(ctx), Name: fmt.Sprintf("%s@%s", name, imageName), }, Image: *imageWithMetadata, } return &isi, nil case 0: return nil, errors.NewNotFound("imageStreamImage", imageID) default: return nil, errors.NewConflict("imageStreamImage", imageID, fmt.Errorf("multiple images match the prefix %q: %s", imageID, strings.Join(set.List(), ", "))) } }
func tagReferenceToTagEvent(stream *api.ImageStream, tagRef api.TagReference, tagOrID string) (*api.TagEvent, error) { switch tagRef.From.Kind { case "DockerImage": return &api.TagEvent{ Created: unversioned.Now(), DockerImageReference: tagRef.From.Name, }, nil case "ImageStreamImage": return api.ResolveImageID(stream, tagOrID) case "ImageStreamTag": return api.LatestTaggedImage(stream, tagOrID), nil default: return nil, fmt.Errorf("invalid from.kind %q: it must be DockerImage, ImageStreamImage or ImageStreamTag", tagRef.From.Kind) } }
// Get retrieves an image by ID that has previously been tagged into an image stream. // `id` is of the form <repo name>@<image id>. func (r *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) { name, imageID, err := ParseNameAndID(id) if err != nil { return nil, err } repo, err := r.imageStreamRegistry.GetImageStream(ctx, name) if err != nil { return nil, err } if repo.Status.Tags == nil { return nil, errors.NewNotFound("imageStreamImage", imageID) } event, err := api.ResolveImageID(repo, imageID) if err != nil { return nil, err } imageName := event.Image image, err := r.imageRegistry.GetImage(ctx, imageName) if err != nil { return nil, err } imageWithMetadata, err := api.ImageWithMetadata(*image) if err != nil { return nil, err } if d, err := digest.ParseDigest(imageName); err == nil { imageName = d.Hex() } if len(imageName) > 7 { imageName = imageName[:7] } isi := api.ImageStreamImage{ ObjectMeta: kapi.ObjectMeta{ Namespace: kapi.NamespaceValue(ctx), Name: fmt.Sprintf("%s@%s", name, imageName), }, Image: *imageWithMetadata, } return &isi, nil }
// Get retrieves an image by ID that has previously been tagged into an image stream. // `id` is of the form <repo name>@<image id>. func (r *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) { name, imageID, err := parseNameAndID(id) if err != nil { return nil, err } repo, err := r.imageStreamRegistry.GetImageStream(ctx, name) if err != nil { return nil, err } if repo.Status.Tags == nil { return nil, errors.NewNotFound(api.Resource("imagestreamimage"), id) } event, err := api.ResolveImageID(repo, imageID) if err != nil { return nil, err } imageName := event.Image image, err := r.imageRegistry.GetImage(ctx, imageName) if err != nil { return nil, err } if err := api.ImageWithMetadata(image); err != nil { return nil, err } image.DockerImageManifest = "" isi := api.ImageStreamImage{ ObjectMeta: kapi.ObjectMeta{ Namespace: kapi.NamespaceValue(ctx), Name: api.MakeImageStreamImageName(name, imageID), CreationTimestamp: image.ObjectMeta.CreationTimestamp, }, Image: *image, } return &isi, nil }