gen-apidocs: include create-only resources in the generated ToC #473
Welcome @abhinav-phi! <br><br>It looks like this is your first PR to <a href='https://github.com/kubernetes-sigs/reference-docs'>kubernetes-sigs/reference-docs</a> 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval. <br><br>You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation. <br><br>You can also check if kubernetes-sigs/reference-docs has its own contribution guidelines. <br><br>You may want to refer to our testing guide if you run into trouble with your tests not passing. <br><br>If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs! <br><br>Thank you, and welcome to Kubernetes. :smiley:
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/reference-docs/pull/473#" title="Author self-approved">abhinav-phi</a>
Once this PR has been reviewed and has the lgtm label, please assign natalisucks for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":["natalisucks"]} -->
The first sentence is now the opposite of what the function does, and Binding (a pods/binding subresource) gets promoted by this change, so the "as opposed to a subresource" part doesn't hold either.
// IsTopLevelResource reports whether this definition is a top-level API
// resource, as opposed to a utility type (Status, WatchEvent) or a field type
// that never appears on the wire by itself.
//
// A List endpoint is the usual marker, but create-only resources such as
// TokenRequest and the SubjectAccessReview family qualify too.
There is no need for this extra loop.
This can be one pass instead of walking OperationCategories twice, same conditions, same result:
for _, c := range d.OperationCategories {
if c == nil {
continue
}
for _, op := range c.Operations {
if op == nil {
continue
}
switch c.Name {
case "Read Operations":
if op.Type.Name == "List" || op.Type.Name == "List All Namespaces" {
return true
}
case "Write Operations":
if op.Type.Name == "Create" {
return true
}
}
}
}
return false
Now that the category is attached and buildGroupBasedCategories marks the definition, this line is redundant and it's the other half of what broke TokenRequest in the first place: it told writeDefinitions to skip the page while the missing category kept it out of the ToC, so it fell through both. Worth dropping so the fix reads on its own.
nit: Since you're here, this XXX: reads like a bug marker but it's just describing the operation ID. Something like "TokenRequest is created through a ServiceAccount subresource, so its operation ID doesn't follow the ${group}${version}${resource} pattern the generic matcher below uses" would save the next person a detour
Nice find, the dropped OperationCategory is easy to miss. I reproduced your result on the v1.37 spec: both groups come back, 162 pages either way.
Have you copied the output into k/website and built it locally?
Mine failed with 18 REF_NOT_FOUND errors. Three of the admission-policy pages relref the definitions/ pages you're removing, so the website change needs to go in at the same time as this one.
While you're there, look at the page you just created, authentication/token-request-v1.md. Its request body and all three responses link to the CSI driver page instead of to itself. There are two different TokenRequest kinds, authentication.v1 and storage.v1, and the link map in markdown.go is keyed on the kind name alone, so one overwrites the other. Same thing makes Pod's eviction op point at the wrong Eviction today. So this needs a fix in markdown.go as well. That can be a follow-up PR, but please hold this one until it lands.
Last thing: the golden tests pass on your base. That golden came in with #460, which you're already on, so that note in the description can go.
Left a few smaller things inline.
Thanks @Caesarsage for the quick review and for reproducing it on the v1.37 spec — all four suggestions are applied in 9cecf0f:
IsTopLevelResource is now a single pass with a switch, and the doc comment no longer claims List-only resources are excluded (I re-verified the regenerated output after the rework: authentication/ and authorization/ still come out with the same pages, and Binding is still promoted to a resource page, consistent with the v1.35 docs where workload-resources/binding-v1 existed).o.Definition.InToc = true — agreed, attaching the category is what places the definition, and the stray flag was exactly what made TokenRequest fall through both writeDefinitions and the ToC before.XXX: comment to explain the operation-ID mismatch.To answer your question: I did not copy the output into k/website and build it there. Two reasons:
1. Format drift between reference-docs master and the site. The content committed on kubernetes/website main still matches the hugo-md output as of the backend switch (May 13): import: string front matter, HTML tables, no preamble shortcodes. Master's output today (after 31032f6) emits code_import:, {{< api-object-preamble >}} and friends — and none of those shortcodes are defined in kubernetes/website's layouts (or docsy), so pasting master-format pages today would break the Hugo build. I checked this while preparing the link-repair PR (kubernetes/website#57414), which fixes the 16 stranded inbound links in the meantime; the full page restore should ride the next scheduled regen once the shortcode templates land on the site side (issue #440 territory).
2. A pre-existing nondeterminism I hit while diffing runs (not from this change — reproduces on master without it, verified by stashing): two consecutive runs of --backend=hugo-md can differ in the core vs events category weights (130/140 swap in _index.md front matter) and in the ref-link disambiguation of the colliding event-v1.md filenames ({{< ref "event-v1#Event" >}} vs {{< ref "../events/event-v1#Event" >}} in core/event-v1.md). Looks like a map-iteration-order dependency in the link map / weight assignment when two groups have same-named filenames. Worth a follow-up issue since it will make every website regen PR noisy — happy to file and take a stab at it if you agree.
@Caesarsage all four of your suggestions are applied in 9cecf0f (single-pass switch + corrected doc comment, redundant InToc dropped, XXX: comment reworded). I re-ran --backend=hugo-md on the v1.36 spec after the rework — authentication/ and authorization/ still emit with the same page set as before, so behavior is unchanged.
Could I ask for a re-review when you have a moment? Happy to iterate on anything else.
Hi @Caesarsage, a consolidated update since the re-review request, with one correction from my side.
First, the golden-test caveat in the PR notes was inaccurate as worded, so I have corrected it in the description rather than leaving it. I ran TestWriteOperationGolden and TestWriteOperationGoldenHugoMode locally against both the merge-base and this PR head: both pass identically in both states, so no golden refresh is needed here. Whatever failure I saw earlier does not reproduce against current master, and I did not want a stale caveat confusing reviewers.
Second, two items from my earlier note still sit outside this PR. The colliding event-v1.md ref-link nondeterminism I reported has no follow-up issue and no owner; I offered to file and attempt it, but only if you agree, so please tell me whether you want that filed (by me or someone else) or left alone. On the website side, the link-repair PR (kubernetes/website#57414) and the shortcode-templates track (issue #440) are both still open, so the coordinated regen and any website build validation remain blocked behind those and cannot be completed from here.
Nothing in the code changed with this update. Could I ask for a re-review when you have a moment? Happy to iterate on anything else.
hi @Caesarsage @natalisucks, friendly nudge.. all four of your suggestions from the sep 6 review went into 9cecf0f and nothing has changed since. could you re review when you have a moment?
applied in 9cecf0f68, definition.go:337-342 is your suggested block, the as opposed to a subresource clause is gone
applied in 9cecf0f68, definition.go:343-365 is the single pass with the switch, no second walk of OperationCategories
applied in 9cecf0f68, the InToc line is deleted from the TokenRequest case, config.go:842 only attaches the category now
applied in 9cecf0f68, config.go:819-821 carries your rewording and no XXX: is left in either file
Well, TokenRequest isn't a top level resource. SubjectAccessReview is, though (and is already documented at https://kubernetes.io/docs/reference/kubernetes-api/definitions/subject-access-review-v1-authorization/).
I think SubjectAccessReview could move to https://kubernetes.io/docs/reference/kubernetes-api/authorization/subject-access-review-v1-authorization/ because it is in the authorization.k8s.io API group.
TokenRequest isn't top-level, so don't attach the category here. Keep the InToc removal so it still lands in definitions/.
// A List endpoint is the usual marker, but create-only resources such as
// TokenReview and the SubjectAccessReview family qualify too.
+1 to @lmktfy. TokenRequest is the body of the serviceaccounts/token subresource, not a resource of its own, so it should stay in definitions/. Two small changes inline. Please check that TokenRequest still gets a page in definitions/ after them.
With that change, this PR no longer causes the TokenRequest link collision, so I'll track the markdown.go fix separately rather than block on it.
dropped the append in 0f2064c, both comment lines with it. the InToc removal stays so TokenRequest still lands in definitions/.
ran the generator on the v1.36 spec at both heads rather than assume it. before, TokenRequest came out as authentication/token-request-v1.md. now it is definitions/token-request-v1-authentication.md, so it does keep a definitions page. authentication/ goes from four resource pages to three, authorization/ is unchanged.
one cost though, and I would rather put it in front of you than decide it myself. the definitions page carries the object type and spec and status but no api operations section, so the POST /api/v1/namespaces/{namespace}/serviceaccounts/{name}/token call ends up documented nowhere in the output. nothing picks it up as an orphaned operation either. that follows directly from keeping TokenRequest off the top level classification.
took the suggestion text in 0f2064c, the comment names TokenReview now.
on SubjectAccessReview, it already comes out under authorization/ once the classification fix lands, so authorization/ gets subject-access-review-v1.md, local-subject-access-review-v1.md, self-subject-access-review-v1.md and self-subject-rules-review-v1.md. If you meant moving it somewhere past that, tell me and I will do it here or as a follow up.
the open question is where TokenRequest itself should sit, since the answer here and the one on website#57313 point different ways. I have put both readings on that issue and will build whichever gets picked.
friendly ping @lmktfy @Caesarsage — i addressed all four suggestions from sep 6 plus the TokenRequest placement question in the oct 16 commits. happy to rebase onto master if that helps. thanks.
Caesarsage
abhinav-phi
Problem
With
--auto-detect,IsTopLevelResourceonly recognized definitions that have a List operation ("Read Operations" category,List/List All Namespaces). Resources that only support Create were therefore never classified as top-level, andbuildGroupBasedCategoriesdropped them entirely — their API group's category/directory and per-resource pages were never emitted.This silently dropped two whole groups from the generated navigation (kubernetes/website#57313):
authentication.k8s.io: TokenRequest, TokenReview, SelfSubjectReviewauthorization.k8s.ioreview types: SubjectAccessReview, LocalSubjectAccessReview, SelfSubjectAccessReview, SelfSubjectRulesReviewBoth groups are listed on the generated
group-versions.mdpage but had no pages. Up to the v1.35 docs these pages existed (e.g./docs/reference/kubernetes-api/authentication-resources/token-request-v1/); the migration to the markdown backend removed them because the generator no longer produced them. Verified against the v1.36 spec: baseline run produces noauthentication/orauthorization/directory.Fix
1.
IsTopLevelResourcealso accepts a top-level Create operation ("Write Operations" category,Createtype) as evidence of a top-level resource.2. In the
TokenRequestspecial case (its operation iscreateCoreV1NamespacedServiceAccountToken, mapped inmapOperationsToDefinitions),o.Typeis now set so the typed operation is recorded, but the write category is deliberately not appended tod.OperationCategories.IsTopLevelResourcetherefore does not see the Create operation, and TokenRequest keeps adefinitions/page instead of becoming an authentication resource page.Result
With
--auto-detect --backend=hugo-mdon the v1.36 spec:authentication/:_index.md,token-review-v1.md,self-subject-review-v1.md(TokenRequest stays ondefinitions/token-request-v1-authentication.md)authorization/:_index.md,subject-access-review-v1.md,local-subject-access-review-v1.md,self-subject-access-review-v1.md,self-subject-rules-review-v1.mdmatching the per-group structure of the other groups. The group
_index/weights of existing groups shift by two steps (Authentication and Authorization now occupy their alphabetical slots); all page content of existing resources is unchanged.Notes
make apimd-hugo && copyapimdrestores the missing group directories. The new resource pages forauthentication/authorizationland incontent/en/docs/reference/kubernetes-api/authentication/and.../authorization/.Known gap this leaves
Running the generator at this head shows the
POST /api/v1/namespaces/{namespace}/serviceaccounts/{name}/tokenoperation is not documented anywhere in the output: the definitions page for TokenRequest carries the object type and its spec and status fields but no API operations section, and no orphaned-operations page picks the endpoint up. It is a consequence of keeping TokenRequest off the top-level classification, so it is raised here rather than fixed silently. Happy to take whichever shape is agreed.AI assistance
This PR description was revised with the assistance of generative AI. The code change is mine and I have read every line of the diff.