Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
make e2e tests happy
Browse files Browse the repository at this point in the history
Signed-off-by: everettraven <everettraven@gmail.com>
  • Loading branch information
everettraven committed May 6, 2024
1 parent 41bc12f commit 8036d86
Show file tree
Hide file tree
Showing 20 changed files with 933 additions and 115 deletions.
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ test-e2e: $(GINKGO) ## Run the e2e tests
$(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) --trace $(FOCUS) test/e2e

e2e: KIND_CLUSTER_NAME=rukpak-e2e
e2e: run image-registry local-git kind-load-bundles registry-load-bundles test-e2e kind-cluster-cleanup ## Run e2e tests against an ephemeral kind cluster
e2e: run image-registry secure-image-registry local-git kind-load-bundles registry-load-bundles secure-registry-load-bundles test-e2e kind-cluster-cleanup ## Run e2e tests against an ephemeral kind cluster

kind-cluster: $(KIND) kind-cluster-cleanup ## Standup a kind cluster
$(KIND) create cluster --name ${KIND_CLUSTER_NAME} ${KIND_CLUSTER_CONFIG}
Expand All @@ -120,6 +120,11 @@ kind-cluster-cleanup: $(KIND) ## Delete the kind cluster
$(KIND) delete cluster --name ${KIND_CLUSTER_NAME}

image-registry: ## Setup in-cluster image registry
./test/tools/imageregistry/image-registry.sh ${REGISTRY_NAMESPACE} ${REGISTRY_NAME}

secure-image-registry: REGISTRY_NAME="docker-registry-secure"
secure-image-registry: DNS_NAME=$(REGISTRY_NAME).$(REGISTRY_NAMESPACE).svc.cluster.local
secure-image-registry: ## Setup a private in-cluster image registry
./test/tools/imageregistry/setup_imageregistry.sh ${KIND_CLUSTER_NAME}

local-git: ## Setup in-cluster git repository
Expand Down Expand Up @@ -211,6 +216,20 @@ kind-load: $(KIND) ## Loads the currently constructed image onto the cluster
$(KIND) load docker-image $(IMAGE) --name $(KIND_CLUSTER_NAME)

registry-load-bundles: ## Load selected e2e testdata container images created in kind-load-bundles into registry
testdata/bundles/plain-v0/valid/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/plain-v0:valid
testdata/bundles/plain-v0/dependent/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/plain-v0:dependent
testdata/bundles/plain-v0/provides/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/plain-v0:provides
testdata/bundles/plain-v0/empty/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/plain-v0:empty
testdata/bundles/plain-v0/no-manifests/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/plain-v0:no-manifests
testdata/bundles/plain-v0/invalid-missing-crds/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/plain-v0:invalid-missing-crds
testdata/bundles/plain-v0/invalid-crds-and-crs/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/plain-v0:invalid-crds-and-crs
testdata/bundles/plain-v0/subdir/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/plain-v0:subdir
testdata/bundles/registry/valid/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/registry:valid
testdata/bundles/registry/invalid/build-push-e2e-bundle.sh ${REGISTRY_NAMESPACE} $(DNS_NAME):5000/bundles/registry:invalid

secure-registry-load-bundles: REGISTRY_NAME="docker-registry-secure"
secure-regsitry-load-bundles: DNS_NAME=$(REGISTRY_NAME).$(REGISTRY_NAMESPACE).svc.cluster.local
secure-registry-load-bundles: ## Load selected e2e testdata container images created in kind-load-bundles into private registry
$(CONTAINER_RUNTIME) tag localhost/testdata/bundles/plain-v0:valid $(DNS_NAME):5000/bundles/plain-v0:valid
./test/tools/imageregistry/load_test_image.sh $(KIND) $(KIND_CLUSTER_NAME)

Expand Down
7 changes: 2 additions & 5 deletions internal/source/image_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,19 @@ func unpackImage(ctx context.Context, imgRef name.Reference, unpackPath string,
return fmt.Errorf("error getting image layers: %w", err)
}

dirBase := "manifests"
for _, layer := range layers {
layerRc, err := layer.Uncompressed()
if err != nil {
return fmt.Errorf("error getting uncompressed layer data: %w", err)
}

// Apply the layer contents, but filter on the directory that contains catalog contents so we only cache the
// catalog contents and nothing else. This filter ensures that the files created have the proper UID and GID
// This filter ensures that the files created have the proper UID and GID
// for the filesystem they will be stored on to ensure no permission errors occur when attempting to create the
// files.
_, err = archive.Apply(ctx, unpackPath, layerRc, archive.WithFilter(func(th *tar.Header) (bool, error) {
th.Uid = os.Getuid()
th.Gid = os.Getgid()
dir, file := filepath.Split(th.Name)
return (dir == "" && file == dirBase) || strings.HasPrefix(dir, fmt.Sprintf("%s/", dirBase)), nil
return true, nil
}))
if err != nil {
return fmt.Errorf("error applying layer to archive: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/image_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package e2e

// ImageRepo is meant to be set via -ldflags during execution of this code
// where it will then be used to configure the testing suite.
var ImageRepo = "localhost/testdata/bundles"
var ImageRepo = "docker-registry.rukpak-e2e.svc.cluster.local:5000/bundles"
131 changes: 32 additions & 99 deletions test/e2e/plain_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:valid"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:valid"),
InsecureSkipTLSVerify: true,
},
},
},
Expand Down Expand Up @@ -107,7 +108,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:valid"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:valid"),
InsecureSkipTLSVerify: true,
},
},
},
Expand All @@ -122,7 +124,6 @@ var _ = Describe("plain provisioner bundle", func() {
})

