-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
173 lines (137 loc) · 5.47 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
## Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
# KubeOS is licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
## See the Mulan PSL v2 for more details.
# Image URL to use all building/pushing image targets
IMG_PROXY ?= proxy:latest
IMG_OPERATOR ?= operator:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
# 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
GO := go
ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
export GO111MODULE=on
export GO_BUILD = $(GO) build -mod=vendor
else
export GO_BUILD=$(GO) build
endif
VERSION_FILE := ./VERSION
VERSION := $(shell cat $(VERSION_FILE))
PACKAGE:=openeuler.org/KubeOS/pkg/version
EXTRALDFLAGS := -linkmode=external -extldflags=-ftrapv \
-extldflags=-Wl,-z,relro,-z,now
LD_FLAGS := -ldflags '-buildid=IdByKubeOS \
-X ${PACKAGE}.Version=${VERSION} \
$(EXTRALDFLAGS) '
GO_BUILD_CGO = CGO_ENABLED=1 \
CGO_CFLAGS="-fstack-protector-strong -fPIE -fPIC -D_FORTIFY_SOURCE=2 -O2" \
CGO_LDFLAGS_ALLOW='-Wl,-z,relro,-z,now' \
CGO_LDFLAGS="-Wl,-z,relro,-z,now -Wl,-z,noexecstack" \
${GO_BUILD} -buildmode=pie -trimpath -tags "seccomp selinux static_build cgo netgo osusergo"
RUSTFLAGS := RUSTFLAGS="-C relocation_model=pic -D warnings -W unsafe_code -W rust_2021_incompatible_closure_captures -C link-arg=-s"
all: operator hostshell rust-kubeos
# Build binary
operator:
${GO_BUILD_CGO} ${LD_FLAGS} -o bin/operator cmd/operator/main.go
strip bin/operator
hostshell:
${GO_BUILD_CGO} ${LD_FLAGS} -o bin/hostshell cmd/admin-container/main.go
strip bin/hostshell
rust-kubeos:
${RUSTFLAGS} cargo build --profile release --target-dir ./bin/rust
proxy:
${RUSTFLAGS} cargo build --profile release --target-dir ./bin/rust --package proxy
agent:
${RUSTFLAGS} cargo build --profile release --target-dir ./bin/rust --package os-agent
kbimg:
${RUSTFLAGS} cargo build --profile release --target-dir ./bin/rust --package kbimg
# clean binary
clean:
rm -rf bin
# Install CRDs into a cluster
install: manifests
kubectl apply -f config/crd
# Uninstall CRDs from a cluster
uninstall: manifests
kubectl delete -f config/crd
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
kubectl apply -f config/rbac
kubectl apply -f config/manager
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
undeploy:
kubectl delete -f config/rbac
kubectl delete -f config/manager
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=upgrade-manager-role paths="./..." output:crd:artifacts:config=config/crd
# Run go fmt against code
fmt:
go fmt ./...
# Run go vet against code
vet:
go vet ./...
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
docker-build: operator rust-proxy
docker build --target operator -t ${IMG_OPERATOR} .
docker build --target proxy -t ${IMG_PROXY} .
# Push the docker image
docker-push:
docker push ${IMG_OPERATOR}
docker push ${IMG_PROXY}
## Location to install dependencies to
LOCALBIN = $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN = $(LOCALBIN)/controller-gen
ENVTEST = $(LOCALBIN)/setup-envtest
## Tool Versionsjk
CONTROLLER_TOOLS_VERSION = v0.5.0
ENVTEST_K8S_VERSION = 1.20.2 ## ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
# Download kustomize locally if necessary
KUSTOMIZE = $(LOCALBIN)/kustomize
kustomize:
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
ARCH := $(shell uname -m)
TEST_CMD := go test `go list ./cmd/... | grep -E 'controllers'` -race -count=1 -timeout=300s -cover -gcflags=all=-l -p 1
ifeq ($(ARCH), aarch64)
TEST_CMD := ETCD_UNSUPPORTED_ARCH=arm64 $(TEST_CMD)
endif
.PHONY: test
test: fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(TEST_CMD)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef