-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (104 loc) · 4.81 KB
/
Copy pathMakefile
File metadata and controls
132 lines (104 loc) · 4.81 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
# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/pyrra-dev/pyrra:main
# 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
gojsontoyaml:
ifeq (, $(shell which gojsontoyaml))
go install github.com/brancz/gojsontoyaml@latest
GOJSONTOYAML=$(GOBIN)/gojsontoyaml
else
GOJSONTOYAML=$(shell which gojsontoyaml)
endif
gofumpt:
ifeq (, $(shell which gofumpt))
go install mvdan.cc/gofumpt@latest
GOFUMPT=$(GOBIN)/gofumpt
else
GOFUMPT=$(shell which gofumpt)
endif
all: ui/build build lint
.PHONY: install
install: ui/node_modules
clean:
rm -rf ui/build ui/node_modules
# Run tests
test: generate fmt vet
go test -race ./... -coverprofile cover.out
build: pyrra
# Build api binary
pyrra: fmt vet
CGO_ENABLED=0 go build -v -ldflags '-w -extldflags "-static" -X main.version=$(shell git describe --tags --always --dirty) -X main.commit=$(shell git rev-parse HEAD)' -o pyrra
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
kubectl apply -f ./config/api.yaml
kubectl apply -f ./config/rbac/role.yaml -n monitoring
kubectl apply -f ./config/kubernetes.yaml
# Run code linters
lint: fmt vet
# Run gofumpt against code
fmt: gofumpt
$(GOFUMPT) -w .
# Run go vet against code
vet:
go vet ./...
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: generate
generate: controller-gen gojsontoyaml ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) object:headerFile="kubernetes/hack/boilerplate.go.txt" crd rbac:roleName="pyrra-kubernetes" webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# config/crd/bases holds the canonical CRD YAML (stable path for consumers). Derive the
# JSON consumed by the jsonnet pipeline from it
find config/crd/bases -name '*.yaml' -print0 | xargs -0 -I{} sh -c '$(GOJSONTOYAML) -yamltojson < "$$1" | jq > "$(PWD)/jsonnet/controller-gen/$$(basename -s .yaml $$1).json"' -- {}
# Generate Go and TypeScript code from the protobuf definitions.
# Plugin versions are pinned in buf.gen.yaml; run this after editing any .proto.
.PHONY: proto
proto: buf
$(BUF) generate proto
docker-build:
docker build . -t ${IMG}
docker-push:
docker push ${IMG}
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
# renovate: datasource=go depName=sigs.k8s.io/controller-tools
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.21.0
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
# find or download buf
buf:
ifeq (, $(shell which buf))
# renovate: datasource=github-releases depName=bufbuild/buf
go install github.com/bufbuild/buf/cmd/buf@v1.72.0
BUF=$(GOBIN)/buf
else
BUF=$(shell which buf)
endif
ui: ui/node_modules ui/build
ui/node_modules:
cd ui && npm install
ui/build:
cd ui && npm run build
examples: examples/kubernetes/manifests examples/kubernetes/manifests-webhook examples/kubernetes-namespaced/manifests examples/openshift/manifests
examples/kubernetes/manifests: examples/kubernetes/main.jsonnet jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json jsonnet/pyrra/kubernetes.libsonnet
jsonnetfmt -i examples/kubernetes/main.jsonnet
jsonnet -m examples/kubernetes/manifests examples/kubernetes/main.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml' -- {}
find examples/kubernetes/manifests -type f ! -name '*.yaml' -delete
examples/kubernetes-namespaced/manifests: examples/kubernetes-namespaced/main.jsonnet jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json jsonnet/pyrra/kubernetes.libsonnet
jsonnetfmt -i examples/kubernetes-namespaced/main.jsonnet
jsonnet -m examples/kubernetes-namespaced/manifests examples/kubernetes-namespaced/main.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml' -- {}
find examples/kubernetes-namespaced/manifests -type f ! -name '*.yaml' -delete
examples/kubernetes/manifests-webhook: examples/kubernetes/main-webhook.jsonnet jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json jsonnet/pyrra/kubernetes.libsonnet
jsonnetfmt -i examples/kubernetes/main-webhook.jsonnet
jsonnet -m examples/kubernetes/manifests-webhook examples/kubernetes/main-webhook.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml' -- {}
find examples/kubernetes/manifests-webhook -type f ! -name '*.yaml' -delete
examples/openshift/manifests: examples/openshift/main.jsonnet jsonnet/controller-gen/pyrra.dev_servicelevelobjectives.json jsonnet/pyrra/kubernetes.libsonnet
jsonnetfmt -i examples/openshift/main.jsonnet
jsonnet -m examples/openshift/manifests examples/openshift/main.jsonnet | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml' -- {}
find examples/openshift/manifests -type f ! -name '*.yaml' -delete