Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hcllint: add a linting check for HCL files #7791

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ check: ## Lint the source code

@echo "==> Check proto files are in-sync..."
@$(MAKE) proto
@if (git status | grep -q .pb.go); then echo the following proto files are out of sync; git status |grep .pb.go; exit 1; fi
@if (git status -s | grep -q .pb.go); then echo the following proto files are out of sync; git status -s | grep .pb.go; exit 1; fi

@echo "==> Check format of jobspecs and HCL files..."
@$(MAKE) hclfmt
@if (git status -s | grep -q -e '\.hcl$$' -e '\.nomad$$'); then echo the following HCL files are out of sync; git status -s | grep -e '\.hcl$$' -e '\.nomad$$'; exit 1; fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only need a single $ here.

Suggested change
@if (git status -s | grep -q -e '\.hcl$$' -e '\.nomad$$'); then echo the following HCL files are out of sync; git status -s | grep -e '\.hcl$$' -e '\.nomad$$'; exit 1; fi
@if (git status -s | grep -q -e '\.hcl$' -e '\.nomad$'); then echo the following HCL files are out of sync; git status -s | grep -e '\.hcl$' -e '\.nomad$'; exit 1; fi

Copy link
Member Author

@tgross tgross Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so at first but when I tested it, I realized Make wants you to escape the $, so the anchor was being ignored without that and the results were wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:til: Thanks for your testing :). Ship it!


@echo "==> Check API package is isolated from rest"
@if go list --test -f '{{ join .Deps "\n" }}' ./api | grep github.com/hashicorp/nomad/ | grep -v -e /vendor/ -e /nomad/api/ -e nomad/api.test; then echo " /api package depends the ^^ above internal nomad packages. Remove such dependency"; exit 1; fi
Expand Down
3 changes: 1 addition & 2 deletions jobspec/test-fixtures/tg-scaling-policy-minimal.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
job "elastic" {
group "group" {
scaling {
}
scaling {}
}
}
3 changes: 1 addition & 2 deletions jobspec/test-fixtures/tg-scaling-policy-multi-policy.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ job "elastic" {

policy {
foo = "wrong"
c = false
c = false
}

}
}
}
3 changes: 2 additions & 1 deletion jobspec/test-fixtures/tg-service-connect-local-service.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ job "connect-proxy-local-service" {
group "group" {
service {
name = "example"

connect {
sidecar_service {
proxy {
Expand All @@ -14,4 +15,4 @@ job "connect-proxy-local-service" {
}
}
}
}
}
8 changes: 7 additions & 1 deletion jobspec/test-fixtures/tg-service-connect-proxy.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,39 @@ job "service-connect-proxy" {
group "group" {
service {
name = "example"

connect {
sidecar_service {
proxy {
local_service_port = 8080
local_service_address = "10.0.1.2"

upstreams {
destination_name = "upstream1"
local_bind_port = 2001
}

upstreams {
destination_name = "upstream2"
local_bind_port = 2002
}

expose {
path {
path = "/metrics"
protocol = "http"
local_path_port = 9001
listener_port = "metrics"
}

path {
path = "/health"
protocol = "http"
local_path_port = 9002
listener_port = "health"
}
}

config {
foo = "bar"
}
Expand All @@ -39,4 +45,4 @@ job "service-connect-proxy" {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ job "sidecar_task_name" {
group "group" {
service {
name = "example"

connect {
sidecar_service {}
sidecar_service = {}

sidecar_task {
name = "my-sidecar"
}
}
}
}
}
}