-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b904906
commit e9536dd
Showing
2 changed files
with
221 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package images | ||
|
||
import ( | ||
"time" | ||
|
||
g "github.com/onsi/ginkgo" | ||
o "github.com/onsi/gomega" | ||
|
||
kapi "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
|
||
buildapi "github.com/openshift/api/build/v1" | ||
imageapi "github.com/openshift/api/image/v1" | ||
buildclientset "github.com/openshift/client-go/build/clientset/versioned" | ||
imageclientset "github.com/openshift/client-go/image/clientset/versioned" | ||
exutil "github.com/openshift/origin/test/extended/util" | ||
) | ||
|
||
var _ = g.Describe("[Feature:ImageLayers] Image layer subresource", func() { | ||
defer g.GinkgoRecover() | ||
var oc = exutil.NewCLI("image-layers", exutil.KubeConfigPath()) | ||
|
||
g.AfterEach(func() { | ||
if g.CurrentGinkgoTestDescription().Failed { | ||
exutil.DumpPodLogsStartingWith("", oc) | ||
} | ||
}) | ||
|
||
g.It("should return layers from tagged images", func() { | ||
client := imageclientset.NewForConfigOrDie(oc.UserConfig()).Image() | ||
isi, err := client.ImageStreamImports(oc.Namespace()).Create(&imageapi.ImageStreamImport{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "1", | ||
}, | ||
Spec: imageapi.ImageStreamImportSpec{ | ||
Import: true, | ||
Images: []imageapi.ImageImportSpec{ | ||
{ | ||
From: kapi.ObjectReference{Kind: "DockerImage", Name: "busybox:latest"}, | ||
To: &kapi.LocalObjectReference{Name: "busybox"}, | ||
}, | ||
{ | ||
From: kapi.ObjectReference{Kind: "DockerImage", Name: "mysql:latest"}, | ||
To: &kapi.LocalObjectReference{Name: "mysql"}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(isi.Status.Images).To(o.HaveLen(2)) | ||
|
||
// TODO: we may race here with the cache, if this is a problem, loop | ||
g.By("verifying that layers for imported images are correct") | ||
layers, err := client.ImageStreams(oc.Namespace()).Layers("1") | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
var busyboxLayers []string | ||
var busyboxDigest string | ||
for _, image := range isi.Status.Images { | ||
l, ok := layers.Layers[image.Image.Name] | ||
o.Expect(ok).To(o.BeTrue()) | ||
o.Expect(len(l)).To(o.BeNumerically(">", 0)) | ||
for _, layerID := range l { | ||
o.Expect(layers.Blobs).To(o.HaveKey(layerID)) | ||
o.Expect(layers.Blobs[layerID].MediaType).NotTo(o.BeEmpty()) | ||
} | ||
if image.Tag == "busybox" { | ||
busyboxLayers = l | ||
busyboxDigest = image.Image.Name | ||
} | ||
o.Expect(layers.Manifests).To(o.HaveKey(image.Image.Name)) | ||
} | ||
|
||
_, err = client.ImageStreams(oc.Namespace()).Create(&imageapi.ImageStream{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "output", | ||
}, | ||
}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
layers, err = client.ImageStreams(oc.Namespace()).Layers("output") | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(layers.Layers).To(o.BeEmpty()) | ||
o.Expect(layers.Blobs).To(o.BeEmpty()) | ||
o.Expect(layers.Manifests).To(o.BeEmpty()) | ||
|
||
_, err = client.ImageStreams(oc.Namespace()).Layers("doesnotexist") | ||
o.Expect(err).To(o.HaveOccurred()) | ||
o.Expect(errors.IsNotFound(err)).To(o.BeTrue()) | ||
|
||
dockerfile := ` | ||
FROM a | ||
RUN echo "a" > /var/lib/file | ||
` | ||
|
||
g.By("running a build based on our tagged layer") | ||
buildClient := buildclientset.NewForConfigOrDie(oc.UserConfig()).Build() | ||
_, err = buildClient.Builds(oc.Namespace()).Create(&buildapi.Build{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "output", | ||
}, | ||
Spec: buildapi.BuildSpec{ | ||
CommonSpec: buildapi.CommonSpec{ | ||
Source: buildapi.BuildSource{ | ||
Dockerfile: &dockerfile, | ||
}, | ||
Strategy: buildapi.BuildStrategy{ | ||
DockerStrategy: &buildapi.DockerBuildStrategy{ | ||
From: &kapi.ObjectReference{Kind: "ImageStreamTag", Name: "busybox:latest"}, | ||
}, | ||
}, | ||
Output: buildapi.BuildOutput{ | ||
To: &kapi.ObjectReference{Kind: "ImageStreamTag", Name: "output:latest"}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
newNamespace := oc.CreateProject() | ||
|
||
g.By("waiting for the build to finish") | ||
var lastBuild *buildapi.Build | ||
err = wait.Poll(time.Second, time.Minute, func() (bool, error) { | ||
build, err := buildClient.Builds(oc.Namespace()).Get("output", metav1.GetOptions{}) | ||
if err != nil { | ||
return false, err | ||
} | ||
o.Expect(build.Status.Phase).NotTo(o.Or(o.Equal(buildapi.BuildPhaseFailed), o.Equal(buildapi.BuildPhaseError), o.Equal(buildapi.BuildPhaseCancelled))) | ||
lastBuild = build | ||
return build.Status.Phase == buildapi.BuildPhaseComplete, nil | ||
}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
g.By("checking the layers for the built image") | ||
layers, err = client.ImageStreams(oc.Namespace()).Layers("output") | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
to := lastBuild.Status.Output.To | ||
o.Expect(to).NotTo(o.BeNil()) | ||
o.Expect(layers.Layers).To(o.HaveKey(to.ImageDigest)) | ||
builtImageLayers := layers.Layers[to.ImageDigest] | ||
o.Expect(len(builtImageLayers)).To(o.Equal(len(busyboxLayers) + 1)) | ||
for i := range busyboxLayers { | ||
o.Expect(busyboxLayers[i]).To(o.Equal(builtImageLayers[i])) | ||
} | ||
o.Expect(layers.Layers).To(o.HaveKey(busyboxDigest)) | ||
o.Expect(layers.Layers[busyboxDigest]).To(o.Equal(busyboxLayers)) | ||
|
||
g.By("tagging the built image into another namespace") | ||
_, err = client.ImageStreamTags(newNamespace).Create(&imageapi.ImageStreamTag{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "output", | ||
}, | ||
Tag: &imageapi.TagReference{ | ||
Name: "copied", | ||
From: &kapi.ObjectReference{Kind: "ImageStreamTag", Namespace: oc.Namespace(), Name: "output:latest"}, | ||
}, | ||
}) | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
||
g.By("checking that the image shows up in the other namespace") | ||
layers, err = client.ImageStreams(newNamespace).Layers("output") | ||
o.Expect(err).NotTo(o.HaveOccurred()) | ||
o.Expect(layers.Layers).To(o.HaveKey(to.ImageDigest)) | ||
o.Expect(layers.Layers[to.ImageDigest]).To(o.Equal(builtImageLayers)) | ||
}) | ||
}) |
Oops, something went wrong.