Skip to content

Commit

Permalink
Merge pull request #127 from thefirstofthe300/ds/add-check-generate-docs
Browse files Browse the repository at this point in the history
Add function to check code autogeneration
  • Loading branch information
morgante committed Mar 29, 2019
2 parents d687f6e + 6381911 commit aaa48de
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DOCKER_IMAGE_KITCHEN_TERRAFORM := cft/kitchen-terraform_terraform-google-kuberne
all: check generate_docs

.PHONY: check
check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace check_generate_docs
check: check_shell check_python check_golang check_terraform check_docker check_base_files test_check_headers check_headers check_trailing_whitespace check_generate check_generate_docs

# The .PHONY directive tells make that this isn't a real target and so
# the presence of a file named 'check_shell' won't cause this target to stop
Expand Down Expand Up @@ -75,6 +75,10 @@ check_headers:
@echo "Checking file headers"
@python test/verify_boilerplate.py

.PHONY: check_generate
check_generate: ## Check that `make generate` does not generate a diff
@source test/make.sh && check_generate

.PHONY: check_generate_docs
check_generate_docs: ## Check that `make generate_docs` does not generate a diff
@source test/make.sh && check_generate_docs
Expand All @@ -90,8 +94,7 @@ generate_docs:

.PHONY: generate
generate:
@pip install --user -r ./helpers/generate_modules/requirements.txt
@./helpers/generate_modules/generate_modules.py
@source test/make.sh && generate

# Versioning
.PHONY: version
Expand Down
4 changes: 4 additions & 0 deletions autogen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ The resources/services/activations/deletions that this module will create/trigge
- Activate network policy if `network_policy` is true
- Add `ip-masq-agent` configmap with provided `non_masquerade_cidrs` if `network_policy` is true

{% if private_cluster %}
**Note**: You must run Terraform from a VM on the same VPC as your cluster, otherwise there will be issues connecting to the GKE master.

{% endif %}
## Usage
There are multiple examples included in the [examples](./examples/) folder but simple usage is as follows:

Expand Down
4 changes: 1 addition & 3 deletions modules/private-cluster/cluster_regional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ resource "google_container_node_pool" "pools" {
name = "${lookup(var.node_pools[count.index], "name")}"
project = "${var.project_id}"
region = "${var.region}"
cluster = "${var.name}"
cluster = "${google_container_cluster.primary.name}"
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version_regional)}"
initial_node_count = "${lookup(var.node_pools[count.index], "initial_node_count", lookup(var.node_pools[count.index], "min_count", 1))}"

Expand Down Expand Up @@ -142,8 +142,6 @@ resource "google_container_node_pool" "pools" {
update = "30m"
delete = "30m"
}

depends_on = ["google_container_cluster.primary"]
}

resource "null_resource" "wait_for_regional_cluster" {
Expand Down
4 changes: 1 addition & 3 deletions modules/private-cluster/cluster_zonal.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ resource "google_container_node_pool" "zonal_pools" {
name = "${lookup(var.node_pools[count.index], "name")}"
project = "${var.project_id}"
zone = "${var.zones[0]}"
cluster = "${var.name}"
cluster = "${google_container_cluster.zonal_primary.name}"
version = "${lookup(var.node_pools[count.index], "auto_upgrade", false) ? "" : lookup(var.node_pools[count.index], "version", local.node_version_zonal)}"
initial_node_count = "${lookup(var.node_pools[count.index], "initial_node_count", lookup(var.node_pools[count.index], "min_count", 1))}"

Expand Down Expand Up @@ -142,8 +142,6 @@ resource "google_container_node_pool" "zonal_pools" {
update = "30m"
delete = "30m"
}

depends_on = ["google_container_cluster.zonal_primary"]
}

resource "null_resource" "wait_for_zonal_cluster" {
Expand Down
32 changes: 31 additions & 1 deletion test/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ function check_trailing_whitespace() {
fi
}

function generate() {
pip install --user -r ./helpers/generate_modules/requirements.txt
./helpers/generate_modules/generate_modules.py
}

function generate_docs() {
echo "Generating markdown docs with terraform-docs"
TMPFILE=$(mktemp)
Expand All @@ -97,12 +102,35 @@ function generate_docs() {
rm -f "$TMPFILE"
}

function check_generate() {
TMPDIR=$(mktemp -d)
git worktree add --detach "$TMPDIR" >/dev/null
cd "$TMPDIR" || exit 1

generate >/dev/null
generate_docs >/dev/null

git diff --stat --exit-code >/dev/null
rc=$?
cd - >/dev/null || exit 1

if [[ $rc -ne 0 ]]; then
echo '"make generate" creates a diff, run "make generate" and commit the results'
fi
rm -rf "$TMPDIR"
git worktree prune >/dev/null

echo "Code was generated properly"

exit $rc
}

function check_generate_docs() {
TMPDIR=$(mktemp -d)
git worktree add --detach "$TMPDIR" >/dev/null
cd "$TMPDIR" || exit 1

make generate_docs >/dev/null
generate_docs >/dev/null
git diff --stat --exit-code >/dev/null
rc=$?
cd - >/dev/null || exit 1
Expand All @@ -113,5 +141,7 @@ function check_generate_docs() {
rm -rf "$TMPDIR"
git worktree prune >/dev/null

echo "Docs were generated properly"

exit $rc
}

0 comments on commit aaa48de

Please sign in to comment.