本文整理汇总了Golang中github.com/openshift/origin/pkg/image/api.LatestTaggedImage函数的典型用法代码示例。如果您正苦于以下问题:Golang LatestTaggedImage函数的具体用法?Golang LatestTaggedImage怎么用?Golang LatestTaggedImage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LatestTaggedImage函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:Xmagicer,项目名称:origin,代码行数:29,代码来源:tagservice.go
示例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)
}
}
开发者ID:kcbabo,项目名称:origin,代码行数:34,代码来源:strategy.go
示例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
}
开发者ID:RomainVabre,项目名称:origin,代码行数:27,代码来源:strategy.go
示例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
}
开发者ID:RomainVabre,项目名称:origin,代码行数:29,代码来源:imageref.go
示例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)
}
开发者ID:Xmagicer,项目名称:origin,代码行数:30,代码来源:tagservice.go
示例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
}
开发者ID:jhadvig,项目名称:origin,代码行数:61,代码来源:controller.go
示例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)
}
开发者ID:johnmccawley,项目名称:origin,代码行数:9,代码来源:rest.go
示例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)
}
开发者ID:asiainfoLDP,项目名称:datafactory,代码行数:60,代码来源:usage.go
示例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}
}
开发者ID:mignev,项目名称:origin,代码行数:57,代码来源:imagelookup.go
示例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
}
开发者ID:erinboyd,项目名称:origin,代码行数:56,代码来源:imagestreamlookup.go
示例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
}
开发者ID:johnmccawley,项目名称:origin,代码行数:54,代码来源:rest.go
示例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
}
开发者ID:nitintutlani,项目名称:origin,代码行数:50,代码来源:rest.go
示例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)
}
}
开发者ID:johnmccawley,项目名称:origin,代码行数:16,代码来源:strategy.go
示例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
}
开发者ID:cjnygard,项目名称:origin,代码行数:47,代码来源:imagelookup.go
示例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
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:65,代码来源:rest.go
示例16: Generate
// Generate returns a potential future DeploymentConfig based on the DeploymentConfig specified
// by namespace and name. Returns a RESTful error.
func (g *DeploymentConfigGenerator) Generate(ctx kapi.Context, name string) (*deployapi.DeploymentConfig, error) {
config, err := g.Client.GetDeploymentConfig(ctx, name)
if err != nil {
return nil, err
}
// Update the containers with new images based on defined triggers
configChanged := false
errs := field.ErrorList{}
causes := []deployapi.DeploymentCause{}
for i, trigger := range config.Spec.Triggers {
params := trigger.ImageChangeParams
// Only process image change triggers
if trigger.Type != deployapi.DeploymentTriggerOnImageChange {
continue
}
name, tag, ok := imageapi.SplitImageStreamTag(params.From.Name)
if !ok {
f := field.NewPath("triggers").Index(i).Child("imageChange", "from")
errs = append(errs, field.Invalid(f, name, err.Error()))
continue
}
// Find the image repo referred to by the trigger params
imageStream, err := g.findImageStream(config, params)
if err != nil {
f := field.NewPath("triggers").Index(i).Child("imageChange", "from")
errs = append(errs, field.Invalid(f, name, err.Error()))
continue
}
// Find the latest tag event for the trigger tag
latestEvent := imageapi.LatestTaggedImage(imageStream, tag)
if latestEvent == nil {
f := field.NewPath("triggers").Index(i).Child("imageChange", "tag")
errs = append(errs, field.Invalid(f, tag, fmt.Sprintf("no image recorded for %s/%s:%s", imageStream.Namespace, imageStream.Name, tag)))
continue
}
// Update containers
template := config.Spec.Template
names := sets.NewString(params.ContainerNames...)
containerChanged := false
for i := range template.Spec.Containers {
container := &template.Spec.Containers[i]
if !names.Has(container.Name) {
continue
}
if len(latestEvent.DockerImageReference) > 0 &&
container.Image != latestEvent.DockerImageReference {
// Update the image
container.Image = latestEvent.DockerImageReference
// Log the last triggered image ID
params.LastTriggeredImage = latestEvent.DockerImageReference
containerChanged = true
}
}
// If any container was updated, create a cause for the change
if containerChanged {
configChanged = true
causes = append(causes, deployapi.DeploymentCause{
Type: deployapi.DeploymentTriggerOnImageChange,
ImageTrigger: &deployapi.DeploymentCauseImageTrigger{
From: kapi.ObjectReference{
Name: imageapi.JoinImageStreamTag(imageStream.Name, tag),
Kind: "ImageStreamTag",
},
},
})
}
}
if len(errs) > 0 {
return nil, errors.NewInvalid(deployapi.Kind("DeploymentConfig"), config.Name, errs)
}
// Bump the version if we updated containers or if this is an initial
// deployment
if configChanged || config.Status.LatestVersion == 0 {
config.Status.Details = &deployapi.DeploymentDetails{
Causes: causes,
}
config.Status.LatestVersion++
}
return config, nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:92,代码来源:config_generator.go
示例17: Search
// Search will attempt to find imagestreams with names that matches the passed in value
func (r ImageStreamSearcher) Search(terms ...string) (ComponentMatches, error) {
componentMatches := ComponentMatches{}
for _, term := range terms {
ref, err := imageapi.ParseDockerImageReference(term)
if err != nil || len(ref.Registry) != 0 {
return nil, fmt.Errorf("image streams 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 ImageStreams %s/%s with ref %q", namespace, ref.Name, searchTag)
streams, err := r.Client.ImageStreams(namespace).List(labels.Everything(), fields.Everything())
if err != nil {
if errors.IsNotFound(err) || errors.IsForbidden(err) {
continue
}
return nil, err
}
ref.Namespace = namespace
for i := 0; i < len(streams.Items); i++ {
stream := streams.Items[i]
score, scored := imageStreamScorer(stream, ref.Name)
if scored {
imageref, _ := imageapi.ParseDockerImageReference(term)
imageref.Name = stream.Name
latest := imageapi.LatestTaggedImage(&stream, searchTag)
if latest == nil {
glog.V(2).Infof("no image recorded for %s/%s:%s", stream.Namespace, stream.Name, searchTag)
componentMatches = append(componentMatches, &ComponentMatch{
Value: imageref.String(),
Argument: fmt.Sprintf("--image-stream=%q", imageref.String()),
Name: imageref.Name,
Description: fmt.Sprintf("Image stream %s in project %s, tracks %q", stream.Name, stream.Namespace, stream.Status.DockerImageRepository),
Score: 0.5 + score,
ImageStream: &stream,
ImageTag: searchTag,
})
continue
}
imageStreamImage, err := r.ImageStreamImages.ImageStreamImages(namespace).Get(stream.Name, latest.Image)
if err != nil {
if errors.IsNotFound(err) {
// continue searching
glog.V(2).Infof("tag %q is set, but image %q has been removed", searchTag, latest.Image)
continue
}
return nil, err
}
imageData := imageStreamImage.Image
imageref.Registry = ""
componentMatches = append(componentMatches, &ComponentMatch{
Value: imageref.String(),
Argument: fmt.Sprintf("--image-stream=%q", imageref.String()),
Name: imageref.Name,
Description: fmt.Sprintf("Image stream %q (tag %q) in project %q, tracks %q", stream.Name, searchTag, stream.Namespace, stream.Status.DockerImageRepository),
Builder: IsBuilderImage(&imageData.DockerImageMetadata),
Score: score,
ImageStream: &stream,
Image: &imageData.DockerImageMetadata,
ImageTag: searchTag,
})
}
}
}
}
return componentMatches, nil
}
开发者ID:nstrug,项目名称:origin,代码行数:77,代码来源:imagestreamlookup.go
示例18: TestTrackingTags
func TestTrackingTags(t *testing.T) {
client, server, storage := setup(t)
defer server.Terminate(t)
stream := &api.ImageStream{
ObjectMeta: kapi.ObjectMeta{
Namespace: "default",
Name: "stream",
},
Spec: api.ImageStreamSpec{
Tags: map[string]api.TagReference{
"tracking": {
From: &kapi.ObjectReference{
Kind: "ImageStreamTag",
Name: "2.0",
},
},
"tracking2": {
From: &kapi.ObjectReference{
Kind: "ImageStreamTag",
Name: "2.0",
},
},
},
},
Status: api.ImageStreamStatus{
Tags: map[string]api.TagEventList{
"tracking": {
Items: []api.TagEvent{
{
DockerImageReference: "foo/[email protected]:1234",
Image: "1234",
},
},
},
"nontracking": {
Items: []api.TagEvent{
{
DockerImageReference: "bar/[email protected]:9999",
Image: "9999",
},
},
},
"2.0": {
Items: []api.TagEvent{
{
DockerImageReference: "foo/[email protected]:1234",
Image: "1234",
},
},
},
},
},
}
_, err := client.Create(
context.TODO(),
etcdtest.AddPrefix("/imagestreams/default/stream"),
runtime.EncodeOrDie(kapi.Codecs.LegacyCodec(v1.SchemeGroupVersion), stream),
)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
image := &api.Image{
ObjectMeta: kapi.ObjectMeta{
Name: "5678",
},
DockerImageReference: "foo/[email protected]:5678",
}
mapping := api.ImageStreamMapping{
ObjectMeta: kapi.ObjectMeta{
Namespace: "default",
Name: "stream",
},
Image: *image,
Tag: "2.0",
}
_, err = storage.Create(kapi.NewDefaultContext(), &mapping)
if err != nil {
t.Fatalf("Unexpected error creating mapping: %v", err)
}
stream, err = storage.imageStreamRegistry.GetImageStream(kapi.NewDefaultContext(), "stream")
if err != nil {
t.Fatalf("error extracting updated stream: %v", err)
}
for _, trackingTag := range []string{"tracking", "tracking2"} {
tracking := api.LatestTaggedImage(stream, trackingTag)
if tracking == nil {
t.Fatalf("unexpected nil %s TagEvent", trackingTag)
}
if e, a := image.DockerImageReference, tracking.DockerImageReference; e != a {
t.Errorf("dockerImageReference: expected %s, got %s", e, a)
}
if e, a := image.Name, tracking.Image; e != a {
//.........这里部分代码省略.........
开发者ID:legionus,项目名称:origin,代码行数:101,代码来源:rest_test.go
示例19: Complete
// Complete completes all the required options for the tag command.
func (o *TagOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
if len(args) < 2 && (len(args) < 1 && !o.deleteTag) {
return cmdutil.UsageError(cmd, "you must specify a source and at least one destination or one or more tags to delete")
}
// Setup writer.
o.out = out
// Setup client.
var err error
o.osClient, _, err = f.Clients()
if err != nil {
return err
}
// Setup namespace.
defaultNamespace, _, err := f.DefaultNamespace()
if err != nil {
return err
}
// Populate source.
if !o.deleteTag {
source := args[0]
glog.V(3).Infof("Using %q as a source tag", source)
sourceKind := o.sourceKind
if len(sourceKind) > 0 {
sourceKind = determineSourceKind(f, sourceKind)
}
if len(sourceKind) > 0 {
validSources := sets.NewString("imagestreamtag", "istag", "imagestreamimage", "isimage", "docker", "dockerimage")
if !validSources.Has(strings.ToLower(sourceKind)) {
cmdutil.CheckErr(cmdutil.UsageError(cmd, "invalid source %q; valid values are %v", o.sourceKind, strings.Join(validSources.List(), ", ")))
}
}
ref, err := imageapi.ParseDockerImageReference(source)
if err != nil {
return fmt.Errorf("invalid SOURCE: %v", err)
}
switch sourceKind {
case "ImageStreamTag", "ImageStreamImage":
if len(ref.Registry) > 0 {
return fmt.Errorf("server in SOURCE is only allowed when providing a Docker image")
}
if ref.Namespace == imageapi.DockerDefaultNamespace {
ref.Namespace = defaultNamespace
}
if sourceKind == "ImageStreamTag" {
if len(ref.Tag) == 0 {
return fmt.Errorf("--source=ImageStreamTag requires a valid <name>:<tag> in SOURCE")
}
} else {
if len(ref.ID) == 0 {
return fmt.Errorf("--source=ImageStreamImage requires a valid <name>@<id> in SOURCE")
}
}
case "":
if len(ref.Registry) > 0 {
sourceKind = "DockerImage"
break
}
if len(ref.ID) > 0 {
sourceKind = "ImageStreamImage"
break
}
if len(ref.Tag) > 0 {
sourceKind = "ImageStreamTag"
break
}
sourceKind = "DockerImage"
}
// if we are not aliasing the tag, specify the exact value to copy
if sourceKind == "ImageStreamTag" && !o.aliasTag {
srcNamespace := ref.Namespace
if len(srcNamespace) == 0 {
srcNamespace = defaultNamespace
}
is, err := o.osClient.ImageStreams(srcNamespace).Get(ref.Name)
if err != nil {
return err
}
event := imageapi.LatestTaggedImage(is, ref.Tag)
if event == nil {
return fmt.Errorf("%q is not currently pointing to an image, cannot use it as the source of a tag", args[0])
}
if len(event.Image) == 0 {
imageRef, err := imageapi.ParseDockerImageReference(event.DockerImageReference)
if err != nil {
return fmt.Errorf("the image stream tag %q has an invalid pull spec and cannot be used to tag: %v", args[0], err)
}
ref = imageRef
sourceKind = "DockerImage"
} else {
ref.ID = event.Image
ref.Tag = ""
sourceKind = "ImageStreamImage"
//.........这里部分代码省略.........
开发者ID:hloganathan,项目名称:origin,代码行数:101,代码来源:tag.go
示例20: HandleImageRepo
// HandleImageRepo processes the next ImageStream event.
func (c *ImageChangeController) HandleImageRepo(repo *imageapi.ImageStream) error {
glog.V(4).Infof("Build image change controller detected ImageStream change %s", repo.Status.DockerImageRepository)
// Loop through all build configurations and record if there was an error
// instead of breaking the loop. The error will be returned in the end, so the
// retry controller can retry. Any BuildConfigs that were processed successfully
// should have had their LastTriggeredImageID updated, so the retry should result
// in a no-op for them.
hasError := false
// TODO: this is inefficient
for _, bc := range c.BuildConfigStore.List() {
config := bc.(*buildapi.BuildConfig)
from := buildutil.GetImageStreamForStrategy(config.Parameters.Strategy)
if from == nil || from.Kind != "ImageStreamTag" {
continue
}
shouldBuild := false
triggeredImage := ""
// For every ImageChange trigger find the latest tagged image from the image repository and replace that value
// throughout the build strategies. A new build is triggered only if the latest tagged image id or pull spec
// differs from the last triggered build recorded on the build config.
for _, trigger := range config.Triggers {
if trigger.Type != buildapi.ImageChangeBuildTriggerType {
continue
}
fromStreamName := getImageStreamNameFromReference(from)
fromNamespace := from.Namespace
if len(fromNamespace) == 0 {
fromNamespace = config.Namespace
}
// only trigger a build if this image repo matches the name and namespace of the ref in the build trigger
// also do not trigger if the imagerepo does not have a valid DockerImageRepository value for us to pull
// the image from
if len(repo.Status.DockerImageRepository) == 0 || fromStreamName != repo.Name || fromNamespace != repo.Namespace {
continue
}
// This split is safe because ImageStreamTag names always have the form
// name:tag.
tag := strings.Split(from.Name, ":")[1]
latest := imageapi.LatestTaggedImage(repo, tag)
if latest == nil {
glog.V(4).Infof("unable to find tagged image: no image recorded for %s/%s:%s", repo.Namespace, repo.Name, tag)
continue
}
glog.V(4).Infof("Found ImageStream %s/%s with tag %s", repo.Namespace, repo.Name, tag)
// (must be different) to trigger a build
last := trigger.ImageChange.LastTriggeredImageID
next := latest.DockerImageReference
if len(last) == 0 || (len(next) > 0 && next != last) {
triggeredImage = next
shouldBuild = true
// it doesn't really make sense to have multiple image change triggers any more,
// so just exit the loop now
break
}
}
if shouldBuild {
glog.V(4).Infof("Running build for BuildConfig %s/%s", config.Namespace, config.Name)
// instantiate new build
request := &buildapi.BuildRequest{
ObjectMeta: kapi.ObjectMeta{
Name: config.Name,
Namespace: config.Namespace,
},
TriggeredByImage: &kapi.ObjectReference{
Kin
|
请发表评论