It("should eventually report a successful state", func() {

By("eventually writing a non-empty image digest to the status", func() {
Eventually(func() (*rukpakv1alpha2.BundleSource, error) {
if err := c.Get(ctx, client.ObjectKeyFromObject(bundleDeployment), bundleDeployment); err != nil {
Expand All @@ -139,42 +140,6 @@ var _ = Describe("plain provisioner bundle", func() {
))
})
})

It("should re-create underlying system resources", func() {
var (
pod *corev1.Pod
)

By("getting the underlying bundle unpacking pod")
selector := util.NewBundleDeploymentLabelSelector(bundleDeployment)
Eventually(func() bool {
pods := &corev1.PodList{}
if err := c.List(ctx, pods, &client.ListOptions{
Namespace: defaultSystemNamespace,
LabelSelector: selector,
}); err != nil {
return false
}
if len(pods.Items) != 1 {
return false
}
pod = &pods.Items[0]
return true
}).Should(BeTrue())

By("storing the pod's original UID")
originalUID := pod.GetUID()

By("deleting the underlying pod and waiting for it to be re-created")
err := c.Delete(context.Background(), pod)
Expect(err).ToNot(HaveOccurred())

By("verifying the pod's UID has changed")
Eventually(func() (types.UID, error) {
err := c.Get(ctx, client.ObjectKeyFromObject(pod), pod)
return pod.GetUID(), err
}).ShouldNot(Equal(originalUID))
})
})

When("a valid Bundle Deployment referencing a remote private container image is created", func() {
Expand All @@ -196,8 +161,9 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: "docker-registry.rukpak-e2e.svc.cluster.local:5000/bundles/plain-v0:valid",
ImagePullSecretName: "registrysecret",
Ref: "docker-registry-secure.rukpak-e2e.svc.cluster.local:5000/bundles/plain-v0:valid",
ImagePullSecretName: "registrysecret",
InsecureSkipTLSVerify: true,
},
},
},
Expand Down Expand Up @@ -264,7 +230,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:non-existent-tag"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:non-existent-tag"),
InsecureSkipTLSVerify: true,
},
},
},
Expand All @@ -279,40 +246,14 @@ var _ = Describe("plain provisioner bundle", func() {
})

It("checks the bundle's phase is stuck in pending", func() {
By("waiting until the pod is reporting ImagePullBackOff state")
Eventually(func() bool {
pod := &corev1.Pod{}
if err := c.Get(ctx, types.NamespacedName{
Name: bundleDeployment.GetName(),
Namespace: defaultSystemNamespace,
}, pod); err != nil {
return false
}
if pod.Status.Phase != corev1.PodPending {
return false
}
for _, status := range pod.Status.ContainerStatuses {
if status.State.Waiting != nil && status.State.Waiting.Reason == "ImagePullBackOff" {
return true
}
}
return false
}).Should(BeTrue())

By("waiting for the bundle to report back that state")
Eventually(func() bool {
err := c.Get(ctx, client.ObjectKeyFromObject(bundleDeployment), bundleDeployment)
if err != nil {
return false
}
unpackPending := meta.FindStatusCondition(bundleDeployment.Status.Conditions, rukpakv1alpha2.PhaseUnpacked)
if unpackPending == nil {
return false
}
if unpackPending.Message != fmt.Sprintf(`Back-off pulling image "%s"`, bundleDeployment.Spec.Source.Image.Ref) {
return false
}
return true
return unpackPending != nil
}).Should(BeTrue())
})
})
Expand All @@ -336,7 +277,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:empty"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:empty"),
InsecureSkipTLSVerify: true,
},
},
},
Expand Down Expand Up @@ -386,7 +328,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:no-manifests"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:no-manifests"),
InsecureSkipTLSVerify: true,
},
},
},
Expand Down Expand Up @@ -418,18 +361,14 @@ var _ = Describe("plain provisioner bundle", func() {
})

