Skip to content

Commit d1d7e25

Browse files
committed
Reduce API docs generation time by 97%
Optimize the API docs generation by disabling the use of Go modules when running the generation tool. This is a workaround for performance issues in the upstream libraries: kubernetes/gengo#147 kubernetes/code-generator#69 Before this workaround: make api-docs 93.87s user 171.98s system 426% cpu 1:02.30 total After the workaround: make api-docs 2.91s user 0.83s system 135% cpu 2.752 total The hack seems worth the 97% improvement for iterating on docs.
1 parent 2b961b5 commit d1d7e25

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ cluster-api-provider-ibmcloud: $(CONTROLLER_GEN)
119119

120120
.PHONY: api-docs
121121
api-docs: $(GENAPIDOCS)
122-
$(GENAPIDOCS) --config $(DIR)/docs/api-doc-gen/config.json --template-dir $(DIR)/docs/api-doc-gen/templates --api-dir ./api/v1alpha1 --out-file $(DIR)/docs/content/reference/api.md
122+
hack/gen-api-docs.sh $(GENAPIDOCS) $(DIR)
123123

124124
# Run tests
125125
.PHONY: test

hack/gen-api-docs.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# This generation script sets up a fake GOPATH for docs generation
4+
# to work around performance issues in the upstream code generation
5+
# libraries. See:
6+
#
7+
# https://github.com/kubernetes/gengo/issues/147
8+
# https://github.com/kubernetes/code-generator/issues/69
9+
10+
GEN_BIN="$1"
11+
REPO_ROOT_DIR="$2"
12+
13+
FAKE_GOPATH="$(mktemp -d)"
14+
trap 'rm -rf ${FAKE_GOPATH}' EXIT
15+
16+
FAKE_REPOPATH="${FAKE_GOPATH}/src/github.com/openshift/hypershift"
17+
mkdir -p "$(dirname "${FAKE_REPOPATH}")" && ln -s "${REPO_ROOT_DIR}" "${FAKE_REPOPATH}"
18+
19+
export GOPATH="${FAKE_GOPATH}"
20+
export GO111MODULE="off"
21+
22+
cd "${FAKE_REPOPATH}"
23+
24+
GO111MODULE="off" GOPATH="${FAKE_GOPATH}" ${GEN_BIN} \
25+
--config "${FAKE_REPOPATH}/docs/api-doc-gen/config.json" \
26+
--template-dir "${FAKE_REPOPATH}/docs/api-doc-gen/templates" \
27+
--api-dir ./api/v1alpha1 \
28+
--out-file "${FAKE_REPOPATH}/docs/content/reference/api.md"

0 commit comments

Comments
 (0)