Skip to content

📖 Add API reference documentation generation #1702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This files seems to be missing and I see the following error in the test results:

 	-template-dir=./docs/book/gen-crd-api-reference-docs/template \
	-out-file=./docs/book/src/api/v1alpha6/api.md
F1005 08:16:40.577071   16819 main.go:123] failed to open config file: open ./docs/book/gen-crd-api-reference-docs/config.json: no such file or directory
make[1]: *** [Makefile:288: generate-api-docs] Error 255
make[1]: Leaving directory '/home/prow/go/src/sigs.k8s.io/cluster-api-provider-openstack'
make: *** [Makefile:255: generate] Error 2 

Do we have to provide it or would the tool fall back to reasonable defaults if we don't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I understand why CI was failing ... config.json is gitignored ! Fixing this !

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also happened to discover we're ignoring '*.json' just last week. We should get rid of that rule; it's weird.

-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
Comment on lines +215 to +216
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why these are required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because complete support for kubebuilder v2 is still missing in the tool ahmetb/gen-crd-api-reference-docs#15

// +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
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/[email protected]"
},
{
"typeMatchPrefix": "^sigs\\.k8s\\.io/cluster-api/api/v1beta1",
"docsURLTemplate": "https://doc.crds.dev/github.com/kubernetes-sigs/[email protected]"
},
{
"typeMatchPrefix": "^sigs\\.k8s\\.io/cluster-api/errors",
"docsURLTemplate": "https://pkg.go.dev/sigs.k8s.io/[email protected]/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