Skip to content

Commit

Permalink
Adding make targets for e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barney-s committed Feb 11, 2025
1 parent 63b9240 commit da72120
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
- name: Install kind
run: go install sigs.k8s.io/kind@latest

#- name: Build and deploy to kind cluster
# run: make deploy-kind
- name: Build and deploy to kind cluster
run: make deploy-kind

#- name: Run e2e tests
# run: make test-e2e
- name: Run e2e tests
run: make test-e2e
62 changes: 53 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
AWS_REGION ?= us-west-2

RELEASE_VERSION ?= dev-$(shell git rev-parse --short HEAD)
OCI_REPO ?= ghcr.io/kro-run/kro

CONTROLLER_IMAGE ?= ${OCI_REPO}/controller:${RELEASE_VERSION}
HELM_IMAGE ?= ${OCI_REPO}
KO_DOCKER_REPO ?= ${OCI_REPO}/kro

KOCACHE ?= ~/.ko
KO_PUSH ?= true
export KIND_CLUSTER_NAME ?= kro

WITH_GOFLAGS = GOFLAGS="$(GOFLAGS)"

Expand Down Expand Up @@ -150,14 +149,26 @@ $(LOCALBIN):

## Tool Binaries
KUBECTL ?= kubectl
KIND ?= kind
KUSTOMIZE ?= $(LOCALBIN)/kustomize
KO ?= $(LOCALBIN)/ko
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KO_VERSION ?= v0.17.1
KUSTOMIZE_VERSION ?= v5.2.1
CONTROLLER_TOOLS_VERSION ?= v0.16.2

.PHONY: ko
ko: $(KO) ## Download ko locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KO): $(LOCALBIN)
@if test -x $(LOCALBIN)/ko && ! $(LOCALBIN)/kustomize version | grep -q $(KO_VERSION); then \
echo "$(LOCALBIN)/ko version is not expected $(KO_VERSION). Removing it before installing."; \
rm -rf $(LOCALBIN)/ko; \
fi
test -s $(LOCALBIN)/ko || GOBIN=$(LOCALBIN) GO111MODULE=on go install github.com/google/ko@$(KO_VERSION)

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
Expand All @@ -174,15 +185,17 @@ $(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: image
build-image: ## Build the kro controller images using ko build
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) \
ko build --bare github.com/kro-run/kro/cmd/controller \
build-image: ko ## Build the kro controller images using ko build
echo $(RELEASE_VERSION)
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) KO_DOCKER_REPO=$(KO_DOCKER_REPO) \
$(KO) build --bare github.com/kro-run/kro/cmd/controller \
--local\
--push=false --tags ${RELEASE_VERSION} --sbom=none

.PHONY: publish
publish-image: ## Publish the kro controller images to ghcr.io
publish-image: ko ## Publish the kro controller images to ghcr.io
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) \
ko publish --bare github.com/kro-run/kro/cmd/controller \
$(KO) publish --bare github.com/kro-run/kro/cmd/controller \
--tags ${RELEASE_VERSION} --sbom=none

.PHONY: package-helm
Expand All @@ -200,7 +213,38 @@ publish-helm: ## Helm publish
.PHONY:
release: build-image publish-image package-helm publish-helm

##@ Deployment

ifndef ignore-not-found
ignore-not-found = true
endif

.PHONY: install
install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUBECTL) apply -f ./helm/crds

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config
$(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f ./helm/crds

.PHONY: deploy-kind
deploy-kind: export KO_DOCKER_REPO=kind.local
deploy-kind:
$(KIND) delete clusters ${KIND_CLUSTER_NAME} || true
$(KIND) create cluster --name ${KIND_CLUSTER_NAME}
$(KUBECTL) --context kind-$(KIND_CLUSTER_NAME) create namespace kro-system
make install
# This generates deployment with ko://... used in image.
# ko then intercepts it builds image, pushes to kind node, replaces the image in deployment and applies it
helm template kro ./helm --namespace kro-system --set image.pullPolicy=Never --set image.ko=true | $(KO) apply -f -
sleep 5
$(KUBECTL) --context kind-${KIND_CLUSTER_NAME} get pods -A

# Run e2e tests
.PHONY: test-e2e
test-e2e: ## Run e2e tests
go test -v ./test/e2e/...
go test -v ./test/e2e/...

.PHONY: test-e2e-kind
test-e2e-kind: deploy-kind
go test -v ./test/e2e/...

0 comments on commit da72120

Please sign in to comment.