Skip to content

Commit da41246

Browse files
committed
OCPNODE-3138: Add zstd:chunked image test
Signed-off-by: Ayato Tokubi <[email protected]>
1 parent ea71886 commit da41246

File tree

8 files changed

+286
-0
lines changed

8 files changed

+286
-0
lines changed

test/extended/include.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
_ "github.com/openshift/origin/test/extended/machine_config"
4141
_ "github.com/openshift/origin/test/extended/machines"
4242
_ "github.com/openshift/origin/test/extended/networking"
43+
_ "github.com/openshift/origin/test/extended/node"
4344
_ "github.com/openshift/origin/test/extended/node_tuning"
4445
_ "github.com/openshift/origin/test/extended/oauth"
4546
_ "github.com/openshift/origin/test/extended/olm"

test/extended/node/zstd_chunked.go

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package node
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
g "github.com/onsi/ginkgo/v2"
9+
o "github.com/onsi/gomega"
10+
11+
corev1 "k8s.io/api/core/v1"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
14+
15+
exutil "github.com/openshift/origin/test/extended/util"
16+
)
17+
18+
var _ = g.Describe("[sig-node][Feature:Builds] zstd:chunked Image", func() {
19+
defer g.GinkgoRecover()
20+
var (
21+
oc = exutil.NewCLI("zstd-chunked-image")
22+
customBuildAdd = exutil.FixturePath("testdata", "node", "zstd-chunked")
23+
customBuildFixture = exutil.FixturePath("testdata", "node", "zstd-chunked", "test-custom-build.yaml")
24+
)
25+
26+
g.It("should successfully run date command", func(ctx context.Context) {
27+
namespace := oc.Namespace()
28+
29+
g.By("creating custom builder image")
30+
// Build with buildah with --compression-format zstd:chunked to ensure the image is compressed with zstd:chunked.
31+
// https://docs.redhat.com/en/documentation/openshift_container_platform/4.18/html/builds_using_buildconfig/custom-builds-buildah#builds-build-custom-builder-image_custom-builds-buildah
32+
err := oc.Run("new-build").Args("--binary", "--strategy=docker", "--name=custom-builder-image").Execute()
33+
o.Expect(err).NotTo(o.HaveOccurred())
34+
br, _ := exutil.StartBuildAndWait(oc, "custom-builder-image", fmt.Sprintf("--from-dir=%s", customBuildAdd))
35+
br.AssertSuccess()
36+
g.By("start custom build and build should complete")
37+
err = oc.AsAdmin().Run("create").Args("-f", customBuildFixture).Execute()
38+
o.Expect(err).NotTo(o.HaveOccurred())
39+
err = oc.AsAdmin().Run("start-build").Args("sample-custom-build").Execute()
40+
o.Expect(err).NotTo(o.HaveOccurred())
41+
err = exutil.WaitForABuild(oc.BuildClient().BuildV1().Builds(oc.Namespace()), "sample-custom-build-1", nil, nil, nil)
42+
o.Expect(err).NotTo(o.HaveOccurred())
43+
44+
// Define a pod that runs the date command using the zstd-chunked image
45+
pod := &corev1.Pod{
46+
ObjectMeta: metav1.ObjectMeta{
47+
Name: "zstd-chunked-pod",
48+
Namespace: namespace,
49+
},
50+
Spec: corev1.PodSpec{
51+
RestartPolicy: corev1.RestartPolicyNever,
52+
Containers: []corev1.Container{
53+
{
54+
Name: "zstd-chunked-container",
55+
Image: fmt.Sprintf("image-registry.openshift-image-registry.svc:5000/%s/sample-custom:latest", namespace),
56+
Command: []string{"date"},
57+
},
58+
},
59+
},
60+
}
61+
62+
g.By("Creating a pod")
63+
pod, err = oc.KubeClient().CoreV1().Pods(namespace).Create(context.Background(), pod, metav1.CreateOptions{})
64+
o.Expect(err).NotTo(o.HaveOccurred())
65+
66+
g.By("Waiting for pod to complete")
67+
err = e2epod.WaitForPodSuccessInNamespaceTimeout(ctx, oc.KubeClient(), pod.Name, namespace, 1*time.Minute)
68+
o.Expect(err).NotTo(o.HaveOccurred())
69+
70+
g.By("Verifying pod completed successfully")
71+
pod, err = oc.KubeClient().CoreV1().Pods(namespace).Get(context.Background(), pod.Name, metav1.GetOptions{})
72+
o.Expect(err).NotTo(o.HaveOccurred())
73+
o.Expect(pod.Status.Phase).To(o.Equal(corev1.PodSucceeded))
74+
})
75+
})

test/extended/testdata/bindata.go

+145
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM registry.redhat.io/rhel8/buildah:latest
2+
# For simplicity, /tmp/build contains the inputs we’ll be building when we
3+
# run this custom builder image. Normally the custom builder image would
4+
# fetch this content from some location at build time. (e.g. via git clone).
5+
ADD Dockerfile.sample /tmp/input/Dockerfile
6+
ADD build.sh /usr/bin
7+
RUN chmod a+x /usr/bin/build.sh
8+
# /tmp/build/build.sh contains the actual custom build logic that will be executed when
9+
# this custom builder image is executed.
10+
ENTRYPOINT ["/usr/bin/build.sh"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM image-registry.openshift-image-registry.svc:5000/openshift/tools:latest
2+
CMD ["date"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
set -euo pipefail
4+
5+
# Note that in this case the build inputs are part of the custom builder image, but normally this
6+
# would be retrieved from an external source.
7+
cd /tmp/input
8+
# OUTPUT_REGISTRY and OUTPUT_IMAGE are env variables provided by the custom
9+
# build framework
10+
TAG="${OUTPUT_REGISTRY}/${OUTPUT_IMAGE}"
11+
12+
cp -R /var/run/configs/openshift.io/certs/certs.d/* /etc/containers/certs.d/
13+
14+
# buildah requires a slight modification to the push secret provided by the service account in order to use it for pushing the image
15+
echo "{ \"auths\": $(cat /var/run/secrets/openshift.io/pull/.dockercfg)}" > /tmp/.pull
16+
echo "{ \"auths\": $(cat /var/run/secrets/openshift.io/push/.dockercfg)}" > /tmp/.push
17+
18+
# performs the build of the new image defined by Dockerfile.sample
19+
buildah --authfile /tmp/.pull --storage-driver vfs bud --isolation chroot -t ${TAG} .
20+
# push the new image to the target for the build
21+
buildah --authfile /tmp/.push --storage-driver vfs push --compression-format zstd:chunked ${TAG}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
kind: List
2+
apiVersion: v1
3+
items:
4+
- kind: ImageStream
5+
apiVersion: image.openshift.io/v1
6+
metadata:
7+
name: sample-custom
8+
- kind: BuildConfig
9+
apiVersion: build.openshift.io/v1
10+
metadata:
11+
name: sample-custom-build
12+
labels:
13+
name: sample-custom-build
14+
annotations:
15+
template.alpha.openshift.io/wait-for-ready: 'true'
16+
spec:
17+
strategy:
18+
type: Custom
19+
customStrategy:
20+
env:
21+
- name: "BUILD_LOGLEVEL"
22+
value: "2"
23+
forcePull: true
24+
from:
25+
kind: ImageStreamTag
26+
name: custom-builder-image:latest
27+
output:
28+
to:
29+
kind: ImageStreamTag
30+
name: sample-custom:latest

test/extended/util/annotate/generated/zz_generated.annotations.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)