Skip to content

Commit 541c21c

Browse files
committed
Add fmt/lint, store json in generated/ dir, rely on default version
Signed-off-by: Saswata Mukherjee <[email protected]>
1 parent 5297eec commit 541c21c

28 files changed

+176
-49
lines changed

Makefile

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,33 @@ checkunused:
131131
##@ Development
132132

133133
.PHONY: manifests
134-
manifests: controller-gen gojsontoyaml ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
134+
manifests: controller-gen gojsontoyaml ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. Also generates json, for jsonnet lib.
135135
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:ignoreUnexportedFields=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases
136136
find config/crd/bases -name '*.yaml' ! -name 'kustomization.yaml' -exec sh -c '\
137137
for file do \
138138
filename=$$(basename "$$file" .yaml); \
139-
out_file="$$(pwd)/jsonnet/$${filename}-crd.json"; \
140-
gojsontoyaml -yamltojson < "$$file" | jq > "$$out_file"; \
139+
out_file="$$(pwd)/jsonnet/generated/$${filename}-crd.json"; \
140+
$(GOJSONTOYAML_BINARY) -yamltojson < "$$file" | jq > "$$out_file"; \
141141
done' sh {} +
142142
find config/rbac -name '*.yaml' ! -name 'kustomization.yaml' -exec sh -c '\
143143
for file do \
144144
filename=$$(basename "$$file" .yaml); \
145-
out_file="$$(pwd)/jsonnet/$${filename}.json"; \
146-
gojsontoyaml -yamltojson < "$$file" | jq > "$$out_file"; \
145+
out_file="$$(pwd)/jsonnet/generated/$${filename}.json"; \
146+
$(GOJSONTOYAML_BINARY) -yamltojson < "$$file" | jq > "$$out_file"; \
147147
done' sh {} +
148148
find config/manager -name '*.yaml' ! -name 'kustomization.yaml' -exec sh -c '\
149149
for file do \
150150
filename=$$(basename "$$file" .yaml); \
151-
out_file="$$(pwd)/jsonnet/$${filename}.json"; \
152-
gojsontoyaml -yamltojson < "$$file" | jq > "$$out_file"; \
151+
out_file="$$(pwd)/jsonnet/generated/$${filename}.json"; \
152+
$(GOJSONTOYAML_BINARY) -yamltojson < "$$file" | jq > "$$out_file"; \
153153
done' sh {} +
154154
find config/prometheus -name '*.yaml' ! -name 'kustomization.yaml' -exec sh -c '\
155155
for file do \
156156
filename=$$(basename "$$file" .yaml); \
157-
out_file="$$(pwd)/jsonnet/$${filename}.json"; \
158-
gojsontoyaml -yamltojson < "$$file" | jq > "$$out_file"; \
157+
out_file="$$(pwd)/jsonnet/generated/$${filename}.json"; \
158+
$(GOJSONTOYAML_BINARY) -yamltojson < "$$file" | jq > "$$out_file"; \
159159
done' sh {} +
160+
$(MAKE) jsonnet-resources
160161

161162
.PHONY: jsonnet-resources
162163
jsonnet-resources: jsonnet gojsontoyaml
@@ -165,12 +166,19 @@ jsonnet-resources: jsonnet gojsontoyaml
165166
$(JSONNET_BINARY) -m jsonnet/examples jsonnet/example.jsonnet | $(XARGS) -I{} sh -c 'cat {} | $(GOJSONTOYAML_BINARY) > {}.yaml' -- {}
166167
find jsonnet/examples -type f -not -name "*.*" -delete
167168

169+
JSONNET_SRC = $(shell find . -type f -not -path './*vendor_jsonnet/*' \( -name '*.libsonnet' -o -name '*.jsonnet' \))
170+
171+
.PHONY: jsonnet-format
172+
jsonnet-format: $(JSONNET_SRC) jsonnetfmt
173+
@echo ">>>>> Running format"
174+
$(JSONNETFMT_BINARY) -n 2 --max-blank-lines 2 --string-style s --comment-style s -i $(JSONNET_SRC)
175+
168176
.PHONY: generate
169177
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
170178
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
171179

172180
.PHONY: fmt
173-
fmt: ## Run go fmt against code.
181+
fmt: jsonnet-format ## Run go fmt against code.
174182
go fmt ./...
175183

176184
.PHONY: vet
@@ -181,8 +189,13 @@ vet: ## Run go vet against code.
181189
test: manifests generate fmt vet envtest ## Run tests.
182190
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell go list ./...) -v -ginkgo.v -coverprofile cover.out
183191

192+
.PHONY: lint-jsonnet
193+
lint-jsonnet: $(JSONNETLINT_BINARY)
194+
@echo ">>>>> Running linter"
195+
echo ${JSONNET_SRC} | $(XARGS) -n 1 -- $(JSONNETLINT_BINARY)
196+
184197
.PHONY: lint
185-
lint: ## Run linting.
198+
lint: lint-jsonnet ## Run linting.
186199
golangci-lint run
187200

188201
##@ Build
@@ -267,12 +280,16 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
267280
GOJSONTOYAML_BINARY ?= $(LOCALBIN)/gojsontoyaml
268281
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
269282
JSONNET_BINARY ?= $(LOCALBIN)/jsonnet
283+
JSONNETFMT_BINARY ?= $(LOCALBIN)/jsonnetfmt
284+
JSONNETLINT_BINARY ?= $(LOCALBIN)/jsonnet-lint
270285

