Skip to content

Commit

Permalink
Merge pull request thanos-io#177 from kakkoyun/jsonnet_linter
Browse files Browse the repository at this point in the history
Add jsonnet linter
  • Loading branch information
kakkoyun authored Jan 12, 2021
2 parents b50112c + 28bcc0d commit f1118ca
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 58 deletions.
28 changes: 17 additions & 11 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.2. DO NOT EDIT.
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.3. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
GOPATH ?= $(shell go env GOPATH)
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
Expand All @@ -20,35 +20,41 @@ EMBEDMD := $(GOBIN)/embedmd-v1.0.0
$(EMBEDMD): .bingo/embedmd.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/embedmd-v1.0.0"
@cd .bingo && $(GO) build -modfile=embedmd.mod -o=$(GOBIN)/embedmd-v1.0.0 "github.com/campoy/embedmd"
@cd .bingo && $(GO) build -mod=mod -modfile=embedmd.mod -o=$(GOBIN)/embedmd-v1.0.0 "github.com/campoy/embedmd"

GOJSONTOYAML := $(GOBIN)/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c
$(GOJSONTOYAML): .bingo/gojsontoyaml.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c"
@cd .bingo && $(GO) build -modfile=gojsontoyaml.mod -o=$(GOBIN)/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c "github.com/brancz/gojsontoyaml"
@cd .bingo && $(GO) build -mod=mod -modfile=gojsontoyaml.mod -o=$(GOBIN)/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c "github.com/brancz/gojsontoyaml"

JB := $(GOBIN)/jb-v0.4.0
$(JB): .bingo/jb.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/jb-v0.4.0"
@cd .bingo && $(GO) build -modfile=jb.mod -o=$(GOBIN)/jb-v0.4.0 "github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb"
@cd .bingo && $(GO) build -mod=mod -modfile=jb.mod -o=$(GOBIN)/jb-v0.4.0 "github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb"

JSONNET := $(GOBIN)/jsonnet-v0.16.0
JSONNET_LINT := $(GOBIN)/jsonnet-lint-v0.17.1-0.20210101181740-31d71aaccda6
$(JSONNET_LINT): .bingo/jsonnet-lint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/jsonnet-lint-v0.17.1-0.20210101181740-31d71aaccda6"
@cd .bingo && $(GO) build -mod=mod -modfile=jsonnet-lint.mod -o=$(GOBIN)/jsonnet-lint-v0.17.1-0.20210101181740-31d71aaccda6 "github.com/google/go-jsonnet/cmd/jsonnet-lint"

JSONNET := $(GOBIN)/jsonnet-v0.17.1-0.20210101181740-31d71aaccda6
$(JSONNET): .bingo/jsonnet.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/jsonnet-v0.16.0"
@cd .bingo && $(GO) build -modfile=jsonnet.mod -o=$(GOBIN)/jsonnet-v0.16.0 "github.com/google/go-jsonnet/cmd/jsonnet"
@echo "(re)installing $(GOBIN)/jsonnet-v0.17.1-0.20210101181740-31d71aaccda6"
@cd .bingo && $(GO) build -mod=mod -modfile=jsonnet.mod -o=$(GOBIN)/jsonnet-v0.17.1-0.20210101181740-31d71aaccda6 "github.com/google/go-jsonnet/cmd/jsonnet"

JSONNETFMT := $(GOBIN)/jsonnetfmt-v0.16.0
JSONNETFMT := $(GOBIN)/jsonnetfmt-v0.17.1-0.20210101181740-31d71aaccda6
$(JSONNETFMT): .bingo/jsonnetfmt.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/jsonnetfmt-v0.16.0"
@cd .bingo && $(GO) build -modfile=jsonnetfmt.mod -o=$(GOBIN)/jsonnetfmt-v0.16.0 "github.com/google/go-jsonnet/cmd/jsonnetfmt"
@echo "(re)installing $(GOBIN)/jsonnetfmt-v0.17.1-0.20210101181740-31d71aaccda6"
@cd .bingo && $(GO) build -mod=mod -modfile=jsonnetfmt.mod -o=$(GOBIN)/jsonnetfmt-v0.17.1-0.20210101181740-31d71aaccda6 "github.com/google/go-jsonnet/cmd/jsonnetfmt"

