Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate wrestic into k8up #474

Merged
merged 180 commits into from Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 179 commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
8558009
Wrapper for Restic
Kidswiss Jun 26, 2018
fed6b9b
Improvement in errorhandling and other bugfixes
Kidswiss Jul 10, 2018
3f82186
Add timeout for snapshot listing
Kidswiss Jul 10, 2018
fac35ea
Handle backups from stdin
Kidswiss Aug 6, 2018
f05b5e0
Wrapper script to pass the args correctly
Kidswiss Aug 10, 2018
53ac283
Small changes to the metric handling
Kidswiss Aug 10, 2018
33bdd0b
Merge branch 'dev' into 'master'
Aug 10, 2018
fd4a70c
Add flag to trigger prune individually
Kidswiss Aug 23, 2018
0a03600
List snapshots after backup or prune
Sep 12, 2018
236967c
Merge branch 'list-snapshots' into 'dev'
Sep 12, 2018
5e4d654
Merge branch 'dev' into 'master'
Sep 12, 2018
88a7a00
Post information to arbitrary HTTP endpoint
Kidswiss Sep 18, 2018
86d7667
Fixed bug with too small buffer
Kidswiss Sep 25, 2018
1a3ef08
Merge branch 'feature/amze-995' into 'master'
Sep 28, 2018
b718723
Restore to disk and S3
Kidswiss Sep 27, 2018
976e184
Small racecondition fixed and logging for post
Kidswiss Oct 3, 2018
6d319b0
Merge branch 'feature/restore' into 'master'
Oct 8, 2018
e412b48
Webhook after S3 restore
Kidswiss Oct 5, 2018
64e9e1d
Merge branch 'feature/restorewebhook' into 'master'
Oct 8, 2018
38a8a0c
Webhook after S3 restore
Kidswiss Oct 5, 2018
148e631
Refactoring
Kidswiss Oct 8, 2018
ecbf94a
Merge branch 'feature/PVCsinwebhook' into 'master'
Oct 30, 2018
8ccd83b
Archive function
Kidswiss Oct 11, 2018
53a23ee
Merge branch 'feature/archive' into 'master'
Oct 31, 2018
d88c2a5
Rename forge to prune for more consistent naming
Kidswiss Nov 1, 2018
e057267
Send a snapshot webhook after commands
Kidswiss Nov 1, 2018
b7d5b43
Print output on listing error
Kidswiss Nov 6, 2018
6febcf7
Make a snapshot per mounted PVC
Kidswiss Nov 1, 2018
6fb8f5e
Merge branch 'feature/webhookafterprune' into 'master'
Nov 8, 2018
a7347bd
Merge branch 'feature/snapshotpermount' into 'master'
Nov 8, 2018
91fbc36
Unlock on sigterm
Kidswiss Nov 8, 2018
d117490
Merge branch 'feature/lockhandling' into 'master'
Nov 8, 2018
4e040e3
Improve error handling
srueg Nov 21, 2018
d5db6d4
Merge branch 'error-handling' into 'master'
Nov 21, 2018
18e2158
Clean up spelling mistakes
mhutter Nov 21, 2018
0a0d879
Bump restic to 0.9.3
srueg Nov 21, 2018
bb202bf
Fail if repository can't be accessed
srueg Nov 21, 2018
659d854
Merge branch 'bump-restic' into 'master'
Nov 21, 2018
4fd30ae
Improve locking on prune
srueg Nov 21, 2018
d7abc0b
Cancel restore on single failure
srueg Nov 21, 2018
47c25d6
Merge branch 'fail-restore' into 'master'
Nov 23, 2018
da6dc55
Fail archive
Nov 23, 2018
4520dae
Run prune together with forget command
Nov 23, 2018
2e6b047
Merge branch 'fail-restore' into 'master'
Nov 28, 2018
248ec94
Increase restic timeout
Nov 29, 2018
4136bf5
Don't lock to list snapshots and files
Nov 29, 2018
38195bd
Set name for stdin backups
Dec 3, 2018
ded60f5
Merge branch 'improve' into 'master'
Dec 7, 2018
4bf5d38
Exit code != 0 on SIGTERM
Kidswiss Dec 7, 2018
9aa6291
Merge branch 'errorcode' into 'master'
Dec 7, 2018
bb6cb48
Remove unlock
Kidswiss Dec 10, 2018
6d57caf
Ability to set file extensions for stdin backups
Kidswiss Dec 11, 2018
796753c
Merge branch 'fileext' into 'master'
Dec 11, 2018
c1453a6
Increased the timeout for snapshot listing
Kidswiss Dec 13, 2018
630addb
Redisign for wrestic
Kidswiss Dec 10, 2018
ff86a41
Remove timeout for snapshotlisting
Kidswiss Dec 14, 2018
390e9cd
Make variables private in favor of interface
Kidswiss Dec 14, 2018
67cd6cd
Bugfixing
Kidswiss Dec 17, 2018
d0634b6
Archival fix
Kidswiss Dec 19, 2018
8799440
Add missing arrayOpts flag
Kidswiss Jan 16, 2019
00b6a2c
Skip PVC backup if mount folder doesn't exist
Kidswiss Jan 16, 2019
6b98653
Also add the metrics for stdin only backups to the webhook
Kidswiss Jan 22, 2019
fcdabc8
Remove unnecessary break
Kidswiss Jan 22, 2019
c2d8a8b
Webhook fixes
Kidswiss Jan 22, 2019
a9cb8b8
Merge branch 'redesign' into 'master'
Jan 30, 2019
ef8bbd5
Merge branch 'redesign' into 'master'
Jan 31, 2019
c80ef6f
Unlock before and after each Restic action
Kidswiss Feb 5, 2019
236951a
Merge branch 'more-unlock' into 'master'
Feb 5, 2019
2f00599
Don't add timestamp to stdin backups
Kidswiss Feb 5, 2019
789ecdd
Merge branch 'no-timestamp' into 'master'
Feb 5, 2019
936f37d
Use dump to tar from restic
Kidswiss Jan 15, 2019
913d286
Make stdin backup path clean
Kidswiss Feb 6, 2019
9f366b5
Handle stdin restores as well as folder restores
Kidswiss Feb 6, 2019
ef3f3cd
Merge branch 'newRestore' into 'master'
Feb 7, 2019
8beedec
Implement pod lookup in wrestic
Kidswiss Feb 11, 2019
56ba9ec
Critical error when unlock fails
Kidswiss Feb 14, 2019
503cece
Add bucket name to webhook information
Kidswiss Feb 15, 2019
a334cd4
Let restore fail if any errors
Kidswiss Feb 15, 2019
ac5b1d9
Automatic integration tests
Kidswiss Feb 12, 2019
9989ef7
Merge pull request #3 from vshn/integration_tests
Kidswiss Mar 11, 2019
55e652f
New statistics parsing
Kidswiss Jul 15, 2019
cb3af55
Log optimisations
Kidswiss Jul 17, 2019
6c96894
Merge pull request #6 from vshn/restic-0.9.4
corvus-ch Aug 13, 2019
ac82091
Build cache before stdIn backup
Kidswiss Mar 8, 2019
a770ea9
Reduce webhook information
Kidswiss Mar 8, 2019
b5da326
Integrate reduced webhooks into new output parsing
Kidswiss Sep 20, 2019
80bfd7c
Merge pull request #7 from vshn/webhook_change
Kidswiss Sep 20, 2019
31449f1
Make short IDs usable
Kidswiss Nov 6, 2019
075ce23
Merge pull request #10 from vshn/short_id
akosma Nov 6, 2019
55859c2
Correct stdin output handling
Kidswiss Nov 6, 2019
d799860
Merge pull request #9 from vshn/stdin_output_fix
Kidswiss Nov 7, 2019
76c9dc0
Ability to restore to the root of a PVC
Kidswiss Nov 7, 2019
01373dc
Merge pull request #12 from vshn/seamless_pvc_restore
akosma Nov 12, 2019
b1d36bc
Pass signals to the restic process
Kidswiss Nov 7, 2019
c027f61
Merge pull request #11 from vshn/catch_signal
Kidswiss Nov 12, 2019
dc4eeac
Adjust integration test
Kidswiss Nov 14, 2019
2d381c6
Fix race conditions
Kidswiss Nov 15, 2019
6d41eab
Merge pull request #14 from vshn/fix_raceconditions
Nov 15, 2019
f3dba5f
Fix racecondition causing hangs during backups
Kidswiss Dec 30, 2019
855aaed
Merge pull request #16 from vshn/debug_raceconditions
Kidswiss Jan 3, 2020
6002946
Skip invalid restic output
Jan 17, 2020
926588e
Give test server more time to properly shut down
Jan 17, 2020
c35d6e3
Merge pull request #17 from vshn/github-actions
Kidswiss Jan 17, 2020
cf73c46
Adding tag abilities to wrestic
Kidswiss Feb 27, 2020
9aff44c
Race condition in error parsing
Kidswiss Apr 6, 2020
cfdb5c4
Merge pull request #20 from vshn/tags
Kidswiss Apr 6, 2020
a6de8c5
update default annotation so they match vshn/restic
Schnitzel Apr 9, 2020
f42d1c8
Merge pull request #21 from Schnitzel/annotation-defaults
Kidswiss Apr 16, 2020
55353ff
Complete Wrestic rewrite
Mar 28, 2020
d3a8e0f
Fix a bug with the dump mechanism
Kidswiss May 12, 2020
e10c797
Fix race conditions for stdout/stdin handling
Kidswiss May 19, 2020
92e2606
Fixing more issues with closed pipes
Kidswiss May 20, 2020
729acf6
Completely avoid using routines for backup output
Kidswiss May 22, 2020
5c36c22
Avoid errors during integration tests
Kidswiss May 27, 2020
34c1e88
Merge pull request #22 from vshn/rewrite
Kidswiss May 29, 2020
42a8ebc
Only wait for locks if it's an exclusive job
Sep 28, 2020
28a34c1
Merge pull request #24 from vshn/fix/wait_lock_race
Kidswiss Oct 22, 2020
c6e9109
Make logging types globally available
Oct 22, 2020
d3c8052
Replace fmt.Errorf
Oct 23, 2020
7fc46ce
Merge pull request #27 from vshn/fix/dropped_errors
Kidswiss Oct 26, 2020
55d6d2b
Don't print progress for stdin backups
Oct 22, 2020
dc79bbe
Merge pull request #28 from vshn/fix/ignore_stdin_progress
Kidswiss Oct 26, 2020
dc4e32b
Adjust exit code handling to 0.12.0
Mar 4, 2021
f7e7993
Adjust tests for new error string
Mar 4, 2021
e332203
Merge pull request #67 from vshn/improve_exit_handling
Kidswiss Mar 4, 2021
c5e5020
Check for nil process
Mar 5, 2021
9f974c2
Merge pull request #73 from vshn/fix_restic_binary
Kidswiss Mar 8, 2021
4400fc2
Improve var names
Mar 16, 2021
c0b9858
Catch some more errors
Mar 16, 2021
721058e
Move restore stats to stats.go
Mar 16, 2021
675cb14
Refactor a bit
Mar 16, 2021
efb48ba
Add stats to restore
Mar 16, 2021
47c61c8
Add integration test for restore webhooks
Mar 16, 2021
f97759a
Merge pull request #77 from vshn/restore_webhook
Kidswiss Mar 19, 2021
6aff0b9
Make parsing restic output resilient to non-json output
cimnine Mar 29, 2021
9fb4f35
Fix Index Out Of Bounds error
cimnine Mar 29, 2021
7b8bfd9
Merge pull request #81 from vshn/ResilientLogging
cimnine Mar 29, 2021
f8e2c32
Reduce Restic Progress FPS
cimnine Mar 29, 2021
7fcef72
Merge pull request #82 from vshn/ReduceResticOutputFrequency
cimnine Mar 30, 2021
20bef97
Refactor integration tests
cimnine May 17, 2021
f4f6969
Pass multiple 'option' flags to restic
cimnine May 11, 2021
11ed70d
Print restic command and args that is eventually invoked
cimnine May 11, 2021
1b3bba6
Extract constant
cimnine May 20, 2021
f55e370
Merge pull request #89 from vshn/PassOptionsToRestic
cimnine May 20, 2021
211afed
Fix backing up of annotated pods
cimnine May 27, 2021
d795f66
Add changelog entry
cimnine May 27, 2021
e313204
Merge pull request #93 from vshn/FixBackupOfAnnotatedPods
cimnine May 27, 2021
6b2d4b0
Remove stale locks before invoking other restic actions
cimnine Jul 30, 2021
163fb46
Merge pull request #98 from vshn/UnlockBeforeActions
cimnine Jul 30, 2021
0d088c9
Move library functions to restic package
cimnine Aug 5, 2021
afdd6a1
Merge pull request #101 from vshn/MoveLibraryCode
cimnine Aug 5, 2021
b73c06b
Merge branch 'master' of ../wrestic into AddWrestic
cimnine Aug 5, 2021
6225e6d
Combine build dependencies
cimnine Aug 5, 2021
f2ba8a3
Single CLI
cimnine Aug 5, 2021
e09a1ba
Fix compilation (and update to k8s 1.21 apis)
cimnine Aug 6, 2021
386e5a8
Combine integration tests
cimnine Aug 6, 2021
0bd6cd6
Use absolute path for KUBEBUILDER_ASSETS
cimnine Aug 6, 2021
4f539df
Fix e2etest-dir in Makefile
cimnine Aug 6, 2021
1e2eb07
Update detik to version 1.1.0
cimnine Aug 6, 2021
6925a6d
Update k8s to 1.21
cimnine Aug 12, 2021
aef633c
fix wrong word in restore log message
cimnine Aug 12, 2021
d0adce4
update gh e2e-test action to k8s 1.21.2
cimnine Aug 12, 2021
f362252
ensure kubectl matches cluster version
cimnine Aug 12, 2021
5db2e8c
silence kubectl output
cimnine Aug 12, 2021
d4f3fce
Better debug info
cimnine Aug 12, 2021
348cb2b
Filter non-json output in restic_snapshots
cimnine Aug 12, 2021
75f2c82
Filter 'pod completed' messages
cimnine Aug 13, 2021
f90a47d
Renamed tests to match bats output
cimnine Aug 13, 2021
8db761d
fixup! Filter 'pod completed' messages
cimnine Aug 13, 2021
3332448
Don't test with k8s 1.13 anymore
cimnine Aug 13, 2021
489989b
Don't output comments in Makefile
cimnine Aug 13, 2021
482e87c
Fix permission problem in e2e test
cimnine Aug 16, 2021
a03e041
Root and non-root wrestic
cimnine Aug 16, 2021
e66464f
Add ARGS to 'make run'
cimnine Aug 16, 2021
9706cd1
Change default goal in Makefile
cimnine Aug 19, 2021
fb3455e
Fix templating in .goreleaser.yml
cimnine Aug 19, 2021
5e34f47
Improved docs for the two modules, operator and restic
cimnine Aug 19, 2021
c1d9dc1
Use 'v' prefix for Docker image version tags
cimnine Aug 19, 2021
8ec4719
Fix snapshot version producing 'vvX.Y.Z'
cimnine Aug 19, 2021
56ac67e
Remove dead code
cimnine Aug 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
@@ -1,3 +1,4 @@
.*
*
!k8up
!wrestic/wrestic.sh
8 changes: 6 additions & 2 deletions .github/workflows/e2e.yml
Expand Up @@ -11,9 +11,9 @@ jobs:
strategy:
matrix:
include:
- kind-node-version: v1.20.0
- kind-node-version: v1.21.2
crd-spec-version: v1
- kind-node-version: v1.13.12 # we cannot go lower than that because of Kind, see https://github.com/kubernetes-sigs/kind/issues/1853
- kind-node-version: v1.18.19
crd-spec-version: v1beta1
steps:
- uses: actions/checkout@v2
Expand All @@ -28,6 +28,10 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: azure/setup-kubectl@v1
with:
version: ${{ matrix.kind-node-version }}
id: install
- name: Run e2e tests
run: make crd e2e-test -e CRD_SPEC_VERSION=${{ matrix.crd-spec-version }} -e KIND_NODE_VERSION=${{ matrix.kind-node-version }} -e KIND_KUBECTL_ARGS=--validate=false -e bats_args="--report-formatter junit"
- name: Publish Test Report
Expand Down
36 changes: 11 additions & 25 deletions .gitignore
@@ -1,48 +1,34 @@
# Created by .ignore support plugin (hsz.mobi)
### Example user template template
### Example user template

