forked from clusterlink-net/clusterlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·179 lines (144 loc) · 6.87 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
SHELL=/bin/bash
IMAGE_VERSION ?= latest
IMAGE_ORG ?= clusterlink-net
IMAGE_BASE ?= ghcr.io/$(IMAGE_ORG)
PLATFORMS ?= linux/amd64
GOARCH ?=amd64
#-----------------------------------------------------------------------------
# Target: clean
#-----------------------------------------------------------------------------
.PHONY: clean
clean: ; $(info cleaning previous builds...) @
@rm -rf ./bin
#------------------------------------------------------
# Setup Targets
#------------------------------------------------------
#-- emtpy file directory (used to track build target timestamps --
dist: ; $(info creating dist directory...)
@mkdir -p $@
#-- development tooling --
.PHONY: prereqs prereqs-force
prereqs: ; $(info installing dev tooling...)
@. ./hack/install-devtools.sh
prereqs-force: ; $(info force installing dev tooling...)
@. ./hack/install-devtools.sh --force
.PHONY: dev-container
dev-container: dist/.dev-container
dist/.dev-container: Containerfile.dev | dist ; $(info building dev-container...)
@docker build -f Containerfile.dev -t $(IMAGE_BASE)/dev:latest .
@touch $@
.PHONY: run-dev-container
run-dev-container: dev-container ; $(info running dev-container...)
@docker run --rm -it --network bridge \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(CURDIR):$(CURDIR) \
--workdir $(CURDIR) \
$(IMAGE_BASE)/dev:latest
#-- precommit code checks --
.PHONY: precommit format lint tests-e2e-k8s
precommit: format lint copr-fix
format: fmt
fmt: gofumpt format-go tidy-go vet-go
vet: vet-go
lint: ; $(info running linters...)
@golangci-lint run --config=./.golangci.yaml ./...
tidy-go: ; $(info tidying up go.mod...)
@go mod tidy
format-go: tidy-go vet-go ; $(info formatting code...)
@goimports -l -w .
gofumpt: ; $(info running gofumpt...)
@gofumpt -l -w .
vet-go: ; $(info vetting code...)
@go vet ./...
copr-fix: ; $(info adding copyright header...)
docker run -it --rm -v $(shell pwd):/github/workspace apache/skywalking-eyes header fix
#------------------------------------------------------
# docs targets
# Note: most are in website/Makefile
#------------------------------------------------------
.PHONY: docs-version
docs-version:
./hack/gen-doc-version.sh
#------------------------------------------------------
# Build targets
#------------------------------------------------------
GO ?= CGO_ENABLED=0 go
# Allow setting of go build flags from the command line.
GOFLAGS :=
BIN_DIR := ./bin
VERSION_FLAG := -X 'github.com/clusterlink-net/clusterlink/pkg/versioninfo.GitTag=$(shell git describe --tags --abbrev=0)'
REVISION_FLAG := -X 'github.com/clusterlink-net/clusterlink/pkg/versioninfo.Revision=$(shell git rev-parse --short HEAD)'
LD_FLAGS := -ldflags "$(VERSION_FLAG) $(REVISION_FLAG)"
export BUILDX_NO_DEFAULT_ATTESTATIONS := 1# Disable default attestations during Docker builds to prevent "unknown/unknown" image in ghcr.
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Controller Gen for crds
CONTROLLER_GEN ?= $(GOBIN)/controller-gen
CONTROLLER_TOOLS_VERSION ?= v0.14.0
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(GOBIN)
test -s $(GOBIN)/controller-gen && $(GOBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: codegen
codegen: controller-gen ## Generate ClusterRole, CRDs and DeepCopyObject.
$(CONTROLLER_GEN) crd paths="./pkg/apis/..." output:crd:artifacts:config=config/crds/
$(CONTROLLER_GEN) rbac:roleName=cl-operator-manager-role paths="./pkg/operator/..." output:rbac:dir=config/operator/rbac
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="././pkg/apis/..."
@goimports -l -w ./pkg/apis/clusterlink.net/v1alpha1/zz_generated.deepcopy.go
cli-build:
@echo "Start go build phase"
$(GO) build -o $(BIN_DIR)/clusterlink $(LD_FLAGS) ./cmd/clusterlink
build: cli-build
GOARCH=$(GOARCH) $(GO) build -o $(BIN_DIR)/$(GOARCH)/cl-controlplane $(LD_FLAGS) ./cmd/cl-controlplane
GOARCH=$(GOARCH) $(GO) build -o $(BIN_DIR)/$(GOARCH)/cl-dataplane ./cmd/cl-dataplane
GOARCH=$(GOARCH) $(GO) build -o $(BIN_DIR)/$(GOARCH)/cl-go-dataplane ./cmd/cl-go-dataplane
GOARCH=$(GOARCH) $(GO) build -o $(BIN_DIR)/$(GOARCH)/cl-operator $(LD_FLAGS) ./cmd/cl-operator/main.go
docker-build: build
docker build --platform $(PLATFORMS) --progress=plain --rm --tag cl-controlplane -f ./cmd/cl-controlplane/Dockerfile .
docker build --platform $(PLATFORMS) --progress=plain --rm --tag cl-dataplane -f ./cmd/cl-dataplane/Dockerfile .
docker build --platform $(PLATFORMS) --progress=plain --rm --tag cl-go-dataplane -f ./cmd/cl-go-dataplane/Dockerfile .
docker build --platform $(PLATFORMS) --progress=plain --rm --tag cl-operator -f ./cmd/cl-operator/Dockerfile .
push-image: build
docker buildx build --platform $(PLATFORMS) --progress=plain --rm --tag $(IMAGE_BASE)/cl-controlplane:$(IMAGE_VERSION) --push -f ./cmd/cl-controlplane/Dockerfile .
docker buildx build --platform $(PLATFORMS) --progress=plain --rm --tag $(IMAGE_BASE)/cl-go-dataplane:$(IMAGE_VERSION) --push -f ./cmd/cl-go-dataplane/Dockerfile .
docker buildx build --platform $(PLATFORMS) --progress=plain --rm --tag $(IMAGE_BASE)/cl-dataplane:$(IMAGE_VERSION) --push -f ./cmd/cl-dataplane/Dockerfile .
docker buildx build --platform $(PLATFORMS) --progress=plain --rm --tag $(IMAGE_BASE)/cl-operator:$(IMAGE_VERSION) --push -f ./cmd/cl-operator/Dockerfile .
install:
mkdir -p ~/.local/bin
cp ./bin/clusterlink ~/.local/bin/
clean-tests:
kind delete cluster --name=peer1
kind delete cluster --name=peer2
#------------------------------------------------------
# Run Targets
#------------------------------------------------------
# Envtest use for checking the deployment operator
ENVTEST ?= $(GOBIN)/setup-envtest
ENVTEST_VERSION ?= 395cfc7
ENVTEST_K8S_VERSION = 1.28.0
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(GOBIN)
test -s $(GOBIN)/setup-envtest || GOBIN=$(GOBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION)
unit-tests: envtest
@echo "Running unit tests..."
export KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(GOBIN) -p path)";\
$(GO) test -v -count=1 ./pkg/... -json -cover | tparse --all
tests-e2e-k8s:
$(GO) test -p 1 -timeout 30m -v -tags e2e-k8s ./tests/e2e/k8s
run-kind-iperf3:
python3 demos/iperf3/kind/simple_test.py
run-kind-bookinfo:
python3 demos/bookinfo/kind/test.py
#------------------------------------------------------
# Clean targets
#------------------------------------------------------
clean-kind:
kind delete cluster --name=peer1
kind delete cluster --name=peer2
kind delete cluster --name=peer3