KUBEVAL := $(GOBIN)/kubeval-v0.0.0-20201005082916-38668c6c5b23
$(KUBEVAL): .bingo/kubeval.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/kubeval-v0.0.0-20201005082916-38668c6c5b23"
@cd .bingo && $(GO) build -modfile=kubeval.mod -o=$(GOBIN)/kubeval-v0.0.0-20201005082916-38668c6c5b23 "github.com/instrumenta/kubeval"
@cd .bingo && $(GO) build -mod=mod -modfile=kubeval.mod -o=$(GOBIN)/kubeval-v0.0.0-20201005082916-38668c6c5b23 "github.com/instrumenta/kubeval"

9 changes: 9 additions & 0 deletions .bingo/jsonnet-lint.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require (
github.com/fatih/color v1.10.0 // indirect
github.com/google/go-jsonnet v0.17.1-0.20210101181740-31d71aaccda6 // cmd/jsonnet-lint
golang.org/x/sys v0.0.0-20210112091331-59c308dcf3cc // indirect
)
6 changes: 5 additions & 1 deletion .bingo/jsonnet.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require github.com/google/go-jsonnet v0.16.0 // cmd/jsonnet
require (
github.com/fatih/color v1.10.0 // indirect
github.com/google/go-jsonnet v0.17.1-0.20210101181740-31d71aaccda6 // cmd/jsonnet
golang.org/x/sys v0.0.0-20210112091331-59c308dcf3cc // indirect
)
6 changes: 5 additions & 1 deletion .bingo/jsonnetfmt.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require github.com/google/go-jsonnet v0.16.0 // cmd/jsonnetfmt
require (
github.com/fatih/color v1.10.0 // indirect
github.com/google/go-jsonnet v0.17.1-0.20210101181740-31d71aaccda6 // cmd/jsonnetfmt
golang.org/x/sys v0.0.0-20210112091331-59c308dcf3cc // indirect
)
22 changes: 12 additions & 10 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.2. DO NOT EDIT.
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.2.3. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
local gobin=$(go env GOBIN)
GOBIN=${GOBIN:=$(go env GOBIN)}

if [ -z "$gobin" ]; then
gobin="$(go env GOPATH)/bin"
if [ -z "$GOBIN" ]; then
GOBIN="$(go env GOPATH)/bin"
fi


EMBEDMD="${gobin}/embedmd-v1.0.0"
EMBEDMD="$GOBIN/embedmd-v1.0.0"

GOJSONTOYAML="${gobin}/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c"
GOJSONTOYAML="$GOBIN/gojsontoyaml-v0.0.0-20200602132005-3697ded27e8c"

JB="${gobin}/jb-v0.4.0"
JB="$GOBIN/jb-v0.4.0"

JSONNET="${gobin}/jsonnet-v0.16.0"
JSONNET_LINT="$GOBIN/jsonnet-lint-v0.17.1-0.20210101181740-31d71aaccda6"

JSONNETFMT="${gobin}/jsonnetfmt-v0.16.0"
JSONNET="$GOBIN/jsonnet-v0.17.1-0.20210101181740-31d71aaccda6"

KUBEVAL="${gobin}/kubeval-v0.0.0-20201005082916-38668c6c5b23"
JSONNETFMT="$GOBIN/jsonnetfmt-v0.17.1-0.20210101181740-31d71aaccda6"

KUBEVAL="$GOBIN/kubeval-v0.0.0-20201005082916-38668c6c5b23"

13 changes: 12 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
jobs:
lint:
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
docker:
- image: circleci/golang:1.15
steps:
- checkout
- run: make vendor
- run: git diff --exit-code
- run: make --always-make fmt lint
- run: git diff --exit-code
build:
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
docker:
- image: quay.io/coreos/jsonnet-ci
- image: circleci/golang:1.15
steps:
- checkout
- run: make --always-make vendor generate validate
Expand All @@ -11,4 +21,5 @@ workflows:
version: 2
build_and_test:
jobs:
- lint
- build
26 changes: 8 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
all: fmt generate validate