# VSCode configs
.vscode/

# IntelliJ project files
.idea
*.iml
out
gen### Go template
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
__debug_bin

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
coverage/

# Antora related
.asciidoctor
.cache
_public/
_archive/

*.DS_Store
cmd/*/debug
cmd/operator/operator
cmd/restic/restic

bin/
dist/
.github/release-notes.md

k8up-crd*.yaml

/k8up
testbin/

# Go releaser
dist/

# Test related
node_modules/
e2e/debug
__debug_bin
coverage/
.integration-test/
.e2e-test/
43 changes: 40 additions & 3 deletions .goreleaser.yml
Expand Up @@ -2,7 +2,9 @@
# Make sure to check the documentation at http://goreleaser.com

builds:
- env:
- main: ./cmd/k8up
binary: k8up
env:
- CGO_ENABLED=0 # this is needed otherwise the Docker image build is faulty
goarch:
- amd64
Expand All @@ -13,10 +15,9 @@ checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ .Tag }}-snapshot"
name_template: "{{ incpatch .Version }}-snapshot"

dockers:

- image_templates:
- "docker.io/vshn/k8up:v{{ .Version }}"
- "quay.io/vshn/k8up:v{{ .Version }}"
Expand All @@ -29,6 +30,42 @@ dockers:

- "{{ if not .Prerelease }}docker.io/vshn/k8up:latest{{ end }}"
- "{{ if not .Prerelease }}quay.io/vshn/k8up:latest{{ end }}"
build_flag_templates:
- "--target=k8up"
extra_files:
- wrestic/wrestic.sh
- image_templates:
- "docker.io/vshn/wrestic:v{{ .Version }}-nonroot"
- "quay.io/vshn/wrestic:v{{ .Version }}-nonroot"

# For prereleases, updating `latest` and the floating tags of the major
# version does not make sense. Only the image for the exact version should
# be pushed.
- "{{ if not .Prerelease }}docker.io/vshn/wrestic:v{{ .Major }}-nonroot{{ end }}"
- "{{ if not .Prerelease }}quay.io/vshn/wrestic:v{{ .Major }}-nonroot{{ end }}"

- "{{ if not .Prerelease }}docker.io/vshn/wrestic:latest-nonroot{{ end }}"
- "{{ if not .Prerelease }}quay.io/vshn/wrestic:latest-nonroot{{ end }}"
build_flag_templates:
- "--target=wrestic"
extra_files:
- wrestic/wrestic.sh
- image_templates:
- "docker.io/vshn/wrestic:v{{ .Version }}"
- "quay.io/vshn/wrestic:v{{ .Version }}"

# For prereleases, updating `latest` and the floating tags of the major
# version does not make sense. Only the image for the exact version should
# be pushed.
- "{{ if not .Prerelease }}docker.io/vshn/wrestic:v{{ .Major }}{{ end }}"
- "{{ if not .Prerelease }}quay.io/vshn/wrestic:v{{ .Major }}{{ end }}"

- "{{ if not .Prerelease }}docker.io/vshn/wrestic:latest{{ end }}"
- "{{ if not .Prerelease }}quay.io/vshn/wrestic:latest{{ end }}"
build_flag_templates:
- "--target=wrestic-root"
extra_files:
- wrestic/wrestic.sh

release:
prerelease: auto
Expand Down
38 changes: 33 additions & 5 deletions Dockerfile
@@ -1,9 +1,37 @@
FROM docker.io/library/alpine:3.14 as runtime
FROM docker.io/library/alpine:3.14 as k8up

ENTRYPOINT ["k8up"]

RUN \
apk add --no-cache curl bash tzdata
RUN mkdir /.cache && chmod -R g=u /.cache

COPY k8up /usr/bin/
USER 65532:65532
RUN apk add --update --no-cache \
bash \
ca-certificates \
curl \
fuse \
openssh-client \
tzdata

ENV RESTIC_BINARY=/usr/local/bin/restic

COPY wrestic/wrestic.sh /app/wrestic
COPY --from=restic/restic:0.12.1 /usr/bin/restic $RESTIC_BINARY
COPY k8up /usr/local/bin/

RUN chmod a+x /usr/local/bin/k8up /usr/local/bin/restic /app/wrestic

USER 65532

## wrestic compatibility shim
FROM k8up as wrestic

WORKDIR /app
ENTRYPOINT ["./wrestic"]

## wrestic root compatibility shim
FROM wrestic as wrestic-root

USER 0

## Default build shall not contain the wrestic compatibility stuff
FROM k8up as default
73 changes: 42 additions & 31 deletions Makefile
Expand Up @@ -6,48 +6,56 @@ MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
.SUFFIXES:
.SECONDARY:
.DEFAULT_GOAL := help

PROJECT_ROOT_DIR = .
include Makefile.vars.mk
include Makefile.restic-integration.mk

e2e_make := $(MAKE) -C e2e
go_build ?= go build -o $(BIN_FILENAME) cmd/operator/main.go

setup-envtest ?= go run sigs.k8s.io/controller-runtime/tools/setup-envtest $(ENVTEST_ADDITIONAL_FLAGS)

# Run tests (see https://sdk.operatorframework.io/docs/building-operators/golang/references/envtest-setup)
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
go_build ?= go build -o $(BIN_FILENAME) cmd/k8up/main.go

all: build ## Invokes the build target

.PHONY: test
test: ## Run tests
go test ./... -coverprofile cover.out

.PHONY: integration-test
# operator module {
# See https://storage.googleapis.com/kubebuilder-tools/ for list of supported K8s versions
#
# A note on 1.20.2:
# 1.20.2 is not (yet) supported, because starting the Kubernetes API controller with
# `--insecure-port` and `--insecure-bind-address` flags is now deprecated,
# but envtest was not updated accordingly.
#integration-test: export ENVTEST_K8S_VERSION = 1.20.x
integration-test: export ENVTEST_K8S_VERSION = 1.19.x
integration-test: export ENVTEST_K8S_VERSION = 1.21.x
integration-test: export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT = $(INTEGRATION_TEST_DEBUG_OUTPUT)
integration-test: generate $(testbin_created) ## Run integration tests with envtest
# }
# restic module {
integration-test: export RESTIC_PATH = $(restic_path)
integration-test: export RESTIC_BINARY = $(restic_path)
integration-test: export RESTIC_PASSWORD = $(restic_password)
integration-test: export RESTIC_REPOSITORY = s3:http://$(minio_address)/test
integration-test: export RESTORE_S3ENDPOINT = http://$(minio_address)/restore
integration-test: export AWS_ACCESS_KEY_ID = $(minio_root_user)
integration-test: export AWS_SECRET_ACCESS_KEY = $(minio_root_password)
integration-test: export RESTORE_ACCESSKEYID = $(minio_root_user)
integration-test: export RESTORE_SECRETACCESSKEY = $(minio_root_password)
integration-test: export BACKUP_DIR = $(backup_dir)
integration-test: export RESTORE_DIR = $(restore_dir)
integration-test: export STATS_URL = $(stats_url)
# }
integration-test: generate $(integrationtest_dir_created) restic-integration-test-setup ## Run integration tests with envtest
$(setup-envtest) use '$(ENVTEST_K8S_VERSION)!'
export KUBEBUILDER_ASSETS="$$($(setup-envtest) use -i -p path '$(ENVTEST_K8S_VERSION)!')"; \
env | grep KUBEBUILDER; \
go test -tags=integration -v ./... -coverprofile cover.out
go test -tags=integration -coverprofile cover.out ./...

.PHONY: build
build: generate fmt vet $(BIN_FILENAME) ## Build manager binary

.PHONY: run
run: export BACKUP_ENABLE_LEADER_ELECTION = $(ENABLE_LEADER_ELECTION)
run: export BACKUP_LOG_LEVEL = debug
run: export K8UP_DEBUG = true
run: export BACKUP_OPERATOR_NAMESPACE = default
run: fmt vet ## Run against the configured Kubernetes cluster in ~/.kube/config
go run ./cmd/operator/main.go
run: fmt vet ## Run against the configured Kubernetes cluster in ~/.kube/config. Use ARGS to pass arguments to the command, e.g. `make run ARGS="--help"`
go run ./cmd/k8up/main.go $(ARGS)

.PHONY: install
install: generate ## Install CRDs into a cluster
Expand Down Expand Up @@ -86,18 +94,20 @@ lint: fmt vet ## Invokes the fmt and vet targets
git diff --exit-code

.PHONY: docker-build
docker-build: export GOOS = linux
docker-build: $(BIN_FILENAME) ## Build the docker image
docker build . -t $(DOCKER_IMG) -t $(QUAY_IMG) -t $(E2E_IMG)
docker build . --target=k8up -t $(K8UP_DOCKER_IMG) -t $(K8UP_QUAY_IMG) -t $(K8UP_E2E_IMG)
docker build . --target=wrestic -t $(WRESTIC_DOCKER_IMG) -t $(WRESTIC_QUAY_IMG) -t $(WRESTIC_E2E_IMG)

.PHONY: docker-push
docker-push: ## Push the docker image
docker push $(DOCKER_IMG)
docker push $(QUAY_IMG)
docker push $(K8UP_DOCKER_IMG) $(WRESTIC_DOCKER_IMG) $(K8UP_QUAY_IMG) $(WRESTIC_QUAY_IMG)

clean: export KUBECONFIG = $(KIND_KUBECONFIG)
clean: e2e-clean kind-clean ## Cleans up the generated resources
rm -r testbin/ dist/ bin/ cover.out $(BIN_FILENAME) || true
clean: restic-integration-test-clean e2e-clean docs-clean ## Cleans up the generated resources
# setup-envtest removes write permission from the files it generates, so they have to be restored in order to delete the directory
chmod +rwx -R -f $(integrationtest_dir) || true

rm -rf $(e2etest_dir) $(integrationtest_dir) dist/ bin/ cover.out $(BIN_FILENAME) || true

.PHONY: help
help: ## Show this help
Expand All @@ -107,19 +117,20 @@ help: ## Show this help
### Assets
###

$(testbin_created):
mkdir -p $(TESTBIN_DIR)
# a marker file must be created, because the date of the
# directory may update when content in it is created/updated,
# which would cause a rebuild / re-initialization of dependants
@touch $(testbin_created)

# Build the binary without running generators
.PHONY: $(BIN_FILENAME)
$(BIN_FILENAME): export CGO_ENABLED = 0
$(BIN_FILENAME): export GOOS = linux
$(BIN_FILENAME):
$(go_build)

$(integrationtest_dir_created):
mkdir -p $(integrationtest_dir)
# a marker file must be created, because the date of the
# directory may update when content in it is created/updated,
# which would cause a rebuild / re-initialization of dependants
@touch $(integrationtest_dir_created)

###
### KIND
###
Expand Down