Skip to content

Commit

Permalink
Add API reference documentation generation
Browse files Browse the repository at this point in the history
Signed-off-by: alexandre.vilain <alexandre.vilain@corp.ovh.com>
  • Loading branch information
alexandrevilain committed Oct 16, 2023
1 parent e38c73d commit b5cf1a5
Show file tree
Hide file tree
Showing 26 changed files with 8,560 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ sshuttle.pid

# Book
docs/book/book/
!docs/book/gen-crd-api-reference-docs/config.json

# venv
.venv
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
RELEASE_NOTES := $(TOOLS_BIN_DIR)/release-notes
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest
GEN_CRD_API_REFERENCE_DOCS := $(TOOLS_BIN_DIR)/gen-crd-api-reference-docs

# Kubebuilder
export KUBEBUILDER_ENVTEST_KUBERNETES_VERSION ?= 1.25.0
Expand Down Expand Up @@ -255,6 +256,7 @@ modules: ## Runs go mod to ensure proper vendoring.
generate: ## Generate code
$(MAKE) generate-go
$(MAKE) generate-manifests
$(MAKE) generate-api-docs

.PHONY: generate-go
generate-go: $(MOCKGEN)
Expand Down Expand Up @@ -283,6 +285,19 @@ generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
output:rbac:dir=$(RBAC_ROOT) \
rbac:roleName=manager-role

.PHONY: generate-api-docs
generate-api-docs: $(GEN_CRD_API_REFERENCE_DOCS) ## Generate api documentation
$(GEN_CRD_API_REFERENCE_DOCS) \
-api-dir=./api/v1alpha7 \
-config=./docs/book/gen-crd-api-reference-docs/config.json \
-template-dir=./docs/book/gen-crd-api-reference-docs/template \
-out-file=./docs/book/src/api/v1alpha7/api.md
$(GEN_CRD_API_REFERENCE_DOCS) \
-api-dir=./api/v1alpha6 \
-config=./docs/book/gen-crd-api-reference-docs/config.json \
-template-dir=./docs/book/gen-crd-api-reference-docs/template \
-out-file=./docs/book/src/api/v1alpha6/api.md

## --------------------------------------
##@ Docker
## --------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha6/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha6 contains API Schema definitions for the infrastructure v1alpha6 API group
// +kubebuilder:object:generate=true
// +groupName=infrastructure.cluster.x-k8s.io
// +k8s:conversion-gen=sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha7
package v1alpha6
3 changes: 0 additions & 3 deletions api/v1alpha6/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// package v1alpha6 contains API Schema definitions for the infrastructure v1alpha6 API group
// +kubebuilder:object:generate=true
// +groupName=infrastructure.cluster.x-k8s.io
package v1alpha6

import (
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha6/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ type OpenStackClusterStatus struct {
FailureMessage *string `json:"failureMessage,omitempty"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=openstackclusters,scope=Namespaced,categories=cluster-api,shortName=osc
// +kubebuilder:subresource:status
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha6/openstackclustertemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type OpenStackClusterTemplate struct {
Spec OpenStackClusterTemplateSpec `json:"spec,omitempty"`
}

// +genclient
// +genclient:Namespaced
//+kubebuilder:object:root=true

// OpenStackClusterTemplateList contains a list of OpenStackClusterTemplate.
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha6/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ type OpenStackMachineStatus struct {
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=openstackmachines,scope=Namespaced,categories=cluster-api,shortName=osm
// +kubebuilder:subresource:status
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha6/openstackmachinetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type OpenStackMachineTemplateSpec struct {
Template OpenStackMachineTemplateResource `json:"template"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=openstackmachinetemplates,scope=Namespaced,categories=cluster-api,shortName=osmt

Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha7/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha7 contains API Schema definitions for the infrastructure v1alpha7 API group
// +kubebuilder:object:generate=true
// +groupName=infrastructure.cluster.x-k8s.io
package v1alpha7
3 changes: 0 additions & 3 deletions api/v1alpha7/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// package v1alpha7 contains API Schema definitions for the infrastructure v1alpha7 API group
// +kubebuilder:object:generate=true
// +groupName=infrastructure.cluster.x-k8s.io
package v1alpha7

import (
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha7/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ type OpenStackClusterStatus struct {
FailureMessage *string `json:"failureMessage,omitempty"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=openstackclusters,scope=Namespaced,categories=cluster-api,shortName=osc
// +kubebuilder:storageversion
Expand Down
6 changes: 4 additions & 2 deletions api/v1alpha7/openstackclustertemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ type OpenStackClusterTemplateSpec struct {
Template OpenStackClusterTemplateResource `json:"template"`
}

//+kubebuilder:object:root=true
// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
//+kubebuilder:resource:path=openstackclustertemplates,scope=Namespaced,categories=cluster-api,shortName=osct
// +kubebuilder:resource:path=openstackclustertemplates,scope=Namespaced,categories=cluster-api,shortName=osct

// OpenStackClusterTemplate is the Schema for the openstackclustertemplates API.
type OpenStackClusterTemplate struct {
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha7/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ type OpenStackMachineStatus struct {
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:resource:path=openstackmachines,scope=Namespaced,categories=cluster-api,shortName=osm
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha7/openstackmachinetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type OpenStackMachineTemplate struct {
Spec OpenStackMachineTemplateSpec `json:"spec,omitempty"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true

// OpenStackMachineTemplateList contains a list of OpenStackMachineTemplate.
Expand Down
36 changes: 36 additions & 0 deletions docs/book/gen-crd-api-reference-docs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"hideMemberFields": [
"TypeMeta"
],
"hideTypePatterns": [
"ParseError$",
"List$"
],
"externalPackages": [
{
"typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/apis/meta/v1\\.Duration$",
"docsURLTemplate": "https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration"
},
{
"typeMatchPrefix": "^k8s\\.io/apimachinery/pkg/apis/meta/v1\\.Condition$",
"docsURLTemplate": "https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Condition"
},
{
"typeMatchPrefix": "^sigs\\.k8s\\.io/cluster-api/api/v1beta1",
"docsURLTemplate": "https://doc.crds.dev/github.com/kubernetes-sigs/cluster-api@v1.5.1"
},
{
"typeMatchPrefix": "^sigs\\.k8s\\.io/cluster-api/api/v1beta1",
"docsURLTemplate": "https://doc.crds.dev/github.com/kubernetes-sigs/cluster-api@v1.5.1"
},
{
"typeMatchPrefix": "^sigs\\.k8s\\.io/cluster-api/errors",
"docsURLTemplate": "https://pkg.go.dev/sigs.k8s.io/cluster-api@v1.5.1/errors#{{.TypeIdentifier}}"
}
],
"typeDisplayNamePrefixOverrides": {
"k8s.io/api/": "Kubernetes ",
"k8s.io/apimachinery/pkg/apis/": "Kubernetes "
},
"markdownDisabled": false
}
48 changes: 48 additions & 0 deletions docs/book/gen-crd-api-reference-docs/template/members.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{ define "members" }}

{{ range .Members }}
{{ if not (hiddenMember .)}}
<tr>
<td>
<code>{{ fieldName . }}</code><br/>
<em>
{{ if linkForType .Type }}
<a href="{{ linkForType .Type}}">
{{ typeDisplayName .Type }}
</a>
{{ else }}
{{ typeDisplayName .Type }}
{{ end }}
</em>
</td>
<td>
{{ if fieldEmbedded . }}
<p>
(Members of <code>{{ fieldName . }}</code> are embedded into this type.)
</p>
{{ end}}

{{ if isOptionalMember .}}
<em>(Optional)</em>
{{ end }}

{{ safe (renderComments .CommentLines) }}

{{ if and (eq (.Type.Name.Name) "ObjectMeta") }}
Refer to the Kubernetes API documentation for the fields of the
<code>metadata</code> field.
{{ end }}

{{ if or (eq (fieldName .) "spec") }}
<br/>
<br/>
<table>
{{ template "members" .Type }}
</table>
{{ end }}
</td>
</tr>
{{ end }}
{{ end }}

{{ end }}
37 changes: 37 additions & 0 deletions docs/book/gen-crd-api-reference-docs/template/pkg.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{ define "packages" }}

{{ range .packages }}
<h2 id="{{- packageAnchorID . -}}">
{{- packageDisplayName . -}}
</h2>

{{ with (index .GoPackages 0 )}}
{{ with .DocComments }}
<p>
{{ safe (renderComments .) }}
</p>
{{ end }}
{{ end }}

Resource Types:
<ul>
{{- range (visibleTypes (sortedTypes .Types)) -}}
{{ if isExportedType . -}}
<li>
<a href="{{ linkForType . }}">{{ typeDisplayName . }}</a>
</li>
{{- end }}
{{- end -}}
</ul>

{{ range (visibleTypes (sortedTypes .Types))}}
{{ template "type" . }}
{{ end }}
<hr/>
{{ end }}

<p><em>
Generated with <code>gen-crd-api-reference-docs</code>.
</em></p>

{{ end }}
81 changes: 81 additions & 0 deletions docs/book/gen-crd-api-reference-docs/template/type.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{{ define "type" }}

<h3 id="{{ anchorIDForType . }}">
{{- .Name.Name }}
{{ if eq .Kind "Alias" }}(<code>{{.Underlying}}</code> alias)</p>{{ end -}}
</h3>
{{ with (typeReferences .) }}
<p>
(<em>Appears on:</em>
{{- $prev := "" -}}
{{- range . -}}
{{- if $prev -}}, {{ end -}}
{{ $prev = . }}
<a href="{{ linkForType . }}">{{ typeDisplayName . }}</a>
{{- end -}}
)
</p>
{{ end }}

<p>
{{ safe (renderComments .CommentLines) }}
</p>

{{ with (constantsOfType .) }}
<table>
<thead>
<tr>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{{- range . -}}
<tr>
{{- /*
renderComments implicitly creates a <p> element, so we
add one to the display name as well to make the contents
of the two cells align evenly.
*/ -}}
<td><p>{{ typeDisplayName . }}</p></td>
<td>{{ safe (renderComments .CommentLines) }}</td>
</tr>
{{- end -}}
</tbody>
</table>
{{ end }}

{{ if .Members }}
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{{ if isExportedType . }}
<tr>
<td>
<code>apiVersion</code><br/>
string</td>
<td>
<code>
{{apiGroup .}}
</code>
</td>
</tr>
<tr>
<td>
<code>kind</code><br/>
string
</td>
<td><code>{{.Name.Name}}</code></td>
</tr>
{{ end }}
{{ template "members" .}}
</tbody>
</table>
{{ end }}

{{ end }}
3 changes: 3 additions & 0 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
- [v1alpha4 to v1alpha5](./topics/crd-changes/v1alpha4-to-v1alpha5.md)
- [v1alpha5 to v1alpha6](./topics/crd-changes/v1alpha5-to-v1alpha6.md)
- [v1alpha6 to v1alpha7](./topics/crd-changes/v1alpha6-to-v1alpha7.md)
- [API reference](./api/index.md)
- [v1alpha6](./api/v1alpha6/api.md)
- [v1alpha7](./api/v1alpha7/api.md)
- [Development](./development/development.md)
- [Hacking CI](./development/ci.md)
1 change: 1 addition & 0 deletions docs/book/src/api/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# API reference
Loading

0 comments on commit b5cf1a5

Please sign in to comment.