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 Feb 28, 2024
1 parent a405eeb commit 69baa16
Show file tree
Hide file tree
Showing 33 changed files with 13,541 additions and 12 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
21 changes: 20 additions & 1 deletion 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.28.0
Expand Down Expand Up @@ -245,7 +246,7 @@ modules: ## Runs go mod to ensure proper vendoring.
cd $(TOOLS_DIR); go mod tidy

.PHONY: generate
generate: generate-controller-gen generate-conversion-gen generate-go generate-manifests ## Generate all generated code
generate: generate-controller-gen generate-conversion-gen generate-go generate-manifests generate-api-docs ## Generate all generated code

.PHONY: generate-go
generate-go: $(MOCKGEN)
Expand Down Expand Up @@ -282,6 +283,24 @@ 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/v1beta1 \
-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/v1beta1/api.md
$(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/v1beta1
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:deprecatedversion:warning="The v1alpha6 version of OpenStackCluster has been deprecated and will be removed in a future release of the API. Please upgrade."
// +kubebuilder:resource:path=openstackclusters,scope=Namespaced,categories=cluster-api,shortName=osc
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 @@ -30,6 +30,8 @@ type OpenStackClusterTemplateSpec struct {
Template OpenStackClusterTemplateResource `json:"template"`
}

// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:deprecatedversion:warning="The v1alpha6 version of OpenStackClusterTemplate has been deprecated and will be removed in a future release of the API. Please upgrade."
// +kubebuilder:resource:path=openstackclustertemplates,scope=Namespaced,categories=cluster-api,shortName=osct
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:deprecatedversion:warning="The v1alpha6 version of OpenStackMachine has been deprecated and will be removed in a future release of the API. Please upgrade."
// +kubebuilder:resource:path=openstackmachines,scope=Namespaced,categories=cluster-api,shortName=osm
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:deprecatedversion:warning="The v1alpha6 version of OpenStackMachineTemplate has been deprecated and will be removed in a future release of the API. Please upgrade."
// +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,5 +14,8 @@ 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
// +k8s:conversion-gen=sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1
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:subresource:status
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,8 +30,10 @@ type OpenStackClusterTemplateSpec struct {
Template OpenStackClusterTemplateResource `json:"template"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:path=openstackclustertemplates,scope=Namespaced,categories=cluster-api,shortName=osct
// +genclient
// +genclient:Namespaced
// +kubebuilder:object:root=true
// +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 @@ -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/v1alpha7/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/v1beta1/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 v1beta1 contains API Schema definitions for the infrastructure v1beta1 API group.
// +kubebuilder:object:generate=true
// +groupName=infrastructure.cluster.x-k8s.io
package v1beta1
2 changes: 2 additions & 0 deletions api/v1beta1/openstackcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,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/v1beta1/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/v1beta1/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,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/v1beta1/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:storageversion
// +kubebuilder:resource:path=openstackmachinetemplates,scope=Namespaced,categories=cluster-api,shortName=osmt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2233,7 +2233,7 @@ spec:
type: object
type: object
served: true
storage: false
storage: true
- name: v1beta1
schema:
openAPIV3Schema:
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 }}
Loading

0 comments on commit 69baa16

Please sign in to comment.