This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
159 lines (132 loc) · 5.11 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
# Image URL to use all building/pushing image targets
TAG ?= v0.7.0-alpha
REPO ?= openyurt
MANAGER_IMG ?= ${REPO}/yurtcluster-operator-manager:${TAG}
AGENT_IMG ?= ${REPO}/yurtcluster-operator-agent:${TAG}
# Go ldflags for version vars
GO_LD_FLAGS ?= $(shell hack/lib/version.sh yurt::version::ldflags)
# Build linux/amd64 arch with `make release-artifacts DOCKER_BUILD_PLATFORMS=linux/amd64`
DOCKER_BUILD_PLATFORMS ?= linux/amd64,linux/arm64,linux/arm/v7
DOCKER_BUILD_GO_PROXY_ARG ?= GO_PROXY=https://goproxy.cn,direct
DOCKER_BUILD_GO_LD_FLAGS_ARG ?= GO_LD_FLAGS="${GO_LD_FLAGS}"
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
# 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
all: manager agent edgectl
# Run tests
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
# Build manager binary
manager: generate fmt vet
go build --ldflags "${GO_LD_FLAGS}" -o bin/manager cmd/manager/manager.go
# Build agent binary
agent: generate fmt vet
go build --ldflags "${GO_LD_FLAGS}" -o bin/agent cmd/agent/agent.go
# Build edgectl binary
edgectl: generate fmt vet
go build --ldflags "${GO_LD_FLAGS}" -o bin/edgectl cmd/edgectl/edgectl.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run --ldflags "${GO_LD_FLAGS}" ./cmd/manager/manager.go
# Install CRDs into a cluster
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image yurtcluster-operator-manager=${MANAGER_IMG}
cd config/agent && $(KUSTOMIZE) edit set image yurtcluster-operator-agent=${AGENT_IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
# Release manifests into docs/manifests and push docker image to dockerhub
release-artifacts: docker-push release-manifests
# Release manifests into docs/manifests
release-manifests: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image yurtcluster-operator-manager=${MANAGER_IMG}
cd config/agent && $(KUSTOMIZE) edit set image yurtcluster-operator-agent=${AGENT_IMG}
$(KUSTOMIZE) build config/default > docs/manifests/deploy.yaml
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." \
output:crd:artifacts:config=config/crd/bases
cp config/crd/bases/* charts/crds/
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Lint codebase
lint: golangci-lint
$(GOLANGCI_LINT) run
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image (only linux/amd64 arch)
docker-build: docker-build-manager docker-build-agent
docker-build-manager:
docker buildx build --load --platform linux/amd64 -f Dockerfile . -t ${MANAGER_IMG} \
--build-arg ${DOCKER_BUILD_GO_PROXY_ARG} --build-arg ${DOCKER_BUILD_GO_LD_FLAGS_ARG}
docker-build-agent:
docker buildx build --load --platform linux/amd64 -f Dockerfile.agent . -t ${AGENT_IMG} \
--build-arg ${DOCKER_BUILD_GO_PROXY_ARG} --build-arg ${DOCKER_BUILD_GO_LD_FLAGS_ARG}
# Push the docker images with multi-arch
docker-push: docker-push-manager docker-push-agent
docker-push-manager:
docker buildx build --push --platform ${DOCKER_BUILD_PLATFORMS} -f Dockerfile . -t ${MANAGER_IMG} \
--build-arg ${DOCKER_BUILD_GO_PROXY_ARG} --build-arg ${DOCKER_BUILD_GO_LD_FLAGS_ARG}
docker-push-agent:
docker buildx build --push --platform ${DOCKER_BUILD_PLATFORMS} -f Dockerfile.agent . -t ${AGENT_IMG} \
--build-arg ${DOCKER_BUILD_GO_PROXY_ARG} --build-arg ${DOCKER_BUILD_GO_LD_FLAGS_ARG}
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
# find or download golangci-lint
golangci-lint:
ifeq (, $(shell which golangci-lint))
@{ \
set -e ;\
GOLANGCI_LINT_TMP_DIR=$$(mktemp -d) ;\
cd $$GOLANGCI_LINT_TMP_DIR ;\
go mod init tmp ;\
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1 ;\
rm -rf $$GOLANGCI_LINT_TMP_DIR ;\
}
GOLANGCI_LINT=$(GOBIN)/golangci-lint
else
GOLANGCI_LINT=$(shell which golangci-lint)
endif
# find or download kustomize
kustomize:
ifeq (, $(shell which kustomize))
@{ \
set -e ;\
KUSTOMIZE_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/v4@v4.5.2 ;\
rm -rf $$KUSTOMIZE_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif