Makefile 5.2 KB
Newer Older
J
jeff 已提交
1 2 3 4 5 6 7
# Copyright 2018 The KubeSphere Authors. All rights reserved.
# Use of this source code is governed by a Apache license
# that can be found in the LICENSE file.

# The binary to build 
BIN ?= ks-apiserver

8 9 10 11 12 13 14 15 16 17 18
# 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


J
jeff 已提交
19 20
IMG ?= kubespheredev/ks-apiserver
OUTPUT_DIR=bin
M
magicsong 已提交
21
GOFLAGS=-mod=vendor
J
jeff 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
define ALL_HELP_INFO
# Build code.
#
# Args:
#   WHAT: Directory names to build.  If any of these directories has a 'main'
#     package, the build will produce executable files under $(OUT_DIR).
#     If not specified, "everything" will be built.
#   GOFLAGS: Extra flags to pass to 'go' when building.
#   GOLDFLAGS: Extra linking flags passed to 'go' when building.
#   GOGCFLAGS: Additional go compile flags passed to 'go' when building.
#
# Example:
#   make
#   make all
#   make all WHAT=cmd/ks-apiserver
#     Note: Use the -N -l options to disable compiler optimizations an inlining.
#           Using these build options allows you to subsequently use source
#           debugging tools like delve.
endef
.PHONY: all
H
update  
hongming 已提交
42
all: test hypersphere ks-apiserver controller-manager
J
jeff 已提交
43 44

# Build ks-apiserver binary
R
runzexia 已提交
45
ks-apiserver: fmt vet
J
jeff 已提交
46 47
	hack/gobuild.sh cmd/ks-apiserver

J
Jeff 已提交
48
# Build controller-manager binary
R
runzexia 已提交
49
controller-manager: fmt vet
J
Jeff 已提交
50 51
	hack/gobuild.sh cmd/controller-manager

52
# Build hypersphere binary
R
runzexia 已提交
53
hypersphere: fmt vet
54 55
	hack/gobuild.sh cmd/hypersphere

J
jeff 已提交
56
# Run go fmt against code 
57
fmt: generate
58
	gofmt -w ./pkg ./cmd ./tools ./api
J
jeff 已提交
59 60

# Run go vet against code
61
vet: generate
J
jeff 已提交
62 63
	go vet ./pkg/... ./cmd/...

J
jeff 已提交
64 65
# Generate manifests e.g. CRD, RBAC etc.
manifests:
R
runzexia 已提交
66
	go run ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all
J
jeff 已提交
67 68 69 70 71

deploy: manifests
	kubectl apply -f config/crds
	kustomize build config/default | kubectl apply -f -

72 73
# generate will generate crds' deepcopy & go openapi structs
# Futher more about go:genreate . https://blog.golang.org/generate
74
generate:
J
jeff 已提交
75
	go generate ./pkg/... ./cmd/...
R
runzexia 已提交
76

R
runzexia 已提交
77 78 79 80 81 82 83
deepcopy:
	GO111MODULE=on go install -mod=vendor k8s.io/code-generator/cmd/deepcopy-gen
	${GOPATH}/bin/deepcopy-gen -i kubesphere.io/kubesphere/pkg/apis/... -h ./hack/boilerplate.go.txt -O zz_generated.deepcopy

openapi:
	go run ./vendor/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go -O openapi_generated -i ./vendor/k8s.io/apimachinery/pkg/apis/meta/v1,./pkg/apis/tenant/v1alpha1 -p kubesphere.io/kubesphere/pkg/apis/tenant/v1alpha1 -h ./hack/boilerplate.go.txt --report-filename ./api/api-rules/violation_exceptions.list
	go run ./vendor/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go -O openapi_generated -i ./vendor/k8s.io/apimachinery/pkg/apis/meta/v1,./pkg/apis/servicemesh/v1alpha2 -p kubesphere.io/kubesphere/pkg/apis/servicemesh/v1alpha2 -h ./hack/boilerplate.go.txt --report-filename ./api/api-rules/violation_exceptions.list
R
runzexia 已提交
84 85
	go run ./vendor/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go -O openapi_generated -i ./vendor/k8s.io/api/networking/v1,./vendor/k8s.io/apimachinery/pkg/apis/meta/v1,./vendor/k8s.io/apimachinery/pkg/util/intstr,./pkg/apis/network/v1alpha1 -p kubesphere.io/kubesphere/pkg/apis/network/v1alpha1 -h ./hack/boilerplate.go.txt --report-filename ./api/api-rules/violation_exceptions.list
	go run ./vendor/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go -O openapi_generated -i ./vendor/k8s.io/apimachinery/pkg/apis/meta/v1,./pkg/apis/devops/v1alpha1,./vendor/k8s.io/apimachinery/pkg/runtime,./vendor/k8s.io/api/core/v1 -p kubesphere.io/kubesphere/pkg/apis/devops/v1alpha1 -h ./hack/boilerplate.go.txt --report-filename ./api/api-rules/violation_exceptions.list
R
runzexia 已提交
86
	go run ./tools/cmd/crd-doc-gen/main.go
J
jeff 已提交
87
# Build the docker image
H
hongming 已提交
88
docker-build: all
J
jeff 已提交
89 90 91
	docker build . -t ${IMG}

# Run tests
R
runzexia 已提交
92
test: fmt vet
93
	export KUBEBUILDER_CONTROLPLANE_START_TIMEOUT=1m; go test ./pkg/... ./cmd/... -covermode=atomic -coverprofile=coverage.txt
J
jeff 已提交
94 95 96 97 98

.PHONY: clean
clean:
	-make -C ./pkg/version clean
	@echo "ok"
99 100 101

# find or download controller-gen
# download controller-gen if necessary
M
magicsong 已提交
102
clientset: 
103
	./hack/generate_client.sh
R
runzexia 已提交
104 105 106 107 108 109 110 111 112


# Currently in the upgrade phase of controller tools.
# But the new controller tools are not compatible with the old version.
# With these commands you may need to manually modify the generated code
# So don't use it unless you know it very deeply
internal-crds:
	$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./pkg/apis/network/..." output:crd:artifacts:config=config/crd/bases

R
runzexia 已提交
113
internal-generate-apis: internal-controller-gen
M
magicsong 已提交
114
	$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/network/...
R
runzexia 已提交
115 116 117 118 119 120 121 122

internal-controller-gen:
ifeq (, $(shell which controller-gen))
	go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.0-beta.4
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
M
magicsong 已提交
123 124 125 126

network-rbac:
	$(CONTROLLER_GEN) paths=./pkg/controller/network/provider/ paths=./pkg/controller/network/ rbac:roleName=network-manager output:rbac:artifacts:config=kustomize/network/calico-k8s
	$(CONTROLLER_GEN) paths=./pkg/controller/network/ rbac:roleName=network-manager output:rbac:artifacts:config=kustomize/network/calico-etcd