Skip to content

Commit 8db580c

Browse files
authored
feat: Generate CRD docs (#197)
<img width="1714" alt="Screenshot 2024-04-24 at 20 50 09" src="https://github.com/aenix-io/etcd-operator/assets/15252187/4b3d607d-96d8-451f-bf95-3436b23c148b">
1 parent d7a6f5a commit 8db580c

File tree

9 files changed

+358
-3
lines changed

9 files changed

+358
-3
lines changed

.crd-docs.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
processor:
2+
ignoreTypes:
3+
- "(EtcdCluster)List$"
4+
- "(EtcdCluster)Status$"
5+
ignoreFields:
6+
- "status$"
7+
- "TypeMeta$"
8+
9+
render:
10+
kubernetesVersion: 1.30.1

.pre-commit-config.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
hooks:
77
- id: trailing-whitespace
88
- id: end-of-file-fixer
9-
exclude: "^charts/etcd-operator/(values.schema.json|README.md)$"
9+
exclude: "^charts/etcd-operator/(values.schema.json|README.md)|site/content/en/docs/v([.0-9]+)/reference/api.md$"
1010
- id: check-added-large-files
1111
- repo: local
1212
hooks:
@@ -24,6 +24,11 @@ repos:
2424
entry: sh -c "make lint-fix"
2525
language: system
2626
require_serial: true
27+
- id: make-generate-docs
28+
name: make-generate-docs
29+
entry: sh -c "make generate-docs"
30+
language: system
31+
require_serial: true
2732
- id: make-mod-tidy
2833
name: make-mod-tidy
2934
entry: sh -c "make mod-tidy"

Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ manifests: controller-gen yq ## Generate WebhookConfiguration, ClusterRole and C
5555
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
5656
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
5757

58+
.PHONY: generate-docs
59+
generate-docs: crd-ref-docs ## Generate CRD reference documentation.
60+
@$(eval VERSION := $(shell $(YQ) '.params.version' site/hugo.yaml))
61+
$(CRD_REF_DOCS) --config=.crd-docs.yaml --renderer=markdown --templates-dir="site/reference-templates" --output-path="site/content/en/docs/$(VERSION)/reference/api.md"
62+
5863
.PHONY: fmt
5964
fmt: ## Run go fmt against code.
6065
go fmt ./...
@@ -236,6 +241,7 @@ KIND ?= $(LOCALBIN)/kind
236241
HELM ?= $(LOCALBIN)/helm
237242
HELM_DOCS ?= $(LOCALBIN)/helm-docs
238243
YQ = $(LOCALBIN)/yq
244+
CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs
239245

240246
## Tool Versions
241247
# renovate: datasource=github-tags depName=kubernetes-sigs/kustomize
@@ -276,6 +282,10 @@ controller-gen: $(LOCALBIN)
276282
envtest: $(LOCALBIN)
277283
@test -x $(ENVTEST) || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION)
278284

285+
.PHONY: crd-ref-docs
286+
crd-ref-docs: $(LOCALBIN)
287+
@test -x $(CRD_REF_DOCS) || GOBIN=$(LOCALBIN) go install github.com/elastic/crd-ref-docs@latest
288+
279289
.PHONY: golangci-lint
280290
golangci-lint: $(LOCALBIN)
281291
@test -x $(GOLANGCI_LINT) && $(GOLANGCI_LINT) version | grep -q $(GOLANGCI_LINT_VERSION) || \

