Skip to content

Commit

Permalink
Merge pull request #611 from googs1025/add_api_reference
Browse files Browse the repository at this point in the history
docs: add JobSet API reference
  • Loading branch information
k8s-ci-robot authored Jul 3, 2024
2 parents fb65e01 + 4bbf590 commit 0105ce5
Show file tree
Hide file tree
Showing 6 changed files with 684 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ test-python-sdk:
./hack/python-sdk/test-sdk.sh

.PHONY: verify
verify: vet fmt-verify ci-lint manifests generate toc-verify
verify: vet fmt-verify ci-lint manifests generate toc-verify generate-apiref
git --no-pager diff --exit-code config api client-go


Expand Down Expand Up @@ -294,4 +294,14 @@ golangci-lint: ## Download golangci-lint locally if necessary.
GOTESTSUM = $(shell pwd)/bin/gotestsum
.PHONY: gotestsum
gotestsum: ## Download gotestsum locally if necessary.
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install gotest.tools/[email protected]
@GOBIN=$(PROJECT_DIR)/bin GO111MODULE=on $(GO_CMD) install gotest.tools/[email protected]


.PHONY: generate-apiref
generate-apiref: genref
cd $(PROJECT_DIR)/hack/genref/ && $(GENREF) -o $(PROJECT_DIR)/site/content/en/docs/reference

GENREF = $(PROJECT_DIR)/bin/genref
.PHONY: genref
genref: ## Download genref locally if necessary.
@GOBIN=$(PROJECT_DIR)/bin $(GO_CMD) install github.com/kubernetes-sigs/reference-docs/[email protected]
20 changes: 20 additions & 0 deletions hack/genref/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# more details can be found https://github.com/kubernetes-sigs/reference-docs/tree/master/genref
hiddenMemberFields:
- "TypeMeta"
- "ObjectMeta"

apis:
- name: jobset
title: JobSet API
package: sigs.k8s.io/jobset
path: api/jobset/v1alpha2

externalPackages:
- match: ^k8s\.io/(api|apimachinery/pkg/apis)/
target: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#{{- lower .TypeIdentifier -}}-{{- arrIndex .PackageSegments -1 -}}-{{- arrIndex .PackageSegments -2 -}}
- match: ^k8s\.io/apimachinery/pkg/api/resource\.Quantity$
target: https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity
- match: ^k8s.io/component-base/config/v1alpha1.
target: https://pkg.go.dev/k8s.io/component-base/config/v1alpha1#{{- .TypeIdentifier -}}
- match: ^time\.Duration$
target: https://pkg.go.dev/time#Duration
34 changes: 34 additions & 0 deletions hack/genref/markdown/members.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{ define "members" }}
{{/* . is a apiType */}}
{{- range .GetMembers -}}
{{/* . is a apiMember */}}
{{- if not .Hidden }}
<tr><td><code>{{ .FieldName }}</code>
{{- if not .IsOptional }} <B>[Required]</B>{{- end -}}
<br/>
{{/* Link for type reference */}}
{{- with .GetType -}}
{{- if .Link -}}
<a href="{{ .Link }}"><code>{{ .DisplayName }}</code></a>
{{- else -}}
<code>{{ .DisplayName }}</code>
{{- end -}}
{{- end }}
</td>
<td>
{{- if .IsInline -}}
(Members of <code>{{ .FieldName }}</code> are embedded into this type.)
{{- end }}
{{ if .GetComment -}}
{{ .GetComment }}
{{- else -}}
<span class="text-muted">No description provided.</span>
{{- end }}
{{- if and (eq (.GetType.Name.Name) "ObjectMeta") -}}
Refer to the Kubernetes API documentation for the fields of the <code>metadata</code> field.
{{- end -}}
</td>
</tr>
{{- end }}
{{- end }}
{{ end }}
46 changes: 46 additions & 0 deletions hack/genref/markdown/pkg.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{ define "packages" -}}

{{- range $idx, $val := .packages -}}
{{/* Special handling for config */}}
{{- if .IsMain -}}
---
title: {{ .Title }}
content_type: tool-reference
package: {{ .DisplayName }}
auto_generated: true
description: Generated API reference documentation for {{ .DisplayName }}.
---
{{ .GetComment -}}
{{- end -}}
{{- end }}

## Resource Types

{{ range .packages -}}
{{ $isConfig := (eq .GroupName "") }}
{{- range .VisibleTypes -}}
{{- if or .IsExported (and $isConfig (eq .DisplayName "Configuration")) }}
- [{{ .DisplayName }}]({{ .Link }})
{{- end -}}
{{- end -}}
{{- end -}}

{{ range .packages }}
{{ if ne .GroupName "" -}}
{{/* For package with a group name, list all type definitions in it. */}}
{{- range .VisibleTypes }}
{{- if or .Referenced .IsExported -}}
{{ template "type" . }}
{{- end -}}
{{ end }}
{{ else }}
{{/* For package w/o group name, list only types referenced. */}}
{{ $isConfig := (eq .GroupName "") }}
{{- range .VisibleTypes -}}
{{- if or .Referenced $isConfig -}}
{{ template "type" . }}
{{- end -}}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
37 changes: 37 additions & 0 deletions hack/genref/markdown/type.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{ define "type" }}

## `{{ .Name.Name }}` {#{{ .Anchor }}}

{{ if eq .Kind "Alias" -}}
(Alias of `{{ .Underlying }}`)
{{ end }}

{{- with .References }}
**Appears in:**
{{ range . }}
{{ if or .Referenced .IsExported -}}
- [{{ .DisplayName }}]({{ .Link }})
{{ end -}}
{{- end -}}
{{- end }}

{{ if .GetComment -}}
{{ .GetComment }}
{{ end }}
{{ if .GetMembers -}}
<table class="table">
<thead><tr><th width="30%">Field</th><th>Description</th></tr></thead>
<tbody>
{{/* . is a apiType */}}
{{- if .IsExported -}}
{{/* Add apiVersion and kind rows if deemed necessary */}}
<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 -}}

{{/* The actual list of members is in the following template */}}
{{- template "members" . -}}
</tbody>
</table>
{{- end -}}
{{- end -}}
Loading

0 comments on commit 0105ce5

Please sign in to comment.