@@ -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
162163jsonnet-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
169177generate : 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.
181189test : 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
267280GOJSONTOYAML_BINARY ?= $(LOCALBIN ) /gojsontoyaml
268281ENVTEST ?= $(LOCALBIN ) /setup-envtest-$(ENVTEST_VERSION )
269282JSONNET_BINARY ?= $(LOCALBIN ) /jsonnet
283+ JSONNETFMT_BINARY ?= $(LOCALBIN ) /jsonnetfmt
284+ JSONNETLINT_BINARY ?= $(LOCALBIN ) /jsonnet-lint
270285
271286# # Tool Versions
272287KUSTOMIZE_VERSION ?= v3.8.7
273288CONTROLLER_TOOLS_VERSION ?= v0.16.0
274289GOJSONTOYAML_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
276293KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
277294.PHONY : kustomize
278295kustomize : $(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
305334envtest : $(ENVTEST ) # # Download setup-envtest locally if necessary.
306335$(ENVTEST ) : $(LOCALBIN )
0 commit comments