When("Bundles are backed by a git repository", func() {
var (
ctx context.Context
)
var ctx context.Context

BeforeEach(func() {
ctx = context.Background()
})

When("the bundle is backed by a git commit", func() {
var (
bundleDeployment *rukpakv1alpha2.BundleDeployment
)
var bundleDeployment *rukpakv1alpha2.BundleDeployment
BeforeEach(func() {
bundleDeployment = &rukpakv1alpha2.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -477,9 +416,7 @@ var _ = Describe("plain provisioner bundle", func() {
})
})
When("the bundle deployment is backed by a git tag", func() {
var (
bundleDeployment *rukpakv1alpha2.BundleDeployment
)
var bundleDeployment *rukpakv1alpha2.BundleDeployment
BeforeEach(func() {
bundleDeployment = &rukpakv1alpha2.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -546,9 +483,7 @@ var _ = Describe("plain provisioner bundle", func() {
})

When("the bundle deployment is backed by a git branch", func() {
var (
bundleDeployment *rukpakv1alpha2.BundleDeployment
)
var bundleDeployment *rukpakv1alpha2.BundleDeployment
BeforeEach(func() {
bundleDeployment = &rukpakv1alpha2.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -615,9 +550,7 @@ var _ = Describe("plain provisioner bundle", func() {
})

When("the bundle deployment has a custom manifests directory", func() {
var (
bundleDeployment *rukpakv1alpha2.BundleDeployment
)
var bundleDeployment *rukpakv1alpha2.BundleDeployment
BeforeEach(func() {
bundleDeployment = &rukpakv1alpha2.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -1025,7 +958,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:subdir"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:subdir"),
InsecureSkipTLSVerify: true,
},
},
},
Expand Down Expand Up @@ -1219,7 +1153,7 @@ var _ = Describe("plain provisioner bundle", func() {
})
})

var _ = Describe("plain provisioner bundleDeployment", func() {
_ = Describe("plain provisioner bundleDeployment", func() {
When("a BundleDeployment is dependent on another BundleDeployment", func() {
var (
ctx context.Context
Expand All @@ -1238,7 +1172,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:dependent"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:dependent"),
InsecureSkipTLSVerify: true,
},
},
},
Expand All @@ -1249,7 +1184,6 @@ var _ = Describe("plain provisioner bundle", func() {
AfterEach(func() {
By("deleting the testing dependent BundleDeployment resource")
Expect(client.IgnoreNotFound(c.Delete(ctx, dependentBD))).To(Succeed())

})
When("the providing BundleDeployment does not exist", func() {
It("should eventually project a failed installation for the dependent BundleDeployment", func() {
Expand All @@ -1269,9 +1203,7 @@ var _ = Describe("plain provisioner bundle", func() {
})
})
When("the providing BundleDeployment is created", func() {
var (
providesBD *rukpakv1alpha2.BundleDeployment
)
var providesBD *rukpakv1alpha2.BundleDeployment
BeforeEach(func() {
ctx = context.Background()

Expand All @@ -1286,7 +1218,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:provides"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:provides"),
InsecureSkipTLSVerify: true,
},
},
},
Expand All @@ -1297,7 +1230,6 @@ var _ = Describe("plain provisioner bundle", func() {
AfterEach(func() {
By("deleting the testing providing BundleDeployment resource")
Expect(client.IgnoreNotFound(c.Delete(ctx, providesBD))).To(Succeed())

})
It("should eventually project a successful installation for the dependent BundleDeployment", func() {
Eventually(func() (*metav1.Condition, error) {
Expand Down Expand Up @@ -1335,7 +1267,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:invalid-crds-and-crs"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:invalid-crds-and-crs"),
InsecureSkipTLSVerify: true,
},
},
},
Expand Down Expand Up @@ -1366,8 +1299,7 @@ var _ = Describe("plain provisioner bundle", func() {
})
})

var _ = Describe("plain provisioner garbage collection", func() {

_ = Describe("plain provisioner garbage collection", func() {
When("a BundleDeployment has been deleted", func() {
var (
ctx context.Context
Expand All @@ -1390,7 +1322,8 @@ var _ = Describe("plain provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:valid"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "plain-v0:valid"),
InsecureSkipTLSVerify: true,
},
},
},
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/registry_provisioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var _ = Describe("registry provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "registry:valid"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "registry:valid"),
InsecureSkipTLSVerify: true,
},
},
},
Expand Down Expand Up @@ -87,7 +88,8 @@ var _ = Describe("registry provisioner bundle", func() {
Source: rukpakv1alpha2.BundleSource{
Type: rukpakv1alpha2.SourceTypeImage,
Image: &rukpakv1alpha2.ImageSource{
Ref: fmt.Sprintf("%v/%v", ImageRepo, "registry:invalid"),
Ref: fmt.Sprintf("%v/%v", ImageRepo, "registry:invalid"),
InsecureSkipTLSVerify: true,
},
},
},
Expand Down
Loading

0 comments on commit 8036d86

Please sign in to comment.