コード例 #1
0
ファイル: imagepolicy.go プロジェクト: abhgupta/origin
// ResolveObjectReference converts a reference into an image API or returns an error. If the kind is not recognized
// this method will return an error to prevent references that may be images from being ignored.
func (c *imageResolutionCache) ResolveObjectReference(ref *kapi.ObjectReference, defaultNamespace string) (*rules.ImagePolicyAttributes, error) {
	switch ref.Kind {
	case "ImageStreamTag":
		ns := ref.Namespace
		if len(ns) == 0 {
			ns = defaultNamespace
		}
		name, tag, ok := imageapi.SplitImageStreamTag(ref.Name)
		if !ok {
			return &rules.ImagePolicyAttributes{IntegratedRegistry: true}, fmt.Errorf("references of kind ImageStreamTag must be of the form NAME:TAG")
		}
		return c.resolveImageStreamTag(ns, name, tag)

	case "ImageStreamImage":
		ns := ref.Namespace
		if len(ns) == 0 {
			ns = defaultNamespace
		}
		name, id, ok := imageapi.SplitImageStreamImage(ref.Name)
		if !ok {
			return &rules.ImagePolicyAttributes{IntegratedRegistry: true}, fmt.Errorf("references of kind ImageStreamImage must be of the form NAME@DIGEST")
		}
		return c.resolveImageStreamImage(ns, name, id)

	case "DockerImage":
		ref, err := imageapi.ParseDockerImageReference(ref.Name)
		if err != nil {
			return nil, err
		}
		return c.resolveImageReference(ref)

	default:
		return nil, fmt.Errorf("image policy does not allow image references of kind %q", ref.Kind)
	}
}
コード例 #2
0
ファイル: debug.go プロジェクト: xgwang-zte/origin
func (o *DebugOptions) getContainerImageCommand(container *kapi.Container) ([]string, error) {
	image := container.Image[strings.LastIndex(container.Image, "/")+1:]
	name, id, ok := imageapi.SplitImageStreamImage(image)
	if !ok {
		return nil, errors.New("container image did not contain an id")
	}
	isimage, err := o.Client.ImageStreamImages(o.Attach.Pod.Namespace).Get(name, id)
	if err != nil {
		return nil, err
	}

	config := isimage.Image.DockerImageMetadata.Config
	return append(config.Entrypoint, config.Cmd...), nil
}
コード例 #3
0
ファイル: resolve.go プロジェクト: juanluisvaladas/origin
// ResolveImagePullSpec resolves the provided source which can be "docker", "istag" or
// "isimage" and returns the full Docker pull spec.
func ResolveImagePullSpec(images client.ImageStreamImagesNamespacer, tags client.ImageStreamTagsNamespacer, source, name, defaultNamespace string) (string, error) {
	// for Docker source, just passtrough the image name
	if IsDocker(source) {
		return name, nil
	}
	// parse the namespace from the provided image
	namespace, image := splitNamespaceAndImage(name)
	if len(namespace) == 0 {
		namespace = defaultNamespace
	}

	dockerImageReference := ""

	if IsImageStreamTag(source) {
		name, tag, ok := imageapi.SplitImageStreamTag(image)
		if !ok {
			return "", fmt.Errorf("invalid image stream tag %q, must be of the form [NAMESPACE/]NAME:TAG", name)
		}
		if resolved, err := tags.ImageStreamTags(namespace).Get(name, tag); err != nil {
			return "", fmt.Errorf("failed to get image stream tag %q: %v", name, err)
		} else {
			dockerImageReference = resolved.Image.DockerImageReference
		}
	}

	if IsImageStreamImage(source) {
		name, digest, ok := imageapi.SplitImageStreamImage(image)
		if !ok {
			return "", fmt.Errorf("invalid image stream image %q, must be of the form [NAMESPACE/]NAME@DIGEST", name)
		}
		if resolved, err := images.ImageStreamImages(namespace).Get(name, digest); err != nil {
			return "", fmt.Errorf("failed to get image stream image %q: %v", name, err)
		} else {
			dockerImageReference = resolved.Image.DockerImageReference
		}
	}

	if len(dockerImageReference) == 0 {
		return "", fmt.Errorf("unable to resolve %s %q", source, name)
	}

	reference, err := imageapi.ParseDockerImageReference(dockerImageReference)
	if err != nil {
		return "", err
	}
	return reference.String(), nil
}
コード例 #4
0
ファイル: types.go プロジェクト: juanluisvaladas/origin
func (n ImageStreamImageNode) ImageTag() string {
	_, id, _ := imageapi.SplitImageStreamImage(n.ImageStreamImage.Name)
	return id
}