Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (116 loc) · 5.77 KB
/
Copy pathMakefile
File metadata and controls
135 lines (116 loc) · 5.77 KB
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
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
ENVTEST ?= $(LOCALBIN)/setup-envtest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.36.0
ENVTEST_VERSION ?= release-0.24
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs
GCI ?= $(LOCALBIN)/gci
CONTROLLER_TOOLS_VERSION ?= v0.21.0
CRD_REF_DOCS_VERSION ?= v0.3.0
CHART_DIR ?= charts/qdrant-kubernetes-api
CRDS_DIR ?= crds
lint:
bash -c 'files=$$(gofmt -l .) && echo $$files && [ -z "$$files" ]'
helm lint $(CHART_DIR)
helm lint $(CHART_DIR) --set includeManagementCRDs=true
helm lint $(CHART_DIR) --set includeAuthCRDs=true
helm lint $(CHART_DIR) --set includeRoutingCRDs=true
helm lint $(CHART_DIR) --set includeQdrantClusterCRDs=false
helm lint $(CHART_DIR) --set includeManagementCRDs=true --set includeAuthCRDs=true --set includeRoutingCRDs=true
helm lint $(CHART_DIR)
golangci-lint run
.PHONY: gen
gen: manifests generate format vet ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
.PHONY: manifests
manifests: controller-gen ## Generate CustomResourceDefinition objects.
rm $(CHART_DIR)/templates/management-crds/*.yaml || true
rm $(CHART_DIR)/templates/region-crds/*.yaml || true
rm $(CHART_DIR)/templates/auth-crds/*.yaml || true
rm $(CHART_DIR)/templates/routing-crds/*.yaml || true
$(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=$(CRDS_DIR)
mv $(CRDS_DIR)/qdrant.io_qdrantreleases.yaml $(CHART_DIR)/templates/management-crds/
cp $(CRDS_DIR)/qdrant*.yaml $(CHART_DIR)/templates/region-crds/
mv $(CRDS_DIR)/auth.qdrant.io*.yaml $(CHART_DIR)/templates/auth-crds/
mv $(CRDS_DIR)/routing.qdrant.io*.yaml $(CHART_DIR)/templates/routing-crds/
for file in $(CHART_DIR)/templates/management-crds/*.yaml; do \
awk '{print} /^ annotations:/{print " helm.sh/resource-policy: keep"}' $$file > temp && mv temp $$file; \
echo "{{ if .Values.includeManagementCRDs }}" | cat - $$file > temp && mv temp $$file; \
echo "{{ end }}" >> $$file; \
done
for file in $(CHART_DIR)/templates/region-crds/qdrant*.yaml; do \
awk '{print} /^ annotations:/{print " helm.sh/resource-policy: keep"}' $$file > temp && mv temp $$file; \
case "$$(basename $$file)" in \
qdrant.io_qdrantclusters.yaml|qdrant.io_qdrantclusterrestores.yaml|qdrant.io_qdrantclustersnapshots.yaml|qdrant.io_qdrantclusterscheduledsnapshots.yaml) \
guard='{{ if and .Values.includeRegionCRDs .Values.includeQdrantClusterCRDs }}' ;; \
*) \
guard='{{ if .Values.includeRegionCRDs }}' ;; \
esac; \
echo "$$guard" | cat - $$file > temp && mv temp $$file; \
echo "{{ end }}" >> $$file; \
done
# We only want to deploy API key CRD to regional clusters
for file in $(CHART_DIR)/templates/auth-crds/auth.qdrant.io*.yaml; do \
awk '{print} /^ annotations:/{print " helm.sh/resource-policy: keep"}' $$file > temp && mv temp $$file; \
echo "{{ if .Values.includeAuthCRDs }}" | cat - $$file > temp && mv temp $$file; \
echo "{{ end }}" >> $$file; \
done
# We only want to deploy routing CRD to regional clusters
for file in $(CHART_DIR)/templates/routing-crds/routing.qdrant.io*.yaml; do \
awk '{print} /^ annotations:/{print " helm.sh/resource-policy: keep"}' $$file > temp && mv temp $$file; \
echo "{{ if .Values.includeRoutingCRDs }}" | cat - $$file > temp && mv temp $$file; \
echo "{{ end }}" >> $$file; \
done
helm lint $(CHART_DIR)
.PHONY: generate
generate: controller-gen crd-ref-docs ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(CRD_REF_DOCS) --config .crd-ref-docs.yaml --renderer markdown --output-path docs/api.md
.PHONY: controller-gen
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)
.PHONY: crd-ref-doc
crd-ref-docs: $(CRD_REF_DOCS) ## Download crd-ref-doc locally if necessary. If wrong version is installed, it will be overwritten.
$(CRD_REF_DOCS): $(LOCALBIN)
test -s $(LOCALBIN)/crd-ref-docs && $(LOCALBIN)/crd-ref-docs --version | grep -q $(CRD_REF_DOCS_VERSION) || \
GOBIN=$(LOCALBIN) go install github.com/elastic/crd-ref-docs@$(CRD_REF_DOCS_VERSION)
.PHONY: go_fmt
go_fmt:
gofmt -w -s .
.PHONY: fmt_imports
fmt_imports: $(GCI)
$(GCI) write ./ --skip-generated -s standard -s default -s 'prefix(github.com/qdrant)'
.PHONY: fmt
format: go_fmt fmt_imports
fmt: format
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
$(GCI): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/daixiang0/gci@latest
.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef