Skip to content

Commit 8d14d60

Browse files
yroblataskbotCopilot
authored
feat: generate documentation for k8s operator (#740)
Co-authored-by: taskbot <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent ed1b17e commit 8d14d60

File tree

4 files changed

+436
-1
lines changed

4 files changed

+436
-1
lines changed

.github/workflows/operator-ci.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
pull_request:
77
paths:
88
- 'cmd/thv-operator/**'
9-
- 'deploy/charts/operator/**'
109
- 'deploy/charts/operator-crds/**'
1110
- 'go.mod'
1211
- 'go.sum'
@@ -112,4 +111,37 @@ jobs:
112111
if: steps.git-check.outputs.crd-changes == 'true' || steps.git-check.outputs.operator-changes == 'true'
113112
run: |
114113
echo "CRDs are not up to date. Please run 'task operator-manifests' and commit the changes."
114+
exit 1
115+
116+
generate-crd-docs:
117+
name: Generate CRD Docs
118+
runs-on: ubuntu-latest
119+
steps:
120+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
121+
122+
- name: Set up Go
123+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
124+
with:
125+
go-version-file: 'go.mod'
126+
cache: true
127+
128+
- name: Install Task
129+
uses: arduino/setup-task@v2
130+
with:
131+
version: 3.x
132+
repo-token: ${{ secrets.GITHUB_TOKEN }}
133+
134+
- name: Generate CRD Docs
135+
run: task crdref-gen
136+
working-directory: cmd/thv-operator
137+
138+
- name: Check for changes
139+
id: git-docs-check
140+
run: |
141+
git diff --exit-code -- docs/operator/crd-api.md || echo "crd-changes=true" >> $GITHUB_OUTPUT
142+
143+
- name: Fail if CRDs are not up to date
144+
if: steps.git-docs-check.outputs.crd-changes == 'true'
145+
run: |
146+
echo "Docs for CRDs are not up to date. Please run 'task crdref-gen' and commit the changes."
115147
exit 1

cmd/thv-operator/Taskfile.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
version: '3'
22

3+
vars:
4+
CRD_DIR: config/crd/bases
5+
DOCS_OUT: ../../docs/operator/crd-api.md
6+
CRDREF_CONFIG: ../../docs/operator/crd-ref-config.yaml
7+
38
tasks:
49
kind-setup:
510
desc: Setup a local Kind cluster
@@ -134,3 +139,19 @@ tasks:
134139
cmds:
135140
- go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
136141
- KUBEBUILDER_ASSETS="$(shell setup-envtest use 1.28.0 -p path)" go test ./cmd/thv-operator/... -coverprofile cover.out
142+
143+
crdref-install:
144+
desc: Install elastic/crd-ref-docs
145+
cmds:
146+
- go install github.com/elastic/crd-ref-docs@latest
147+
148+
crdref-gen:
149+
desc: Generate CRD API docs via crd-ref-docs
150+
deps: [crdref-install]
151+
cmds:
152+
- crd-ref-docs --source-path=. --config={{ .CRDREF_CONFIG }} --renderer markdown --output-path {{ .DOCS_OUT }}
153+
sources:
154+
- 'config/crd/bases/**/*.yaml'
155+
- 'api/**/*.go'
156+
generates:
157+
- '{{ .DOCS_OUT }}'

0 commit comments

Comments
 (0)