Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ jobs:
with:
go-version: '=1.21.0'
cache: false
- uses: nolar/setup-k3d-k3s@v1
with:
skip-creation: true
- uses: RocketChat/k3d-with-registry@main
- name: Build binary
run: |
cd $__W_SRC_REL
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ mongoValues.yaml
db-secret.yaml
db-cluster.yaml
*.ignore

tests/k3d/disk/
102 changes: 99 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ endif

# Image URL to use all building/pushing image targets
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)

BIMG ?= backup:latest

# Reusable kubectl command with kubeconfig
# KUBECTL_WITH_CONFIG = k3d kubeconfig print ${NAME} > /tmp/${NAME}.kube.config && KUBECONFIG=/tmp/${NAME}.kube.config kubectl
KUBECTL_WITH_CONFIG = KUBECONFIG=/tmp/${NAME}.kube.config kubectl

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -111,7 +117,7 @@ test: manifests generate fmt vet ## Run tests.
##@ Build

.PHONY: build
build: generate fmt vet ## Build manager binary.
build: generate manifests fmt vet ## Build manager binary.
CGO_ENABLED=0 GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -o bin/manager main.go

.PHONY: run
Expand All @@ -126,7 +132,7 @@ docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .

.PHONY: docker-build-no-test
docker-build-no-test:
docker-build-no-test: build
docker build -t ${IMG} .

.PHONY: docker-push
Expand Down Expand Up @@ -186,7 +192,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.10.0
CONTROLLER_TOOLS_VERSION ?= v0.19.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down Expand Up @@ -254,3 +260,93 @@ catalog-build: opm ## Build a catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

.PHONY: k3d-cluster
k3d-cluster:
ifndef NAME
$(error NAME is required. Usage: make k3d-cluster NAME=my-cluster)
endif
test -d tests/k3d/disk || mkdir -pv tests/k3d/disk
k3d cluster list -o json | jq '.[].name' -r | grep -q ${NAME} || \
k3d cluster create ${NAME} --kubeconfig-update-default=false --kubeconfig-switch-context=false --no-lb --no-rollback --wait -s1 -a1 --volume $(PWD)/tests/k3d/disk:/disk
k3d kubeconfig print ${NAME} > /tmp/${NAME}.kube.config

.PHONY: k3d-add-storageclass
k3d-add-storageclass: k3d-cluster
$(KUBECTL_WITH_CONFIG) apply -f tests/assets/k3d/local-path-config.yaml
$(KUBECTL_WITH_CONFIG) rollout restart deployment/local-path-provisioner -n kube-system
$(KUBECTL_WITH_CONFIG) rollout status deployment/local-path-provisioner -n kube-system
$(KUBECTL_WITH_CONFIG) annotate storageclass local-path storageclass.kubernetes.io/is-default-class- || true
$(KUBECTL_WITH_CONFIG) apply -f tests/assets/k3d/manual-storageclass.yaml

.PHONY: k3d-load-image
k3d-load-image: docker-build-no-test k3d-cluster k3d-add-storageclass
k3d image load ${IMG} -c ${NAME}

.PHONY: k3d-deploy
k3d-deploy-airlock: k3d-load-image
$(KUBECTL_WITH_CONFIG) apply -f config/crd/bases
$(KUBECTL_WITH_CONFIG) get namespace airlock-system 2>&1 >/dev/null || $(KUBECTL_WITH_CONFIG) create namespace airlock-system
$(KUBECTL_WITH_CONFIG) apply -k config/rbac
$(KUBECTL_WITH_CONFIG) apply -f config/manager/manager.yaml
$(KUBECTL_WITH_CONFIG) apply -f tests/assets/airlock
$(KUBECTL_WITH_CONFIG) set env deployment/controller-manager DEV_MODE=true -n airlock-system

.PHONY: k3d-destroy
k3d-destroy:
ifndef NAME
$(error NAME is required. Usage: make k3d-cluster NAME=my-cluster)
endif
k3d cluster delete ${NAME}

.PHONY: k3d-deploy-mongo
k3d-deploy-mongo: k3d-cluster
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/mongo

.PHONY: k3d-deploy-minio
k3d-deploy-minio: k3d-cluster k3d-add-storageclass
$(KUBECTL_WITH_CONFIG) apply -k "github.com/minio/operator?ref=v6.0.4"
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/minio

.PHONY: docker-build-backup-image
docker-build-backup-image:
docker build -t ${BIMG} backup-image/

.PHONY: k3d-load-backup-image
k3d-load-backup-image: k3d-cluster docker-build-backup-image
k3d image import -c ${NAME} ${BIMG}

.PHONY: k3d-run-backup-pod
k3d-run-backup-pod: k3d-cluster k3d-load-backup-image
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/local-tests/backup-pod.yaml

.PHONY: k3d-load-mongo-data
k3d-load-mongo-data: k3d-deploy-mongo
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/local-tests/mongo-restore-job.yaml

# subject to change as more matures
.PHONY: k3d-setup-all
k3d-setup-all: k3d-load-mongo-data k3d-load-backup-image k3d-deploy-airlock k3d-deploy-minio

.PHONY: k3d-retsart-airlock
k3d-restart-airlock:
ifndef NAME
$(error NAME is required. Usage: make k3d-restart-airlock NAME=my-cluster)
endif
$(KUBECTL_WITH_CONFIG) rollout restart deployment controller-manager -n airlock-system

# Example: make k3d-kubectl NAME=airlock-test get pods \\-A
k3d-kubectl:
ifndef NAME
$(error NAME is required. Usage: make k3d-kubectl NAME=my-cluster [kubectl args...])
endif
$(KUBECTL_WITH_CONFIG) $(wordlist 2, $(words $(MAKECMDGOALS)), $(MAKECMDGOALS))

# Support for passing commands after the target name
%::
@:

.PHONY: k3d-add-backup-store
k3d-add-backup-store: k3d-cluster
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/local-tests/mongodbbucketstoresecret.yaml
$(KUBECTL_WITH_CONFIG) apply -f ./config/samples/airlock_v1alpha1_mongodbbackupstore.yaml
Loading
Loading