From ca057722e501f93ce9e8b36561d8fb8ef020fd4c Mon Sep 17 00:00:00 2001 From: Frederic Branczyk <fbranczyk@gmail.com> Date: Fri, 18 May 2018 12:04:33 +0200 Subject: [PATCH] Add formatting jsonnet to generate make target --- Makefile | 10 +++++-- README.md | 30 ++++++++++---------- examples/jsonnet-snippets/bootkube.jsonnet | 4 +-- examples/jsonnet-snippets/kubeadm.jsonnet | 4 +-- examples/jsonnet-snippets/node-ports.jsonnet | 4 +-- examples/prometheus-name-override.jsonnet | 18 ++++++------ 6 files changed, 38 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index baae1e20..60c6d5f3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +JSONNET_FMT := jsonnet fmt -n 2 --max-blank-lines 2 --string-style s --comment-style s + image: docker build -f ../../scripts/jsonnet/Dockerfile -t po-jsonnet ../../ @@ -11,10 +13,14 @@ crdtojsonnet: cat ../../example/prometheus-operator-crd/servicemonitor.crd.yaml | gojsontoyaml -yamltojson > jsonnet/kube-prometheus/prometheus-operator/servicemonitor-crd.libsonnet cat ../../example/prometheus-operator-crd/rulefile.crd.yaml | gojsontoyaml -yamltojson > jsonnet/kube-prometheus/prometheus-operator/rulefile-crd.libsonnet -generate-raw: crdtojsonnet +generate-raw: crdtojsonnet fmt jb install ./build.sh +fmt: + find . -name 'vendor' -prune -o -name '*.libsonnet' -o -name '*.jsonnet' -print | \ + xargs -n 1 -- $(JSONNET_FMT) -i + test: image @echo ">> Compiling assets and generating Kubernetes manifests" docker run --rm -u=$(shell id -u $(USER)):$(shell id -g $(USER)) -v $(shell dirname $(dir $(abspath $(dir $$PWD)))):/go/src/github.com/coreos/prometheus-operator/ --workdir /go/src/github.com/coreos/prometheus-operator/contrib/kube-prometheus po-jsonnet make test-raw @@ -23,4 +29,4 @@ test-raw: crdtojsonnet jb install ./test.sh -.PHONY: image generate crdtojsonnet generate-raw test +.PHONY: image generate crdtojsonnet generate-raw test test-raw fmt diff --git a/README.md b/README.md index d67ea680..cc392e7a 100644 --- a/README.md +++ b/README.md @@ -151,16 +151,16 @@ kubeadm: [embedmd]:# (examples/jsonnet-snippets/kubeadm.jsonnet) ```jsonnet -(import "kube-prometheus/kube-prometheus.libsonnet") + -(import "kube-prometheus/kube-prometheus-kubeadm.libsonnet") +(import 'kube-prometheus/kube-prometheus.libsonnet') + +(import 'kube-prometheus/kube-prometheus-kubeadm.libsonnet') ``` bootkube: [embedmd]:# (examples/jsonnet-snippets/bootkube.jsonnet) ```jsonnet -(import "kube-prometheus/kube-prometheus.libsonnet") + -(import "kube-prometheus/kube-prometheus-bootkube.libsonnet") +(import 'kube-prometheus/kube-prometheus.libsonnet') + +(import 'kube-prometheus/kube-prometheus-bootkube.libsonnet') ``` kops: @@ -175,23 +175,23 @@ Another mixin that may be useful for exploring the stack is to expose the UIs of [embedmd]:# (examples/jsonnet-snippets/node-ports.jsonnet) ```jsonnet -(import "kube-prometheus/kube-prometheus.libsonnet") + -(import "kube-prometheus/kube-prometheus-node-ports.libsonnet") +(import 'kube-prometheus/kube-prometheus.libsonnet') + +(import 'kube-prometheus/kube-prometheus-node-ports.libsonnet') ``` For example the name of the `Prometheus` object provided by this library can be overridden: [embedmd]:# (examples/prometheus-name-override.jsonnet) ```jsonnet -((import "kube-prometheus/kube-prometheus.libsonnet") + { - prometheus+: { - prometheus+: { - metadata+: { - name: "my-name", - } - } - } -}).prometheus.prometheus +((import 'kube-prometheus/kube-prometheus.libsonnet') + { + prometheus+: { + prometheus+: { + metadata+: { + name: 'my-name', + }, + }, + }, + }).prometheus.prometheus ``` Standard Kubernetes manifests are all written using [ksonnet-lib](https://github.com/ksonnet/ksonnet-lib/), so they can be modified with the mixins supplied by ksonnet-lib. For example to override the namespace of the node-exporter DaemonSet: diff --git a/examples/jsonnet-snippets/bootkube.jsonnet b/examples/jsonnet-snippets/bootkube.jsonnet index 89a7eb7b..f7386a01 100644 --- a/examples/jsonnet-snippets/bootkube.jsonnet +++ b/examples/jsonnet-snippets/bootkube.jsonnet @@ -1,2 +1,2 @@ -(import "kube-prometheus/kube-prometheus.libsonnet") + -(import "kube-prometheus/kube-prometheus-bootkube.libsonnet") +(import 'kube-prometheus/kube-prometheus.libsonnet') + +(import 'kube-prometheus/kube-prometheus-bootkube.libsonnet') diff --git a/examples/jsonnet-snippets/kubeadm.jsonnet b/examples/jsonnet-snippets/kubeadm.jsonnet index 591809eb..a7837163 100644 --- a/examples/jsonnet-snippets/kubeadm.jsonnet +++ b/examples/jsonnet-snippets/kubeadm.jsonnet @@ -1,2 +1,2 @@ -(import "kube-prometheus/kube-prometheus.libsonnet") + -(import "kube-prometheus/kube-prometheus-kubeadm.libsonnet") +(import 'kube-prometheus/kube-prometheus.libsonnet') + +(import 'kube-prometheus/kube-prometheus-kubeadm.libsonnet') diff --git a/examples/jsonnet-snippets/node-ports.jsonnet b/examples/jsonnet-snippets/node-ports.jsonnet index 68731676..c02f1ae7 100644 --- a/examples/jsonnet-snippets/node-ports.jsonnet +++ b/examples/jsonnet-snippets/node-ports.jsonnet @@ -1,2 +1,2 @@ -(import "kube-prometheus/kube-prometheus.libsonnet") + -(import "kube-prometheus/kube-prometheus-node-ports.libsonnet") +(import 'kube-prometheus/kube-prometheus.libsonnet') + +(import 'kube-prometheus/kube-prometheus-node-ports.libsonnet') diff --git a/examples/prometheus-name-override.jsonnet b/examples/prometheus-name-override.jsonnet index d6410fd8..86218012 100644 --- a/examples/prometheus-name-override.jsonnet +++ b/examples/prometheus-name-override.jsonnet @@ -1,9 +1,9 @@ -((import "kube-prometheus/kube-prometheus.libsonnet") + { - prometheus+: { - prometheus+: { - metadata+: { - name: "my-name", - } - } - } -}).prometheus.prometheus +((import 'kube-prometheus/kube-prometheus.libsonnet') + { + prometheus+: { + prometheus+: { + metadata+: { + name: 'my-name', + }, + }, + }, + }).prometheus.prometheus -- GitLab