include .bingo/Variables.mk

FIRST_GOPATH := $(firstword $(subst :, ,$(shell go env GOPATH)))
JSONNET_SRC = $(shell find . -name 'vendor' -prune -o -name 'jsonnet/vendor' -prune -o -name 'tmp' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print)
JSONNETFMT_CMD := $(JSONNETFMT) -n 2 --max-blank-lines 2 --string-style s --comment-style s

CONTAINER_CMD:=docker run --rm \
-u="$(shell id -u):$(shell id -g)" \
-v "$(shell go env GOCACHE):/.cache/go-build" \
-v "$(PWD):/go/src/github.com/thanos-io/kube-thanos:Z" \
-w "/go/src/github.com/thanos-io/kube-thanos" \
-e USER=deadbeef \
-e GO111MODULE=on \
quay.io/coreos/jsonnet-ci

EXAMPLES := examples
MANIFESTS := manifests


.PHONY: generate-in-docker
generate-in-docker:
@echo ">> Compiling assets and generating Kubernetes manifests"
$(CONTAINER_CMD) make $(MFLAGS) generate
all: fmt generate validate

.PHONY: generate
generate: vendor ${MANIFESTS} **.md
Expand All @@ -33,11 +19,15 @@ generate: vendor ${MANIFESTS} **.md
${MANIFESTS}: $(JSONNET) $(GOJSONTOYAML) vendor example.jsonnet build.sh
@rm -rf ${MANIFESTS}
@mkdir -p ${MANIFESTS}
PATH=$$PATH:$$(pwd)/$(BIN_DIR) ./build.sh
JSONNET=$(JSONNET) GOJSONTOYAML=$(GOJSONTOYAML) ./build.sh

.PHONY: fmt
fmt: $(JSONNETFMT)
PATH=$$PATH:$$(pwd)/$(BIN_DIR) echo ${JSONNET_SRC} | xargs -n 1 -- $(JSONNETFMT_CMD) -i
echo ${JSONNET_SRC} | xargs -n 1 -- $(JSONNETFMT_CMD) -i

.PHONY: lint
lint: $(JSONNET_LINT) vendor
echo ${JSONNET_SRC} | xargs -n 1 -- $(JSONNET_LINT) -J vendor

.PHONY: vendor
vendor: | $(JB) jsonnetfile.json jsonnetfile.lock.json
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,24 @@ set -x
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail

JSONNET=${JSONNET:-jsonnet}
GOJSONTOYAML=${GOJSONTOYAML:-gojsontoyaml}

# Make sure to start with a clean 'manifests' dir
rm -rf manifests
mkdir manifests

# optional, but we would like to generate yaml, not json
jsonnet -J vendor -m manifests "${1-example.jsonnet}" | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}
${JSONNET} -J vendor -m manifests "${1-example.jsonnet}" | xargs -I{} sh -c "cat {} | ${GOJSONTOYAML} > {}.yaml; rm -f {}" -- {}
find manifests -type f ! -name '*.yaml' -delete

# The following script generates all components, mostly used for testing

rm -rf examples/all/manifests
mkdir examples/all/manifests

