本文整理匯總了Golang中github.com/openshift/origin/pkg/image/api.LatestTaggedImage函數的典型用法代碼示例。如果您正苦於以下問題:Golang LatestTaggedImage函數的具體用法?Golang LatestTaggedImage怎麽用?Golang LatestTaggedImage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了LatestTaggedImage函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Get
func (t tagService) Get(ctx context.Context, tag string) (distribution.Descriptor, error) {
imageStream, err := t.repo.getImageStream()
if err != nil {
context.GetLogger(ctx).Errorf("error retrieving ImageStream %s/%s: %v", t.repo.namespace, t.repo.name, err)
return distribution.Descriptor{}, distribution.ErrRepositoryUnknown{Name: t.repo.Named().Name()}
}
te := imageapi.LatestTaggedImage(imageStream, tag)
if te == nil {
return distribution.Descriptor{}, distribution.ErrTagUnknown{Tag: tag}
}
dgst, err := digest.ParseDigest(te.Image)
if err != nil {
return distribution.Descriptor{}, err
}
if !t.repo.pullthrough {
image, err := t.repo.getImage(dgst)
if err != nil {
return distribution.Descriptor{}, err
}
if !isImageManaged(image) {
return distribution.Descriptor{}, distribution.ErrTagUnknown{Tag: tag}
}
}
return distribution.Descriptor{Digest: dgst}, nil
}
示例2: tagReferenceToTagEvent
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)
}
}
示例3: tagReferenceToTagEvent
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
}
示例4: FromStream
// FromStream generates an ImageRef from an OpenShift ImageStream
func (g *imageRefGenerator) FromStream(stream *imageapi.ImageStream, tag string) (*ImageRef, error) {
imageRef := &ImageRef{
Stream: stream,
}
if tagged := imageapi.LatestTaggedImage(stream, tag); tagged != nil {
if ref, err := imageapi.ParseDockerImageReference(tagged.DockerImageReference); err == nil {
imageRef.ResolvedReference = &ref
imageRef.Reference = ref
}
}
if pullSpec := stream.Status.DockerImageRepository; len(pullSpec) != 0 {
ref, err := imageapi.ParseDockerImageReference(pullSpec)
if err != nil {
return nil, err
}
imageRef.Reference = ref
}
switch {
case len(tag) > 0:
imageRef.Reference.Tag = tag
case len(tag) == 0 && len(imageRef.Reference.Tag) == 0:
imageRef.Reference.Tag = imageapi.DefaultImageTag
}
return imageRef, nil
}
示例5: Untag
func (t tagService) Untag(ctx context.Context, tag string) error {
imageStream, err := t.repo.getImageStream()
if err != nil {
context.GetLogger(ctx).Errorf("error retrieving ImageStream %s/%s: %v", t.repo.namespace, t.repo.name, err)
return distribution.ErrRepositoryUnknown{Name: t.repo.Named().Name()}
}
te := imageapi.LatestTaggedImage(imageStream, tag)
if te == nil {
return distribution.ErrTagUnknown{Tag: tag}
}
if !t.repo.pullthrough {
dgst, err := digest.ParseDigest(te.Image)
if err != nil {
return err
}
image, err := t.repo.getImage(dgst)
if err != nil {
return err
}
if !isImageManaged(image) {
return distribution.ErrTagUnknown{Tag: tag}
}
}
return t.repo.registryOSClient.ImageStreamTags(imageStream.Namespace).Delete(imageStream.Name, tag)
}
示例6: Handle
// Handle processes image change triggers associated with imageRepo.
func (c *ImageChangeController) Handle(imageRepo *imageapi.ImageStream) error {
configs, err := c.deploymentConfigClient.listDeploymentConfigs()
if err != nil {
return fmt.Errorf("couldn't get list of DeploymentConfig while handling ImageStream %s: %v", labelForRepo(imageRepo), err)
}
// Find any configs which should be updated based on the new image state
configsToUpdate := map[string]*deployapi.DeploymentConfig{}
for _, config := range configs {
glog.V(4).Infof("Detecting changed images for DeploymentConfig %s", deployutil.LabelForDeploymentConfig(config))
for _, trigger := range config.Triggers {
params := trigger.ImageChangeParams
// Only automatic image change triggers should fire
if trigger.Type != deployapi.DeploymentTriggerOnImageChange || !params.Automatic {
continue
}
// Check if the image repo matches the trigger
if !triggerMatchesImage(config, params, imageRepo) {
continue
}
// Find the latest tag event for the trigger tag
latestEvent := imageapi.LatestTaggedImage(imageRepo, params.Tag)
if latestEvent == nil {
glog.V(2).Infof("Couldn't find latest tag event for tag %s in ImageStream %s", params.Tag, labelForRepo(imageRepo))
continue
}
// Ensure a change occurred
if len(latestEvent.DockerImageReference) > 0 &&
latestEvent.DockerImageReference != params.LastTriggeredImage {
// Mark the config for regeneration
configsToUpdate[config.Name] = config
}
}
}
// Attempt to regenerate all configs which may contain image updates
anyFailed := false
for _, config := range configsToUpdate {
err := c.regenerate(config)
if err != nil {
anyFailed = true
glog.V(2).Infof("Couldn't regenerate DeploymentConfig %s: %s", deployutil.LabelForDeploymentConfig(config), err)
continue
}
glog.V(4).Infof("Regenerated DeploymentConfig %s in response to image change trigger", deployutil.LabelForDeploymentConfig(config))
}
if anyFailed {
return fatalError(fmt.Sprintf("couldn't update some DeploymentConfig for trigger on ImageStream %s", labelForRepo(imageRepo)))
}
glog.V(4).Infof("Updated all DeploymentConfigs for trigger on ImageStream %s", labelForRepo(imageRepo))
return nil
}
示例7: imageFor
// imageFor retrieves the most recent image for a tag in a given imageStreem.
func (r *REST) imageFor(ctx kapi.Context, tag string, imageStream *api.ImageStream) (*api.Image, error) {
event := api.LatestTaggedImage(imageStream, tag)
if event == nil || len(event.Image) == 0 {
return nil, kapierrors.NewNotFound("imageStreamTag", api.JoinImageStreamTag(imageStream.Name, tag))
}
return r.imageRegistry.GetImage(ctx, event.Image)
}
示例8: getImageReferenceForObjectReference
// getImageReferenceForObjectReference returns corresponding docker image reference for the given object
// reference representing either an image stream image or image stream tag or docker image.
func (c *GenericImageStreamUsageComputer) getImageReferenceForObjectReference(
namespace string,
objRef *kapi.ObjectReference,
) (imageapi.DockerImageReference, error) {
switch objRef.Kind {
case "ImageStreamImage":
nameParts := strings.Split(objRef.Name, "@")
if len(nameParts) != 2 {
return imageapi.DockerImageReference{}, fmt.Errorf("failed to parse name of imageStreamImage %q", objRef.Name)
}
res, err := imageapi.ParseDockerImageReference(objRef.Name)
if err != nil {
return imageapi.DockerImageReference{}, err
}
if res.Namespace == "" {
res.Namespace = objRef.Namespace
}
if res.Namespace == "" {
res.Namespace = namespace
}
return res, nil
case "ImageStreamTag":
// This is really fishy. An admission check can be easily worked around by setting a tag reference
// to an ImageStreamTag with no or small image and then tagging a large image to the source tag.
// TODO: Shall we refuse an ImageStreamTag set in the spec if the quota is set?
nameParts := strings.Split(objRef.Name, ":")
if len(nameParts) != 2 {
return imageapi.DockerImageReference{}, fmt.Errorf("failed to parse name of imageStreamTag %q", objRef.Name)
}
ns := namespace
if len(objRef.Namespace) > 0 {
ns = objRef.Namespace
}
isName := nameParts[0]
is, err := c.getImageStream(ns, isName)
if err != nil {
return imageapi.DockerImageReference{}, fmt.Errorf("failed to get imageStream for ImageStreamTag %s/%s: %v", ns, objRef.Name, err)
}
event := imageapi.LatestTaggedImage(is, nameParts[1])
if event == nil || len(event.DockerImageReference) == 0 {
return imageapi.DockerImageReference{}, fmt.Errorf("%q is not currently pointing to an image, cannot use it as the source of a tag", objRef.Name)
}
return imageapi.ParseDockerImageReference(event.DockerImageReference)
case "DockerImage":
managedByOS, ref := imageReferenceBelongsToInternalRegistry(objRef.Name)
if !managedByOS {
return imageapi.DockerImageReference{}, fmt.Errorf("DockerImage %s does not belong to internal registry", objRef.Name)
}
return ref, nil
}
return imageapi.DockerImageReference{}, fmt.Errorf("unsupported object reference kind %s", objRef.Kind)
}
示例9: Resolve
// Resolve will attempt to find an imagestream with a name that matches the passed in value
func (r ImageStreamResolver) Resolve(value string) (*ComponentMatch, error) {
ref, err := imageapi.ParseDockerImageReference(value)
if err != nil || len(ref.Registry) != 0 {
return nil, fmt.Errorf("image repositories must be of the form [<namespace>/]<name>[:<tag>|@<digest>]")
}
namespaces := r.Namespaces
if len(ref.Namespace) != 0 {
namespaces = []string{ref.Namespace}
}
searchTag := ref.Tag
if len(searchTag) == 0 {
searchTag = imageapi.DefaultImageTag
}
for _, namespace := range namespaces {
glog.V(4).Infof("checking ImageStream %s/%s with ref %q", namespace, ref.Name, searchTag)
repo, err := r.Client.ImageStreams(namespace).Get(ref.Name)
if err != nil {
if errors.IsNotFound(err) || errors.IsForbidden(err) {
continue
}
return nil, err
}
ref.Namespace = namespace
latest := imageapi.LatestTaggedImage(repo, searchTag)
if latest == nil {
// continue searching in the next namespace
glog.V(2).Infof("no image recorded for %s/%s:%s", repo.Namespace, repo.Name, searchTag)
continue
}
imageStreamImage, err := r.ImageStreamImages.ImageStreamImages(namespace).Get(ref.Name, latest.Image)
if err != nil {
if errors.IsNotFound(err) {
// continue searching in the next namespace
glog.V(2).Infof("tag %q is set, but image %q has been removed", searchTag, latest.Image)
continue
}
return nil, err
}
imageData := imageStreamImage.Image
ref.Registry = ""
return &ComponentMatch{
Value: ref.String(),
Argument: fmt.Sprintf("--image=%q", ref.String()),
Name: ref.Name,
Description: fmt.Sprintf("Image repository %s (tag %q) in project %s, tracks %q", repo.Name, searchTag, repo.Namespace, repo.Status.DockerImageRepository),
Builder: IsBuilderImage(&imageData.DockerImageMetadata),
Score: 0,
ImageStream: repo,
Image: &imageData.DockerImageMetadata,
ImageTag: searchTag,
}, nil
}
return nil, ErrNoMatch{value: value}
}
示例10: annotationMatches
func (r *ImageStreamByAnnotationSearcher) annotationMatches(stream *imageapi.ImageStream, value string) []*ComponentMatch {
if stream.Spec.Tags == nil {
glog.Infof("No tags found on image, returning nil")
return nil
}
matches := []*ComponentMatch{}
for tag, tagref := range stream.Spec.Tags {
if tagref.Annotations == nil {
continue
}
supports, ok := tagref.Annotations[supportsAnnotationKey]
if !ok {
continue
}
score, ok := matchSupportsAnnotation(value, supports)
if !ok {
continue
}
latest := imageapi.LatestTaggedImage(stream, tag)
if latest == nil {
continue
}
imageStream, err := r.ImageStreamImages.ImageStreamImages(stream.Namespace).Get(stream.Name, latest.Image)
if err != nil {
glog.V(2).Infof("Could not retrieve image stream image for stream %q, tag %q: %v", stream.Name, tag, err)
continue
}
if imageStream == nil {
continue
}
// indicate the server knows how to directly tag images
var meta map[string]string
if imageStream.Generation > 0 {
meta = map[string]string{"direct-tag": "1"}
}
imageData := imageStream.Image
matchName := fmt.Sprintf("%s/%s", stream.Namespace, stream.Name)
glog.V(5).Infof("ImageStreamAnnotationSearcher match found: %s for %s with score %f", matchName, value, score)
match := &ComponentMatch{
Value: value,
Name: fmt.Sprintf("%s", matchName),
Argument: fmt.Sprintf("--image-stream=%q", matchName),
Description: fmt.Sprintf("Image stream %s in project %s", stream.Name, stream.Namespace),
Score: score,
ImageStream: stream,
Image: &imageData.DockerImageMetadata,
ImageTag: tag,
Meta: meta,
}
matches = append(matches, match)
}
return matches
}
示例11: newISTag
func newISTag(tag string, imageStream *api.ImageStream, image *api.Image) (*api.ImageStreamTag, error) {
istagName := api.JoinImageStreamTag(imageStream.Name, tag)
event := api.LatestTaggedImage(imageStream, tag)
if event == nil || len(event.Image) == 0 {
return nil, kapierrors.NewNotFound("imageStreamTag", istagName)
}
ist := &api.ImageStreamTag{
ObjectMeta: kapi.ObjectMeta{
Namespace: imageStream.Namespace,
Name: istagName,
CreationTimestamp: event.Created,
Annotations: map[string]string{},
ResourceVersion: imageStream.ResourceVersion,
},
}
// if the imageStream has Spec.Tags[tag].Annotations[k] = v, copy it to the image's annotations
// and add them to the istag's annotations
if imageStream.Spec.Tags != nil {
if tagRef, ok := imageStream.Spec.Tags[tag]; ok {
if image != nil && image.Annotations == nil {
image.Annotations = make(map[string]string)
}
for k, v := range tagRef.Annotations {
ist.Annotations[k] = v
if image != nil {
image.Annotations[k] = v
}
}
}
}
if image != nil {
imageWithMetadata, err := api.ImageWithMetadata(*image)
if err != nil {
return nil, err
}
ist.Image = *imageWithMetadata
} else {
ist.Image = api.Image{}
ist.Image.Name = event.Image
}
// Replace the DockerImageReference with the value from event, which contains
// real value from status. This should fix the problem for v1 registries,
// where mutliple tags point to a single id and only the first image's metadata
// is saved. This in turn will always return the pull spec from the first
// imported image, which might be different than the requested tag.
ist.Image.DockerImageReference = event.DockerImageReference
return ist, nil
}
示例12: Get
// Get retrieves an image that has been tagged by stream and tag. `id` is of the format
// <stream name>:<tag>.
func (r *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {
name, tag, err := nameAndTag(id)
if err != nil {
return nil, err
}
stream, err := r.imageStreamRegistry.GetImageStream(ctx, name)
if err != nil {
return nil, err
}
event := api.LatestTaggedImage(stream, tag)
if event == nil || len(event.Image) == 0 {
return nil, errors.NewNotFound("imageStreamTag", id)
}
image, err := r.imageRegistry.GetImage(ctx, event.Image)
if err != nil {
return nil, err
}
// if the stream has Spec.Tags[tag].Annotations[k] = v, copy it to the image's annotations
if stream.Spec.Tags != nil {
if tagRef, ok := stream.Spec.Tags[tag]; ok {
if image.Annotations == nil {
image.Annotations = make(map[string]string)
}
for k, v := range tagRef.Annotations {
image.Annotations[k] = v
}
}
}
imageWithMetadata, err := api.ImageWithMetadata(*image)
if err != nil {
return nil, err
}
ist := api.ImageStreamTag{
ObjectMeta: kapi.ObjectMeta{
Namespace: kapi.NamespaceValue(ctx),
Name: id,
CreationTimestamp: event.Created,
},
Image: *imageWithMetadata,
}
return &ist, nil
}
示例13: tagReferenceToTagEvent
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)
}
}
示例14: annotationMatches
func (r *ImageStreamByAnnotationResolver) annotationMatches(stream *imageapi.ImageStream, value string) []*ComponentMatch {
if stream.Spec.Tags == nil {
glog.Infof("No tags found on image, returning nil")
return nil
}
matches := []*ComponentMatch{}
for tag, tagref := range stream.Spec.Tags {
if tagref.Annotations == nil {
continue
}
supports, ok := tagref.Annotations[supportsAnnotationKey]
if !ok {
continue
}
score, ok := matchSupportsAnnotation(value, supports)
if !ok {
continue
}
latest := imageapi.LatestTaggedImage(stream, tag)
if latest == nil {
continue
}
imageStream, err := r.ImageStreamImages.ImageStreamImages(stream.Namespace).Get(stream.Name, latest.Image)
if err != nil {
glog.V(2).Infof("Could not retrieve image stream image for stream %q, tag %q: %v", stream.Name, tag, err)
continue
}
if imageStream == nil {
continue
}
imageData := imageStream.Image
match := &ComponentMatch{
Value: value,
Name: stream.Name,
Argument: fmt.Sprintf("--image-stream=%q", value),
Description: fmt.Sprintf("Image stream %s in project %s, tracks %q", stream.Name, stream.Namespace, stream.Status.DockerImageRepository),
Builder: IsBuilderImage(&imageData.DockerImageMetadata),
Score: score,
ImageStream: stream,
Image: &imageData.DockerImageMetadata,
ImageTag: imageapi.DefaultImageTag,
}
matches = append(matches, match)
}
return matches
}
示例15: processTriggers
// processTriggers will go over all deployment triggers that require processing and update
// the deployment config accordingly. This contains the work that the image change controller
// had been doing up to the point we got the /instantiate endpoint.
func processTriggers(config *deployapi.DeploymentConfig, isn client.ImageStreamsNamespacer, force bool) error {
errs := []error{}
// Process any image change triggers.
for _, trigger := range config.Spec.Triggers {
if trigger.Type != deployapi.DeploymentTriggerOnImageChange {
continue
}
params := trigger.ImageChangeParams
// Forced deployments should always try to resolve the images in the template.
// On the other hand, paused deployments or non-automatic triggers shouldn't.
if !force && (config.Spec.Paused || !params.Automatic) {
continue
}
// Tag references are already validated
name, tag, _ := imageapi.SplitImageStreamTag(params.From.Name)
stream, err := isn.ImageStreams(params.From.Namespace).Get(name)
if err != nil {
if !errors.IsNotFound(err) {
errs = append(errs, err)
}
continue
}
// Find the latest tag event for the trigger reference.
latestEvent := imageapi.LatestTaggedImage(stream, tag)
if latestEvent == nil {
continue
}
// Ensure a change occurred
latestRef := latestEvent.DockerImageReference
if len(latestRef) == 0 || latestRef == params.LastTriggeredImage {
continue
}
// Update containers
names := sets.NewString(params.ContainerNames...)
for i := range config.Spec.Template.Spec.Containers {
container := &config.Spec.Template.Spec.Containers[i]
if !names.Has(container.Name) {
continue
}
if container.Image != latestRef {
// Update the image
container.Image = latestRef
// Log the last triggered image ID
params.LastTriggeredImage = latestRef
}
}
}
if err := utilerrors.NewAggregate(errs); err != nil {
return errors.NewInternalError(err)
}
return nil
}