site/content/en/docs/v0.2/reference/_index.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
title: Reference
33
description: Low level reference docs for your project.
44
weight: 9
5+
simple_list: true
56
---
6-
7-
TODO
+244
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
---
2+
title: API Reference
3+
description: Autogenerated API Reference for the CRD
4+
weight: 9
5+
simple_list: true
6+
---
7+
8+
## Packages
9+
- [etcd.aenix.io/v1alpha1](#etcdaenixiov1alpha1)
10+
11+
12+
## etcd.aenix.io/v1alpha1
13+
14+
Package v1alpha1 contains API Schema definitions for the etcd.aenix.io v1alpha1 API group
15+
16+
### Resource Types
17+
- [EtcdCluster](#etcdcluster)
18+
19+
20+
21+
#### EmbeddedMetadataResource
22+
23+
24+
25+
26+
27+
28+
29+
_Appears in:_
30+
- [EtcdClusterSpec](#etcdclusterspec)
31+
32+
| Field | Description | Default | Validation |
33+
| --- | --- | --- | --- |
34+
| `metadata` _[EmbeddedObjectMetadata](#embeddedobjectmetadata)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
35+
36+
37+
#### EmbeddedObjectMetadata
38+
39+
40+
41+
EmbeddedObjectMetadata contains a subset of the fields included in k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta
42+
Only fields which are relevant to embedded resources are included.
43+
44+
45+
46+
_Appears in:_
47+
- [EmbeddedMetadataResource](#embeddedmetadataresource)
48+
- [EmbeddedPersistentVolumeClaim](#embeddedpersistentvolumeclaim)
49+
- [EmbeddedPodDisruptionBudget](#embeddedpoddisruptionbudget)
50+
- [EmbeddedService](#embeddedservice)
51+
- [PodTemplate](#podtemplate)
52+
53+
| Field | Description | Default | Validation |
54+
| --- | --- | --- | --- |
55+
| `name` _string_ | Name must be unique within a namespace. Is required when creating resources, although<br />some resources may allow a client to request the generation of an appropriate name<br />automatically. Name is primarily intended for creation idempotence and configuration<br />definition.<br />Cannot be updated.<br />More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names | | |
56+
| `labels` _object (keys:string, values:string)_ | Labels Map of string keys and values that can be used to organize and categorize<br />(scope and select) objects. May match selectors of replication controllers<br />and services.<br />More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels | | |
57+
| `annotations` _object (keys:string, values:string)_ | Annotations is an unstructured key value map stored with a resource that may be<br />set by external tools to store and retrieve arbitrary metadata. They are not<br />queryable and should be preserved when modifying objects.<br />More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations | | |
58+
59+
60+
#### EmbeddedPersistentVolumeClaim
61+
62+
63+
64+
EmbeddedPersistentVolumeClaim is an embedded version of k8s.io/api/core/v1.PersistentVolumeClaim.
65+
It contains TypeMeta and a reduced ObjectMeta.
66+
67+
68+
69+
_Appears in:_
70+
- [StorageSpec](#storagespec)
71+
72+
| Field | Description | Default | Validation |
73+
| --- | --- | --- | --- |
74+
| `metadata` _[EmbeddedObjectMetadata](#embeddedobjectmetadata)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
75+
| `spec` _[PersistentVolumeClaimSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30.1/#persistentvolumeclaimspec-v1-core)_ | Spec defines the desired characteristics of a volume requested by a pod author.<br />More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims | | |
76+
77+
78+
#### EmbeddedPodDisruptionBudget
79+
80+
81+
82+
EmbeddedPodDisruptionBudget describes PDB resource for etcd cluster members
83+
84+
85+
86+
_Appears in:_
87+
- [EtcdClusterSpec](#etcdclusterspec)
88+
89+
| Field | Description | Default | Validation |
90+
| --- | --- | --- | --- |
91+
| `metadata` _[EmbeddedObjectMetadata](#embeddedobjectmetadata)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
92+
| `spec` _[PodDisruptionBudgetSpec](#poddisruptionbudgetspec)_ | Spec defines the desired characteristics of a PDB.<br />More info: https://kubernetes.io/docs/concepts/workloads/pods/disruptions/#pod-disruption-budgets | | |
93+
94+
95+
#### EmbeddedService
96+
97+
98+
99+
100+
101+
102+
103+
_Appears in:_
104+
- [EtcdClusterSpec](#etcdclusterspec)
105+
106+
| Field | Description | Default | Validation |
107+
| --- | --- | --- | --- |
108+
| `metadata` _[EmbeddedObjectMetadata](#embeddedobjectmetadata)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
109+
| `spec` _[ServiceSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30.1/#servicespec-v1-core)_ | Spec defines the behavior of the service. | | |
110+
111+
112+
#### EtcdCluster
113+
114+
115+
116+
EtcdCluster is the Schema for the etcdclusters API
117+
118+
119+
120+
121+
122+
| Field | Description | Default | Validation |
123+
| --- | --- | --- | --- |
124+
| `apiVersion` _string_ | `etcd.aenix.io/v1alpha1` | | |
125+
| `kind` _string_ | `EtcdCluster` | | |
126+
| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30.1/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
127+
| `spec` _[EtcdClusterSpec](#etcdclusterspec)_ | | | |
128+
129+
130+
#### EtcdClusterSpec
131+
132+
133+
134+
EtcdClusterSpec defines the desired state of EtcdCluster
135+
136+
137+
138+
_Appears in:_
139+
- [EtcdCluster](#etcdcluster)
140+
141+
| Field | Description | Default | Validation |
142+
| --- | --- | --- | --- |
143+
| `replicas` _integer_ | Replicas is the count of etcd instances in cluster. | 3 | Minimum: 0 <br /> |
144+
| `options` _object (keys:string, values:string)_ | Options are the extra arguments to pass to the etcd container. | | |
145+
| `podTemplate` _[PodTemplate](#podtemplate)_ | PodTemplate defines the desired state of PodSpec for etcd members. If not specified, default values will be used. | | |
146+
| `serviceTemplate` _[EmbeddedService](#embeddedservice)_ | Service defines the desired state of Service for etcd members. If not specified, default values will be used. | | |
147+
| `headlessServiceTemplate` _[EmbeddedMetadataResource](#embeddedmetadataresource)_ | HeadlessService defines the desired state of HeadlessService for etcd members. If not specified, default values will be used. | | |
148+
| `podDisruptionBudgetTemplate` _[EmbeddedPodDisruptionBudget](#embeddedpoddisruptionbudget)_ | PodDisruptionBudgetTemplate describes PDB resource to create for etcd cluster members. Nil to disable. | | |
149+
| `storage` _[StorageSpec](#storagespec)_ | | | |
150+
| `security` _[SecuritySpec](#securityspec)_ | Security describes security settings of etcd (authentication, certificates, rbac) | | |
151+
152+
153+
154+
155+
156+
157+
#### PodDisruptionBudgetSpec
158+
159+
160+
161+
162+
163+
164+
165+
_Appears in:_
166+
- [EmbeddedPodDisruptionBudget](#embeddedpoddisruptionbudget)
167+
168+
| Field | Description | Default | Validation |
169+
| --- | --- | --- | --- |
170+
| `minAvailable` _[IntOrString](#intorstring)_ | MinAvailable describes minimum ready replicas. If both are empty, controller will implicitly<br />calculate MaxUnavailable based on number of replicas<br />Mutually exclusive with MaxUnavailable. | | |
171+
| `maxUnavailable` _[IntOrString](#intorstring)_ | MinAvailable describes maximum not ready replicas. If both are empty, controller will implicitly<br />calculate MaxUnavailable based on number of replicas<br />Mutually exclusive with MinAvailable | | |
172+
173+
174+
#### PodTemplate
175+
176+
177+
178+
PodTemplate allows overrides, such as sidecars, init containers, changes to the security context, etc to the pod template generated by the operator.
179+
180+
181+
182+
_Appears in:_
183+
- [EtcdClusterSpec](#etcdclusterspec)
184+
185+
| Field | Description | Default | Validation |
186+
| --- | --- | --- | --- |
187+
| `metadata` _[EmbeddedObjectMetadata](#embeddedobjectmetadata)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
188+
| `spec` _[PodSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30.1/#podspec-v1-core)_ | Spec follows the structure of a regular Pod spec. Overrides defined here will be strategically merged with the default pod spec, generated by the operator. | | |
189+
190+
191+
#### SecuritySpec
192+
193+
194+
195+
SecuritySpec defines security settings for etcd.
196+
197+
198+
199+
_Appears in:_
200+
- [EtcdClusterSpec](#etcdclusterspec)
201+
202+
| Field | Description | Default | Validation |
203+
| --- | --- | --- | --- |
204+
| `tls` _[TLSSpec](#tlsspec)_ | Section for user-managed tls certificates | | |
205+
206+
207+
#### StorageSpec
208+
209+
210+
211+
StorageSpec defines the configured storage for a etcd members.
212+
If neither `emptyDir` nor `volumeClaimTemplate` is specified, then by default an [EmptyDir](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir) will be used.
213+
214+
215+
216+
_Appears in:_
217+
- [EtcdClusterSpec](#etcdclusterspec)
218+
219+
| Field | Description | Default | Validation |
220+
| --- | --- | --- | --- |
221+
| `emptyDir` _[EmptyDirVolumeSource](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30.1/#emptydirvolumesource-v1-core)_ | EmptyDirVolumeSource to be used by the StatefulSets. If specified, used in place of any volumeClaimTemplate. More<br />info: https://kubernetes.io/docs/concepts/storage/volumes/#emptydir | | |
222+
| `volumeClaimTemplate` _[EmbeddedPersistentVolumeClaim](#embeddedpersistentvolumeclaim)_ | A PVC spec to be used by the StatefulSets. | | |
223+
224+
225+
#### TLSSpec
226+
227+
228+
229+
TLSSpec defines user-managed certificates names.
230+
231+
232+
233+
_Appears in:_
234+
- [SecuritySpec](#securityspec)
235+
236+
| Field | Description | Default | Validation |
237+
| --- | --- | --- | --- |
238+
| `peerTrustedCASecret` _string_ | Trusted CA certificate secret to secure peer-to-peer communication between etcd nodes. It is expected to have tls.crt field in the secret. | | |
239+
| `peerSecret` _string_ | Certificate secret to secure peer-to-peer communication between etcd nodes. It is expected to have tls.crt and tls.key fields in the secret. | | |
240+
| `serverSecret` _string_ | Server certificate secret to secure client-server communication. Is provided to the client who connects to etcd by client port (2379 by default).<br />It is expected to have tls.crt and tls.key fields in the secret. | | |
241+
| `clientTrustedCASecret` _string_ | Trusted CA for client certificates that are provided by client to etcd. It is expected to have tls.crt field in the secret. | | |
242+
| `clientSecret` _string_ | Client certificate for etcd-operator to do maintenance. It is expected to have tls.crt and tls.key fields in the secret. | | |
243+
244+
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- define "gvDetails" -}}
2+
{{- $gv := . -}}
3+
4+
## {{ $gv.GroupVersionString }}
5+
6+
{{ $gv.Doc }}
7+
8+
{{- if $gv.Kinds }}
9+
### Resource Types
10+
{{- range $gv.SortedKinds }}
11+
- {{ $gv.TypeForKind . | markdownRenderTypeLink }}
12+
{{- end }}
13+
{{ end }}
14+
15+
{{ range $gv.SortedTypes }}
16+
{{ template "type" . }}
17+
{{ end }}
18+
19+
{{- end -}}

site/reference-templates/gv_list.tpl

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{- define "gvList" -}}
2+
{{- $groupVersions := . -}}
3+
4+
---
5+
title: API Reference
6+
description: Autogenerated API Reference for the CRD
7+
weight: 9
8+
simple_list: true
9+
---
10+
11+
## Packages
12+
{{- range $groupVersions }}
13+
- {{ markdownRenderGVLink . }}
14+
{{- end }}
15+
16+
{{ range $groupVersions }}
17+
{{ template "gvDetails" . }}
18+
{{ end }}
19+
20+
{{- end -}}

site/reference-templates/type.tpl

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{{- define "type" -}}
2+
{{- $type := . -}}
3+
{{- if markdownShouldRenderType $type -}}
4+
5+
#### {{ $type.Name }}
6+
7+
{{ if $type.IsAlias }}_Underlying type:_ _{{ markdownRenderTypeLink $type.UnderlyingType }}_{{ end }}
8+
9+
{{ $type.Doc }}
10+
11+
{{ if $type.Validation -}}
12+
_Validation:_
13+
{{- range $type.Validation }}
14+
- {{ . }}
15+
{{- end }}
16+
{{- end }}
17+
18+
{{ if $type.References -}}
19+
_Appears in:_
20+
{{- range $type.SortedReferences }}
21+
- {{ markdownRenderTypeLink . }}
22+
{{- end }}
23+
{{- end }}
24+
25+
{{ if $type.Members -}}
26+
| Field | Description | Default | Validation |
27+
| --- | --- | --- | --- |
28+
{{ if $type.GVK -}}
29+
| `apiVersion` _string_ | `{{ $type.GVK.Group }}/{{ $type.GVK.Version }}` | | |
30+
| `kind` _string_ | `{{ $type.GVK.Kind }}` | | |
31+
{{ end -}}
32+
33+
{{ range $type.Members -}}
34+
| `{{ .Name }}` _{{ markdownRenderType .Type }}_ | {{ template "type_members" . }} | {{ markdownRenderDefault .Default }} | {{ range .Validation -}} {{ . }} <br />{{ end }} |
35+
{{ end -}}
36+
37+
{{ end -}}
38+
39+
{{- end -}}
40+
{{- end -}}

0 commit comments

Comments
 (0)