jsonnet -J vendor -m examples/all/manifests "${1-all.jsonnet}" | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}
${JSONNET} -J vendor -m examples/all/manifests "${1-all.jsonnet}" | xargs -I{} sh -c "cat {} | ${GOJSONTOYAML} > {}.yaml; rm -f {}" -- {}
find examples/all/manifests -type f ! -name '*.yaml' -delete
```

> Note you need `jsonnet` (`go get github.com/google/go-jsonnet/cmd/jsonnet`) and `gojsontoyaml` (`go get github.com/brancz/gojsontoyaml`) installed to run `build.sh`. If you just want json output, not yaml, then you can skip the pipe and everything afterwards.
Expand Down
9 changes: 7 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ set -x
# only exit with zero if all commands of the pipeline exit successfully
set -o pipefail

JSONNET=${JSONNET:-jsonnet}
GOJSONTOYAML=${GOJSONTOYAML:-gojsontoyaml}

# Make sure to start with a clean 'manifests' dir
rm -rf manifests
mkdir manifests

# optional, but we would like to generate yaml, not json
jsonnet -J vendor -m manifests "${1-example.jsonnet}" | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}
${JSONNET} -J vendor -m manifests "${1-example.jsonnet}" | xargs -I{} sh -c "cat {} | ${GOJSONTOYAML} > {}.yaml; rm -f {}" -- {}
find manifests -type f ! -name '*.yaml' -delete

# The following script generates all components, mostly used for testing

rm -rf examples/all/manifests
mkdir examples/all/manifests

jsonnet -J vendor -m examples/all/manifests "${1-all.jsonnet}" | xargs -I{} sh -c 'cat {} | gojsontoyaml > {}.yaml; rm -f {}' -- {}
${JSONNET} -J vendor -m examples/all/manifests "${1-all.jsonnet}" | xargs -I{} sh -c "cat {} | ${GOJSONTOYAML} > {}.yaml; rm -f {}" -- {}
find examples/all/manifests -type f ! -name '*.yaml' -delete
6 changes: 3 additions & 3 deletions examples/thanos-receive.jsonnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local t = import 'kube-thanos/kube-thanos-receive.libsonnet';
local receive = import 'kube-thanos/kube-thanos-receive.libsonnet';

t.receive {
receive({
local tr = self,
name:: 'thanos-receive',
namespace:: 'observability',
Expand All @@ -15,4 +15,4 @@ t.receive {
pvcTemplate+:: {
size: '50G',
},
}
})
2 changes: 1 addition & 1 deletion jsonnet/kube-thanos/kube-thanos-bucket.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local defaults = {
podLabelSelector:: {
[labelName]: defaults.commonLabels[labelName]
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
if labelName != 'app.kubernetes.io/version'
},
};

Expand Down
2 changes: 1 addition & 1 deletion jsonnet/kube-thanos/kube-thanos-compact.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local defaults = {
podLabelSelector:: {
[labelName]: defaults.commonLabels[labelName]
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
if labelName != 'app.kubernetes.io/version'
},
};

Expand Down
2 changes: 1 addition & 1 deletion jsonnet/kube-thanos/kube-thanos-query-frontend.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ local defaults = {
podLabelSelector:: {
[labelName]: defaults.commonLabels[labelName]
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
if labelName != 'app.kubernetes.io/version'
},
};

Expand Down
2 changes: 1 addition & 1 deletion jsonnet/kube-thanos/kube-thanos-query.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local defaults = {
podLabelSelector:: {
[labelName]: defaults.commonLabels[labelName]
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
if labelName != 'app.kubernetes.io/version'
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
podLabelSelector:: {
[labelName]: defaults.commonLabels[labelName]
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
if labelName != 'app.kubernetes.io/version'
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local receive = import 'kube-thanos/kube-thanos-receive.libsonnet';
// When calling the function to generate the component's manifest,
// you can pass an object structured like the default to overwrite default values.
local defaults = receiveConfigDefaults {
local defaults = self,
hashrings: [{
hashring: 'default',
tenants: [],
Expand Down
2 changes: 1 addition & 1 deletion jsonnet/kube-thanos/kube-thanos-rule.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local defaults = {
podLabelSelector:: {
[labelName]: defaults.commonLabels[labelName]
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
if labelName != 'app.kubernetes.io/version'
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
podLabelSelector:: {
[labelName]: defaults.commonLabels[labelName]
for labelName in std.objectFields(defaults.commonLabels)
if !std.setMember(labelName, ['app.kubernetes.io/version'])
if labelName != 'app.kubernetes.io/version'
},
}
1 change: 0 additions & 1 deletion jsonnet/kube-thanos/kube-thanos-store-shards.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local store = import 'kube-thanos/kube-thanos-store.libsonnet';
// When calling the function to generate the component's manifest,
// you can pass an object structured like the default to overwrite default values.
local defaults = storeConfigDefaults {
local defaults = self,
shards: 1,
};

Expand Down

0 comments on commit f1118ca

Please sign in to comment.