Skip to content

Commit

Permalink
removed code duplication
Browse files Browse the repository at this point in the history
Signed-off-by: pawarpranav83 <[email protected]>
  • Loading branch information
pawarpranav83 committed Feb 8, 2024
1 parent bb01b4e commit 0f00402
Show file tree
Hide file tree
Showing 14 changed files with 1,041 additions and 204 deletions.
4 changes: 2 additions & 2 deletions Dockerfiles/ig-tests.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COPY go.mod go.sum /cache/
RUN cd /cache && \
go mod download
ADD . /go/src/github.com/inspektor-gadget/inspektor-gadget
WORKDIR /go/src/github.com/inspektor-gadget/inspektor-gadget/integration/ig/k8s
WORKDIR /go/src/github.com/inspektor-gadget/inspektor-gadget/integration/all
RUN CGO_ENABLED=0 GOARCH=${TARGETARCH} go test -c -o ig-integration-${TARGETARCH}.test ./...

FROM ${BASE_IMAGE}
Expand All @@ -23,5 +23,5 @@ LABEL org.opencontainers.image.licenses=Apache-2.0

ARG TARGETARCH

COPY --from=builder /go/src/github.com/inspektor-gadget/inspektor-gadget/integration/ig/k8s/ig-integration-${TARGETARCH}.test /usr/bin/ig-integration.test
COPY --from=builder /go/src/github.com/inspektor-gadget/inspektor-gadget/integration/all/ig-integration-${TARGETARCH}.test /usr/bin/ig-integration.test
ENTRYPOINT ["/usr/bin/ig-integration.test"]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ ig-tests:
.PHONY: integration-tests
integration-tests: kubectl-gadget
KUBECTL_GADGET="$(shell pwd)/kubectl-gadget" \
go test ./integration/inspektor-gadget/... \
go test ./integration/all/... \
-v \
-integration \
-timeout 30m \
Expand All @@ -266,6 +266,7 @@ integration-tests: kubectl-gadget
-dnstester-image $(DNSTESTER_IMAGE) \
-gadget-repository $(GADGET_REPOSITORY) \
-gadget-tag $(GADGET_TAG) \
-test-component=inspektor-gadget \
$$INTEGRATION_TESTS_PARAMS


Expand Down
52 changes: 52 additions & 0 deletions integration/all/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
include $(shell pwd)/../../minikube.mk

DNSTESTER_IMAGE ?= "ghcr.io/inspektor-gadget/dnstester:latest"

# make does not allow implicit rules (with '%') to be phony so let's use
# the 'phony_explicit' dependency to make implicit rules inherit the phony
# attribute
.PHONY: phony_explicit
phony_explicit:


build:
make -C $(shell pwd)/../.. ig

.PHONY: build-tests
build-tests:
docker buildx build --load -t ig-tests -f ./../../Dockerfiles/ig-tests.Dockerfile ../../
docker create --name ig-tests-container ig-tests
docker cp ig-tests-container:/usr/bin/ig-integration.test ig-integration.test
docker rm ig-tests-container
chmod +x ig-integration.test

# test

TEST_TARGETS = \
test-docker \
test-containerd \
test-cri-o

.PHONY: test-all
test-all: $(TEST_TARGETS) test

test: test-$(CONTAINER_RUNTIME)


# INTEGRATION_TESTS_PARAMS can be used to pass additional parameters locally e.g
# INTEGRATION_TESTS_PARAMS="-test.run TestListContainers" CONTAINER_RUNTIME=containerd make -C integration/ig/k8s test
.PHONY: phony_explicit
test-%: build build-tests
export MINIKUBE_PROFILE=minikube-$* && \
echo "Checking minikube with profile $${MINIKUBE_PROFILE} is running ..." && \
$(MINIKUBE) status -p $${MINIKUBE_PROFILE} -f {{.APIServer}} >/dev/null || (echo "Error: $${MINIKUBE_PROFILE} not running, exiting ..." && exit 1) && \
echo "Preparing minikube with profile $${MINIKUBE_PROFILE} for testing ..." && \
$(MINIKUBE) cp ../../ig-linux-amd64 $${MINIKUBE_PROFILE}:/bin/ig >/dev/null && \
$(MINIKUBE) ssh sudo chmod +x /bin/ig && \
$(MINIKUBE) cp ig-integration.test $${MINIKUBE_PROFILE}:/bin/ig-integration.test >/dev/null && \
$(MINIKUBE) ssh sudo chmod +x /bin/ig-integration.test && \
rm ig-integration.test && \
$(MINIKUBE) -p $${MINIKUBE_PROFILE} ssh "sudo ln -sf /var/lib/minikube/binaries/$(KUBERNETES_VERSION)/kubectl /bin/kubectl" && \
$(MINIKUBE) -p $${MINIKUBE_PROFILE} ssh "sudo ln -sf /etc/kubernetes/admin.conf /root/.kube/config" && \
echo "Running test in minikube with profile $${MINIKUBE_PROFILE} ..." && \
$(MINIKUBE) -p $${MINIKUBE_PROFILE} ssh "sudo ig-integration.test -test.v -test.timeout 30m -integration -dnstester-image $(DNSTESTER_IMAGE) -test-component=ig $${INTEGRATION_TESTS_PARAMS}"
Loading

0 comments on commit 0f00402

Please sign in to comment.