forked from keptn/lifecycle-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add CRD docs auto generator tooling (keptn#884)
Signed-off-by: Amishakumari544 <[email protected]>
- Loading branch information
1 parent
751ce0f
commit 2071bf1
Showing
17 changed files
with
1,899 additions
and
33 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
.github/scripts/generate-crd-docs/crd-docs-generator-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
processor: | ||
useRawDocstring: true | ||
ignoreTypes: [ ] | ||
ignoreFields: | ||
- "status$" | ||
- "TypeMeta$" | ||
|
||
render: | ||
kubernetesVersion: 1.24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
# CRD docs auto generation script | ||
# | ||
# This script goes through all API definitions in the operator/apis folder | ||
# and generates docs from code for each API group and version | ||
# | ||
# Inputs: None | ||
|
||
# renovate: datasource=github-releases depName=elastic/crd-ref-docs | ||
GENERATOR_VERSION=master | ||
API_DOMAIN="keptn.sh" | ||
API_ROOT='operator/apis/' | ||
TEMPLATE_DIR='.github/scripts/generate-crd-docs/templates' | ||
RENDERER='markdown' | ||
RENDERER_CONFIG_FILE='.github/scripts/generate-crd-docs/crd-docs-generator-config.yaml' | ||
|
||
echo "Checking if code generator tool is installed..." | ||
test -s crd-ref-docs || go install github.com/elastic/crd-ref-docs@${GENERATOR_VERSION} | ||
|
||
echo "Running CRD docs auto-generator..." | ||
|
||
for api_group in "$API_ROOT"*; do | ||
sanitized_api_group="${api_group#$API_ROOT}" | ||
INDEX_PATH="./docs/content/en/docs/crd-ref/$sanitized_api_group/_index.md" | ||
|
||
if [ ! -f "$INDEX_PATH" ]; then | ||
echo "API group index file doesn't exist for group $sanitized_api_group. Creating it now..." | ||
# Use sanitized_api_group and make first char uppercase | ||
API_GROUP="$(tr '[:lower:]' '[:upper:]' <<< "${sanitized_api_group:0:1}")${sanitized_api_group:1}" | ||
export API_GROUP | ||
envsubst < './.github/scripts/generate-crd-docs/templates/index-template.md' > "$INDEX_PATH" | ||
unset API_GROUP | ||
fi | ||
|
||
for api_version in "$api_group"/*; do | ||
sanitized_api_version="${api_version#$API_ROOT$sanitized_api_group/}" | ||
|
||
OUTPUT_PATH="./docs/content/en/docs/crd-ref/$sanitized_api_group/$sanitized_api_version" | ||
|
||
echo "Arguments:" | ||
echo "TEMPLATE_DIR: $TEMPLATE_DIR" | ||
echo "API_ROOT: $API_ROOT" | ||
echo "API_GROUP: $sanitized_api_group" | ||
echo "API_VERSION: $sanitized_api_version" | ||
echo "RENDERER: $RENDERER" | ||
echo "RENDERER_CONFIG_FILE: $RENDERER_CONFIG_FILE" | ||
echo "OUTPUT_PATH: $OUTPUT_PATH/_index.md" | ||
|
||
echo "Creating docs folder $OUTPUT_PATH..." | ||
mkdir -p "$OUTPUT_PATH" | ||
|
||
echo "Generating CRD docs for $sanitized_api_group.$API_DOMAIN/$sanitized_api_version..." | ||
crd-ref-docs \ | ||
--templates-dir "$TEMPLATE_DIR" \ | ||
--source-path="./$api_version" \ | ||
--renderer="$RENDERER" \ | ||
--config "$RENDERER_CONFIG_FILE" \ | ||
--output-path "$OUTPUT_PATH/_index.md" | ||
echo "---------------------" | ||
done | ||
done |
19 changes: 19 additions & 0 deletions
19
.github/scripts/generate-crd-docs/templates/gv_details.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{{- define "gvDetails" -}} | ||
{{- $gv := . -}} | ||
|
||
## {{ $gv.GroupVersionString }} | ||
|
||
{{ $gv.Doc }} | ||
|
||
{{- if $gv.Kinds }} | ||
### Resource Types | ||
{{- range $gv.SortedKinds }} | ||
- {{ $gv.TypeForKind . | markdownRenderTypeLink }} | ||
{{- end }} | ||
{{ end }} | ||
|
||
{{ range $gv.SortedTypes }} | ||
{{ template "type" . }} | ||
{{ end }} | ||
|
||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{{- define "gvList" -}} | ||
{{- $groupVersions := . -}} | ||
{{- $groupVersion := index $groupVersions 0 -}} | ||
|
||
--- | ||
title: {{ $groupVersion.Version }} | ||
description: Reference information for {{ $groupVersion.GroupVersionString }} | ||
--- | ||
<!-- markdownlint-disable --> | ||
|
||
## Packages | ||
{{- range $groupVersions }} | ||
- {{ markdownRenderGVLink . }} | ||
{{- end }} | ||
|
||
{{ range $groupVersions }} | ||
{{ template "gvDetails" . }} | ||
{{ end }} | ||
|
||
{{- end -}} | ||
<!-- markdownlint-enable --> |
4 changes: 4 additions & 0 deletions
4
.github/scripts/generate-crd-docs/templates/index-template.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: $API_GROUP API | ||
description: Reference information about the $API_GROUP API | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{{- define "type" -}} | ||
{{- $type := . -}} | ||
{{- if markdownShouldRenderType $type -}} | ||
|
||
#### {{ $type.Name }} | ||
|
||
{{ if $type.IsAlias }}_Underlying type:_ `{{ markdownRenderTypeLink $type.UnderlyingType }}`{{ end }} | ||
|
||
{{ $type.Doc }} | ||
|
||
{{ if $type.References -}} | ||
_Appears in:_ | ||
{{- range $type.SortedReferences }} | ||
- {{ markdownRenderTypeLink . }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{ if $type.Members -}} | ||
| Field | Description | | ||
| --- | --- | | ||
{{ if $type.GVK -}} | ||
| `apiVersion` _string_ | `{{ $type.GVK.Group }}/{{ $type.GVK.Version }}` | ||
| `kind` _string_ | `{{ $type.GVK.Kind }}` | ||
{{ end -}} | ||
|
||
{{ range $type.Members -}} | ||
| `{{ .Name }}` _{{ markdownRenderType .Type }}_ | {{ template "type_members" . }} | | ||
{{ end -}} | ||
|
||
{{ end -}} | ||
|
||
{{- end -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{- define "type_members" -}} | ||
{{- $field := . -}} | ||
{{- if eq $field.Name "metadata" -}} | ||
Refer to Kubernetes API documentation for fields of `metadata`. | ||
{{- else -}} | ||
{{ $field.Doc }} | ||
{{- end -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: Lifecycle API | ||
description: Reference information about the Lifecycle API | ||
--- |
Oops, something went wrong.