Skip to content

Commit

Permalink
cleanup and e2e test changes
Browse files Browse the repository at this point in the history
Signed-off-by: ashnamehrotra <ashnamehrotra@gmail.com>
  • Loading branch information
ashnamehrotra committed Jan 10, 2024
1 parent 4a0f3f2 commit eae481d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ REMOVER_IMG ?= ${REMOVER_REPO}:${REMOVER_TAG}
COLLECTOR_REPO ?= ghcr.io/eraser-dev/collector
COLLECTOR_IMG ?= ${COLLECTOR_REPO}:${COLLECTOR_TAG}
VULNERABLE_IMG ?= docker.io/library/alpine:3.7.3
EOL_IMG ?= docker.io/library/alpine:3.1
EOL_IMG ?= docker.io/library/alpine:3.7.3
BUSYBOX_BASE_IMG ?= busybox:1.36.0
NON_VULNERABLE_IMG ?= ghcr.io/eraser-dev/non-vulnerable:latest
E2E_TESTS ?= $(shell find ./test/e2e/tests/ -mindepth 1 -type d)
Expand Down Expand Up @@ -177,7 +177,13 @@ non-vulnerable-img:
-t ${NON_VULNERABLE_IMG} \
--target non-vulnerable .

e2e-test: vulnerable-img eol-img non-vulnerable-img busybox-img collector-dummy-img
custom-node:
docker build -t custom-node:latest \
-f test/e2e/test-data/Dockerfile.customNode \
--build-arg NODE_VERSION=${KUBERNETES_VERSION} test/e2e/test-data
MODIFIED_NODE_IMAGE=custom-node:latest

e2e-test: vulnerable-img eol-img non-vulnerable-img busybox-img collector-dummy-img custom-node
for test in $(E2E_TESTS); do \
CGO_ENABLED=0 \
PROJECT_ABSOLUTE_PATH=$(CURDIR) \
Expand All @@ -196,6 +202,7 @@ e2e-test: vulnerable-img eol-img non-vulnerable-img busybox-img collector-dummy-
NON_VULNERABLE_IMAGE=${NON_VULNERABLE_IMG} \
EOL_IMAGE=${EOL_IMG} \
NODE_VERSION=kindest/node:v${KUBERNETES_VERSION} \
MODIFIED_NODE_IMAGE=${MODIFIED_NODE_IMAGE} \
TEST_LOGDIR=${TEST_LOGDIR} \
go test -count=$(TEST_COUNT) -timeout=$(TIMEOUT) $(TESTFLAGS) -tags=e2e -v $$test ; \
done
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/test-data/Dockerfile.customNode
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG NODE_VERSION
FROM kindest/node:v${NODE_VERSION}

ENV CONTAINERD_ADDRESS="/fake/socket/address.sock"
6 changes: 1 addition & 5 deletions test/e2e/tests/collector_runtime_config/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ func TestMain(m *testing.M) {

util.Testenv = env.NewWithConfig(envconf.New())

if err := os.Setenv("CONTAINERD_ADDRESS", "/fake/runtime/address.sock"); err != nil {
os.Exit(1)
}

// Create KinD Cluster
util.Testenv.Setup(
envfuncs.CreateKindClusterWithConfig(util.KindClusterName, util.NodeVersion, util.KindConfigPath),
envfuncs.CreateKindClusterWithConfig(util.KindClusterName, util.ModifiedNodeImage, util.KindConfigCustomRuntimePath),
envfuncs.CreateNamespace(util.TestNamespace),
util.LoadImageToCluster(util.KindClusterName, util.ManagerImage, util.ManagerTarballPath),
util.LoadImageToCluster(util.KindClusterName, util.RemoverImage, util.RemoverTarballPath),
Expand Down
27 changes: 7 additions & 20 deletions test/e2e/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ const (
FilterNodesType = HelmPath("runtimeConfig.manager.nodeFilter.type")
ScheduleImmediate = HelmPath("runtimeConfig.manager.scheduling.beginImmediately")

CustomRuntimeAddress = HelmPath("runtimeConfig.manager.runtime.name")
CustomRuntimeName = HelmPath("runtimeConfig.manager.runtime.address")
CustomRuntimeAddress = HelmPath("runtimeConfig.manager.runtime.address")
CustomRuntimeName = HelmPath("runtimeConfig.manager.runtime.name")

CollectorLabel = "collector"
ManualLabel = "manual"
Expand Down Expand Up @@ -120,10 +120,11 @@ var (
EraserV1ImagelistPath = filepath.Join(TestDataPath, "eraser_v1_imagelist.yaml")
ImagelistAlpinePath = filepath.Join(TestDataPath, "imagelist_alpine.yaml")

NodeVersion = os.Getenv("NODE_VERSION")
TestNamespace = envconf.RandomName("test-ns", 16)
EraserNamespace = pkgUtil.GetNamespace()
TestLogDir = os.Getenv("TEST_LOGDIR")
NodeVersion = os.Getenv("NODE_VERSION")
ModifiedNodeImage = os.Getenv("MODIFIED_NODE_IMAGE")
TestNamespace = envconf.RandomName("test-ns", 16)
EraserNamespace = pkgUtil.GetNamespace()
TestLogDir = os.Getenv("TEST_LOGDIR")

ParsedImages *Images
Timeout = time.Minute * 5
Expand Down Expand Up @@ -597,20 +598,6 @@ func DockerTagImage(image, tag string) (string, error) {
return output, err
}

func KindLoadImage(clusterName string, images ...string) (string, error) {
args := []string{"load", "docker-image", "--name", clusterName}
args = append(args, images...)
cmd := exec.Command("kind", args...)

stdoutStderr, err := cmd.CombinedOutput()
output := strings.TrimSpace(string(stdoutStderr))
if err != nil {
err = fmt.Errorf("%w: %s", err, output)
}

return output, err
}

func DeleteImageListsAndJobs(kubeConfig string) error {
if err := KubectlDelete(kubeConfig, "", []string{"imagejob", "--all"}); err != nil {
return err
Expand Down

0 comments on commit eae481d

Please sign in to comment.