271286
## Tool Versions
272287
KUSTOMIZE_VERSION ?= v3.8.7
273288
CONTROLLER_TOOLS_VERSION ?= v0.16.0
274289
GOJSONTOYAML_VERSION ?= v0.1.0
275-
JSONNET_VERSION ?= v0.19.1
290+
JSONNET_VERSION ?= v0.21.0
291+
JSONNETFMT_VERSION ?= v0.21.0
292+
JSONNETLINT_VERSION ?= v0.21.0
276293
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
277294
.PHONY: kustomize
278295
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
@@ -301,6 +318,18 @@ $(JSONNET_BINARY): $(LOCALBIN)
301318
test -s $(LOCALBIN)/jsonnet && $(LOCALBIN)/jsonnet --version | grep -q $(JSONNET_VERSION) || \
302319
GOBIN=$(LOCALBIN) go install github.com/google/go-jsonnet/cmd/jsonnet@$(JSONNET_VERSION)
303320

321+
.PHONY: jsonnetfmt
322+
jsonnetfmt: $(JSONNETFMT_BINARY) ## Download jsonnetfmt locally if necessary. If wrong version is installed, it will be overwritten.
323+
$(JSONNETFMT_BINARY): $(LOCALBIN)
324+
test -s $(LOCALBIN)/jsonnetfmt && $(LOCALBIN)/jsonnetfmt --version | grep -q $(JSONNETFMT_VERSION) || \
325+
GOBIN=$(LOCALBIN) go install github.com/google/go-jsonnet/cmd/jsonnetfmt@$(JSONNETFMT_VERSION)
326+
327+
.PHONY: jsonnet-lint
328+
jsonnet-lint: $(JSONNETLINT_BINARY) ## Download jsonnetlint locally if necessary. If wrong version is installed, it will be overwritten.
329+
$(JSONNETLINT_BINARY): $(LOCALBIN)
330+
test -s $(LOCALBIN)/jsonnet-lint && $(LOCALBIN)/jsonnet-lint --version | grep -q $(JSONNETLINT_VERSION) || \
331+
GOBIN=$(LOCALBIN) go install github.com/google/go-jsonnet/cmd/jsonnet-lint@$(JSONNETLINT_VERSION)
332+
304333
.PHONY: envtest
305334
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
306335
$(ENVTEST): $(LOCALBIN)

jsonnet/example.jsonnet

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ local persesOperator = import 'perses-operator.libsonnet';
33
// Define the configuration for the perses operator
44
local config = {
55
namespace: 'perses-dev',
6-
image: 'persesdev/perses-operator:v1.0.0',
76
resources: {
87
limits: { cpu: '500m', memory: '128Mi' },
98
requests: { cpu: '10m', memory: '64Mi' },
109
},
1110
};
1211

1312
// Generate all manifests
14-
persesOperator(config)
13+
persesOperator(config)

jsonnet/examples/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ spec:
4545
containers:
4646
- args:
4747
- --leader-elect
48-
image: persesdev/perses-operator:v1.0.0
48+
image: persesdev/perses-operator:v0.1.10
4949
imagePullPolicy: Always
5050
livenessProbe:
5151
httpGet:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
labels:
5+
app.kubernetes.io/component: rbac
6+
app.kubernetes.io/created-by: perses-operator
7+
app.kubernetes.io/instance: leader-election-role
8+
app.kubernetes.io/name: perses-operator
9+
app.kubernetes.io/part-of: perses-operator
10+
app.kubernetes.io/version: 0.1.10
11+
name: perses-operator-leader-election-role
12+
namespace: perses-dev
13+
rules:
14+
- apiGroups:
15+
- ""
16+
resources:
17+
- configmaps
18+
verbs:
19+
- get
20+
- list
21+
- watch
22+
- create
23+
- update
24+
- patch
25+
- delete
26+
- apiGroups:
27+
- coordination.k8s.io
28+
resources:
29+
- leases
30+
verbs:
31+
- get
32+
- list
33+
- watch
34+
- create
35+
- update
36+
- patch
37+
- delete
38+
- apiGroups:
39+
- ""
40+
resources:
41+
- events
42+
verbs:
43+
- create
44+
- patch
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
labels:
5+
app.kubernetes.io/component: rbac
6+
app.kubernetes.io/created-by: perses-operator
7+
app.kubernetes.io/instance: leader-election-rolebinding
8+
app.kubernetes.io/name: perses-operator
9+
app.kubernetes.io/part-of: perses-operator
10+
app.kubernetes.io/version: 0.1.10
11+
name: perses-operator-leader-election-rolebinding
12+
namespace: perses-dev
13+
roleRef:
14+
apiGroup: rbac.authorization.k8s.io
15+
kind: Role
16+
name: perses-operator-leader-election-role
17+
subjects:
18+
- kind: ServiceAccount
19+
name: perses-operator
20+
namespace: perses-dev

jsonnet/examples/roleBinding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ roleRef:
1616
subjects:
1717
- kind: ServiceAccount
1818
name: perses-operator
19-
namespace: system
19+
namespace: perses-dev
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)