From c3ca06a6036331b46dddea4a3c3ca4b7f19fb4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Tue, 20 Sep 2016 15:21:11 +0200 Subject: [PATCH] Use dockerImageDestination.PutManifest in openshiftDestination.PutManifest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of manipulating an ImageStreamMapping and having to do exactly what OpenShift does, just use the Docker Registry API and let the server side deal with that. This fixes “unexpected end of JSON input” when uploading schema2 manifests (because we didn’t also include the config object), and should resolve https://github.com/projectatomic/skopeo/issues/208 (by using the existing code on the server side) Signed-off-by: Miloslav Trmač --- openshift/openshift.go | 42 +----------------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/openshift/openshift.go b/openshift/openshift.go index 1e2873fd65..615695f255 100644 --- a/openshift/openshift.go +++ b/openshift/openshift.go @@ -353,47 +353,13 @@ func (d *openshiftImageDestination) PutBlob(stream io.Reader, inputInfo types.Bl } func (d *openshiftImageDestination) PutManifest(m []byte) error { - // FIXME? Can this eventually just call d.docker.PutManifest()? - - // Note: This does absolutely no kind/version checking or conversions. manifestDigest, err := manifest.Digest(m) if err != nil { return err } d.imageStreamImageName = manifestDigest - // FIXME: We can't do what respositorymiddleware.go does because we don't know the internal address. Does any of this matter? - dockerImageReference := fmt.Sprintf("%s/%s/%s@%s", d.client.ref.dockerReference.Hostname(), d.client.ref.namespace, d.client.ref.stream, manifestDigest) - ism := imageStreamMapping{ - typeMeta: typeMeta{ - Kind: "ImageStreamMapping", - APIVersion: "v1", - }, - objectMeta: objectMeta{ - Namespace: d.client.ref.namespace, - Name: d.client.ref.stream, - }, - Image: image{ - objectMeta: objectMeta{ - Name: manifestDigest, - }, - DockerImageReference: dockerImageReference, - DockerImageManifest: string(m), - }, - Tag: d.client.ref.dockerReference.Tag(), - } - body, err := json.Marshal(ism) - if err != nil { - return err - } - - // FIXME: validate components per validation.IsValidPathSegmentName? - path := fmt.Sprintf("/oapi/v1/namespaces/%s/imagestreammappings", d.client.ref.namespace) - body, err = d.client.doRequest("POST", path, body) - if err != nil { - return err - } - return nil + return d.docker.PutManifest(m) } func (d *openshiftImageDestination) PutSignatures(signatures [][]byte) error { @@ -508,12 +474,6 @@ type imageSignature struct { // IssuedBy SignatureIssuer `json:"issuedBy,omitempty"` // IssuedTo SignatureSubject `json:"issuedTo,omitempty"` } -type imageStreamMapping struct { - typeMeta `json:",inline"` - objectMeta `json:"metadata,omitempty"` - Image image `json:"image"` - Tag string `json:"tag"` -} type typeMeta struct { Kind string `json:"kind,omitempty"` APIVersion string `json:"apiVersion,omitempty"`