diff --git a/Makefile b/Makefile index c327e0e6fc7..c3d867563cd 100644 --- a/Makefile +++ b/Makefile @@ -204,12 +204,12 @@ else @/bin/bash -c $(DOCS_CMD) endif -API_DOCS_CMD = "gen-crd-api-reference-docs \ - -config /usr/local/bin/example-config.json \ - -api-dir ./pkg/apis/cr/v1alpha1 \ - -template-dir /usr/local/bin/template \ - -out-file API.md \ - " +API_DOCS_CMD = "gen-crd-api-reference-docs \ + -config docs/api_docs/example-config.json \ + -api-dir ./pkg/apis/cr/v1alpha1 \ + -template-dir docs/api_docs/template \ + -out-file API.md \ +" crd_docs: ifeq ($(DOCKER_BUILD),"true") diff --git a/docker/build/Dockerfile b/docker/build/Dockerfile index c4553c68d67..014e3d8b2c1 100644 --- a/docker/build/Dockerfile +++ b/docker/build/Dockerfile @@ -22,14 +22,8 @@ COPY --from=golangci/golangci-lint:v1.50 /usr/bin/golangci-lint /usr/local/bin/ RUN wget -O /usr/local/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-linux-amd64 \ && chmod +x /usr/local/bin/kind -# adding crd documentation tool here, since docs-build does not have golang base to create binary from go file -RUN wget -O gen-crd-api-reference-docs_linux_amd64.tar.gz https://github.com/ahmetb/gen-crd-api-reference-docs/archive/refs/tags/v0.3.0.tar.gz \ - && tar xzfv gen-crd-api-reference-docs_linux_amd64.tar.gz \ - && mkdir crd_documentation \ - && cp -r gen-crd-api-reference-docs-0.3.0/* ./crd_documentation \ - && cd crd_documentation \ - && go build \ - && cp -r * /usr/local/bin/ +# Adding CRD documentation generation tool. +RUN GOBIN=/usr/local/bin go install github.com/ahmetb/gen-crd-api-reference-docs@v0.3.0 ENV CGO_ENABLED=0 \ GO111MODULE="on" \ diff --git a/docs/api_docs/example-config.json b/docs/api_docs/example-config.json new file mode 100644 index 00000000000..298f00b64cc --- /dev/null +++ b/docs/api_docs/example-config.json @@ -0,0 +1,28 @@ +{ + "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/(api|apimachinery/pkg/apis)/", + "docsURLTemplate": "https://v1-18.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#{{lower .TypeIdentifier}}-{{arrIndex .PackageSegments -1}}-{{arrIndex .PackageSegments -2}}" + }, + { + "typeMatchPrefix": "^github\\.com/knative/pkg/apis/duck/", + "docsURLTemplate": "https://pkg.go.dev/github.com/knative/pkg/apis/duck/{{arrIndex .PackageSegments -1}}#{{.TypeIdentifier}}" + } + ], + "typeDisplayNamePrefixOverrides": { + "k8s.io/api/": "Kubernetes ", + "k8s.io/apimachinery/pkg/apis/": "Kubernetes " + }, + "markdownDisabled": false +} diff --git a/docs/api_docs/template/members.tpl b/docs/api_docs/template/members.tpl new file mode 100644 index 00000000000..a529c671647 --- /dev/null +++ b/docs/api_docs/template/members.tpl @@ -0,0 +1,48 @@ +{{ define "members" }} + +{{ range .Members }} +{{ if not (hiddenMember .)}} +
{{ fieldName . }}
+ (Members of {{ fieldName . }}
are embedded into this type.)
+
metadata
field.
+ {{ end }}
+
+ {{ if or (eq (fieldName .) "spec") }}
+ Packages:
++ {{ safe (renderComments .) }} +
+ {{ end }} + {{ end }} + + Resource Types: +
+ Generated with gen-crd-api-reference-docs
+ {{ with .gitCommit }} on git commit {{ . }}
{{end}}.
+
{{.Underlying}}
alias){{ end -}}
++ (Appears on: + {{- $prev := "" -}} + {{- range . -}} + {{- if $prev -}}, {{ end -}} + {{ $prev = . }} + {{ typeDisplayName . }} + {{- end -}} + ) +
+{{ end }} + ++ {{ safe (renderComments .CommentLines) }} +
+ +{{ with (constantsOfType .) }} +Value | +Description | +
---|---|
{{ typeDisplayName . }} |
+ {{ safe (renderComments .CommentLines) }} | +
Field | +Description | +
---|---|
+ apiVersion + string |
+
+
+ {{apiGroup .}}
+
+ |
+
+ kind + string + |
+ {{.Name.Name}} |
+