-
Notifications
You must be signed in to change notification settings - Fork 34
/
Makefile
160 lines (131 loc) · 5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Image URL to use all building/pushing image targets
REGISTRY ?= quay.io
REPO ?= kubevirt
IMAGE_TAG ?= latest
IMAGE_GIT_TAG ?= $(shell git describe --abbrev=8 --tags)
IMG ?= $(REPO)/kubemacpool
OCI_BIN ?= $(shell if podman ps >/dev/null 2>&1; then echo podman; elif docker ps >/dev/null 2>&1; then echo docker; fi)
TLS_SETTING := $(if $(filter $(OCI_BIN),podman),--tls-verify=false,)
PLATFORM_LIST ?= linux/amd64,linux/s390x,linux/arm64
ARCH := $(shell uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
PLATFORMS ?= linux/${ARCH}
PLATFORMS := $(if $(filter all,$(PLATFORMS)),$(PLATFORM_LIST),$(PLATFORMS))
# Define the platforms for building a multi-platform image.
# Example:
# PLATFORMS ?= linux/amd64,linux/arm64,linux/s390x
# Alternatively, you can set the PLATFORMS variable using:
# export PLATFORMS=linux/arm64,linux/s390x,linux/amd64
# or export PLATFORMS=all to automatically include all supported platforms.
DOCKER_BUILDER ?= kubemacpool-docker-builder
KUBEMACPOOL_IMAGE_TAGGED := ${REGISTRY}/${IMG}:${IMAGE_TAG}
KUBEMACPOOL_IMAGE_GIT_TAGGED := ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}
BIN_DIR = $(CURDIR)/build/_output/bin/
export GOFLAGS=-mod=vendor
export GO111MODULE=on
export GOROOT=$(BIN_DIR)/go/
export GOBIN=$(GOROOT)/bin/
export PATH := $(GOBIN):$(PATH)
export GO := $(GOBIN)/go
KUSTOMIZE := GOFLAGS=-mod=mod $(GO) run sigs.k8s.io/kustomize/kustomize/[email protected]
CONTROLLER_GEN := GOFLAGS=-mod=mod $(GO) run sigs.k8s.io/controller-tools/cmd/[email protected]
GOFMT := GOFLAGS=-mod=mod $(GO)fmt
VET := GOFLAGS=-mod=mod $(GO) vet
DEEPCOPY_GEN := GOFLAGS=-mod=mod $(GO) install k8s.io/code-generator/cmd/deepcopy-gen@latest
GO_VERSION = $(shell hack/go-version.sh)
E2E_TEST_EXTRA_ARGS ?=
export E2E_TEST_TIMEOUT ?= 1h
E2E_TEST_ARGS ?= $(strip -test.v -test.timeout=$(E2E_TEST_TIMEOUT) -ginkgo.timeout=$(E2E_TEST_TIMEOUT) -ginkgo.v $(E2E_TEST_EXTRA_ARGS))
export KUBECTL ?= cluster/kubectl.sh
all: generate
$(GO):
hack/install-go.sh $(BIN_DIR) > /dev/null
# Run tests
test: $(GO)
$(GO) test ./pkg/... ./cmd/... -coverprofile cover.out
functest: $(GO)
GO=$(GO) TEST_ARGS="$(E2E_TEST_ARGS)" ./hack/functest.sh
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: generate-deploy
$(KUBECTL) apply -f config/test/kubemacpool.yaml
deploy-test: generate-test
$(KUBECTL) apply -f config/test/kubemacpool.yaml
generate-deploy: $(GO) manifests
$(KUSTOMIZE) build config/release > config/release/kubemacpool.yaml
generate-test: $(GO) manifests
$(KUSTOMIZE) build config/test > config/test/kubemacpool.yaml
generate-external: $(GO) manifests
cp -r config/test config/external
cd config/external && \
$(KUSTOMIZE) edit set image quay.io/kubevirt/kubemacpool=$(REGISTRY)/$(IMG)
$(KUSTOMIZE) build config/external > config/external/kubemacpool.yaml
# Generate manifests e.g. CRD, RBAC etc.
manifests: $(GO)
$(CONTROLLER_GEN) crd rbac:roleName=kubemacpool paths=./pkg/... output:crd:dir=config/ output:stdout
# Run go fmt against code
fmt: $(GO)
$(GOFMT) -d pkg/ cmd/ tests/
# Run go vet against code
vet: $(GO)
$(VET) ./pkg/... ./cmd/... ./tests/...
install-deep-copy: $(GO)
$(DEEPCOPY_GEN)
# Generate code
generate-go: install-deep-copy fmt vet manifests
PATH=$(GOBIN):$(PATH) $(GO) generate ./pkg/... ./cmd/...
generate: generate-go generate-deploy generate-test generate-external
check: $(GO)
./hack/check.sh
# Build the docker image
container:
./hack/build-multiarch-kubemacpool.sh $(ARCH) $(PLATFORMS) $(KUBEMACPOOL_IMAGE_TAGGED) $(KUBEMACPOOL_IMAGE_GIT_TAGGED) $(DOCKER_BUILDER) $(OCI_BIN) $(REGISTRY)
# Push the docker image
docker-push:
@if [ "$(OCI_BIN)" = "podman" ]; then \
podman manifest push ${TLS_SETTING} ${REGISTRY}/${IMG}:${IMAGE_TAG} ${REGISTRY}/${IMG}:${IMAGE_TAG}; \
fi
@if [[ "${REGISTRY}" == localhost* || "${REGISTRY}" == 127.0.0.1* ]]; then \
echo "Local registry detected (${REGISTRY}). Skipping IMAGE_GIT_TAG handling."; \
else \
if skopeo inspect docker://${REGISTRY}/${IMG}:${IMAGE_GIT_TAG} >/dev/null 2>&1; then \
echo "Tag '${IMAGE_GIT_TAG}' already exists. Skipping tagging and push."; \
elif skopeo inspect docker://${REGISTRY}/${IMG}:${IMAGE_GIT_TAG} 2>&1 | grep -q "manifest unknown"; then \
if [ "$(OCI_BIN)" = "podman" ]; then \
podman tag ${REGISTRY}/${IMG}:${IMAGE_TAG} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}; \
podman manifest push ${TLS_SETTING} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG} ${REGISTRY}/${IMG}:${IMAGE_GIT_TAG}; \
fi \
else \
echo "Error checking for tag '${IMAGE_GIT_TAG}'. Aborting to avoid potential overwrite."; \
exit 1; \
fi; \
fi
cluster-up:
./cluster/up.sh
cluster-down:
./cluster/down.sh
cluster-sync:
./cluster/sync.sh
cluster-clean:
./cluster/clean.sh
bump-kubevirtci:
./hack/bump-kubevirtci.sh
vendor: $(GO)
$(GO) mod tidy -compat=$(GO_VERSION)
$(GO) mod vendor
.PHONY: \
vendor \
test \
deploy \
deploy-test \
generate \
generate-go \
generate-deploy \
generate-test \
manifests \
fmt \
vet \
check \
container \
push \
cluster-up \
cluster-down \
cluster-sync