Skip to content
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

resourcedocs: Add Anchors to inlined definitions #186

Merged
merged 4 commits into from
Jan 5, 2021

Conversation

feloy
Copy link
Contributor

@feloy feloy commented Dec 11, 2020

Inlined definitions into the Markdown generated by gen-resourcesdocs are not referenceable.

These changes adds anchors to the inlined definitions.

These changes also explicitly set fragment names for Resources.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 11, 2020
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 11, 2020
Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

It passed CI, and the intention makes sense to me.
/lgtm

{{.TypeDefinition | indent 2 | indent .Indent | indent .Indent}}
{{end}}
{{- end}}{{/* range .Fields */}}

{{range .FieldCategories}}
### {{.Name}}
### {{.Name}} {#{{.Name}}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment about why the fragment identifier is set?

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 need the set the fragment identifier if the same as the heading?
Hugo should automatically generate the anchors for the headings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my comment below,I would like to keep the original case of the heading (which is a Resource Name)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 11, 2020
@kbhawkey
Copy link
Contributor

👀

@@ -28,7 +28,7 @@ type Chapter interface {
// Section is an interface to a section of an output
type Section interface {
AddContent(s string) error
AddTypeDefinition(s string) error
AddTypeDefinition(typ string, description string) error
Copy link
Contributor

@kbhawkey kbhawkey Dec 11, 2020

Choose a reason for hiding this comment

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

nit: typ is the type?

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, as type is a reserved keyword in Go, we cannot use type as variable name

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, typ is odd. t or something else might make it more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is quite common in Go, see for example https://golang.org/pkg/go/types/

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha, interesting.

@@ -63,7 +63,6 @@ func escapeName(parts ...string) string {

// headingID returns the ID built by hugo for a given header
func headingID(s string) string {
result := strings.ToLower(s)
result = strings.ReplaceAll(result, " ", "-")
result := strings.ReplaceAll(s, " ", "-")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to normalize the heading?
I was under the impression that Hugo would do this.

Copy link
Contributor Author

@feloy feloy Dec 11, 2020

Choose a reason for hiding this comment

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

Yes, Hugo does it by default, but puts the fragment in lowercase. I would prefer to keep the original case, as these are Resource names, and I would like to use the fragment name as text to display in the api-reference shortcode: (see https://github.com/kubernetes/website/pull/23294/files#diff-4992971bcbda91c2f2374a2e62fffda3d7852174780e027070e766c62bf87ac1 )

Copy link
Contributor

Choose a reason for hiding this comment

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

I need to look at the generated pages.
Could you update the shortcode to adapt the formatting of the resource name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The shortcode has been changed in this commit: kubernetes/website@d9b18d3

The result should be visible in the paragraph https://deploy-preview-23294--kubernetes-io-master-staging.netlify.app/docs/concepts/configuration/secret/#using-imagepullsecrets (see the PodSpec API ...)

The build of the preview website fails, I can't see why

Copy link
Contributor

Choose a reason for hiding this comment

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

looking now. See this message:
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to rebase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I made a rebase to restart the tests in the meantime. Here is the commit:
kubernetes/website@99e1b41

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also get the message, but you can see the change in the api-reference.html file of this commit

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 11, 2020
{{.TypeDefinition | indent 2 | indent .Indent | indent .Indent}}
{{end}}
{{- end}}{{/* range .Fields */}}

{{range .FieldCategories}}
### {{.Name}}
### {{.Name}} {#{{.Name}}}{{/* explicitly set fragment to keep capitalization */}}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 to the comment, thanks @feloy

@kbhawkey
Copy link
Contributor

kbhawkey commented Dec 11, 2020

What happens when this code builds in CI? Are there files generated into a staging directory in this repository?
It would be great to see the generated Markdown files.
For some time now, I have wanted a way to test tooling changes by building the website with the generated output.

@kbhawkey
Copy link
Contributor

Looking at:
https://deploy-preview-23294--kubernetes-io-master-staging.netlify.app/docs/reference/kubernetes-api/workloads-resources/pod-v1/#lifecycle

And:

"io.k8s.api.core.v1.Lifecycle": {
      "description": "Lifecycle describes actions that the management system should take in response to container lifecycle events. For the PostStart and PreStop lifecycle handlers, management of the container blocks until the action is complete, unless the container process fails, in which case the handler is aborted.",
      "properties": {
        "postStart": {
          "$ref": "#/definitions/io.k8s.api.core.v1.Handler",
          "description": "PostStart is called immediately after a container is created. If the handler fails, the container is terminated and restarted according to its restart policy. Other management of the container blocks until the hook completes. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks"
        },
        "preStop": {
          "$ref": "#/definitions/io.k8s.api.core.v1.Handler",
          "description": "PreStop is called immediately before a container is terminated due to an API request or management event such as liveness/startup probe failure, preemption, resource contention, etc. The handler is not called if the container crashes or exits. The reason for termination is passed to the handler. The Pod's termination grace period countdown begins before the PreStop hooked is executed. Regardless of the outcome of the handler, the container will eventually terminate within the Pod's termination grace period. Other management of the container blocks until the hook completes or until the termination grace period is reached. More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks"
        }

Why is ,

 "terminationGracePeriodSeconds": {
          "description": "Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period will be used instead. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. Defaults to 30 seconds.",
          "format": "int64",
          "type": "integer"
        },

Found under the heading Lifecycle?
How are the fields ordered on the page for PodSpec?

@feloy
Copy link
Contributor Author

feloy commented Dec 18, 2020

Looking at:
https://deploy-preview-23294--kubernetes-io-master-staging.netlify.app/docs/reference/kubernetes-api/workloads-resources/pod-v1/#lifecycle

[...]

Found under the heading Lifecycle?
How are the fields ordered on the page for PodSpec?

Hi @kbhawkey the headings are defined in the configuration file at (1)

Note that the heading Lifecyle is different from the Lifecycle Kubernetes resource.

(1) https://github.com/kubernetes-sigs/reference-docs/blob/master/gen-resourcesdocs/config/v1.20/fields.yaml#L22

@feloy
Copy link
Contributor Author

feloy commented Dec 18, 2020

What happens when this code builds in CI? Are there files generated into a staging directory in this repository?
It would be great to see the generated Markdown files.
For some time now, I have wanted a way to test tooling changes by building the website with the generated output.

The changes are not visible in this repo, but you can see the changes in the PR (1), especially in the commits (2) and (3)

(1) kubernetes/website#23294
(2) kubernetes/website@7c4fc1c
(3) kubernetes/website@dffa264

@kbhawkey
Copy link
Contributor

kbhawkey commented Dec 18, 2020

Looking at:
https://deploy-preview-23294--kubernetes-io-master-staging.netlify.app/docs/reference/kubernetes-api/workloads-resources/pod-v1/#lifecycle
[...]
Found under the heading Lifecycle?
How are the fields ordered on the page for PodSpec?

Hi @kbhawkey the headings are defined in the configuration file at (1)

Note that the heading Lifecyle is different from the Lifecycle Kubernetes resource.

(1) https://github.com/kubernetes-sigs/reference-docs/blob/master/gen-resourcesdocs/config/v1.20/fields.yaml#L22

Hi @feloy
OK, this is what I thought. I found it confusing to use a Kubernetes object name as a heading if the fields under that heading do not represent the object's fields. Compare this representation to fields such as affinity, which refer/resolve to the Affinity object.
With the Affinity field, the sub-fields are in-lined below the field name but the reader does not get a hint that Affinity is an actual object (could use a link as well as inlining the object definition?).
See "$ref": "#/definitions/io.k8s.api.core.v1.Affinity",. Is there a common definition for Affinity? I see that there are common definitions for NodeAffinity, PodAffinity, and so on.
Another example is the tolerations field (array of Toleration), "$ref": "#/definitions/io.k8s.api.core.v1.Toleration".

Conversely, the initContainers and containers fields are not in-lined in PodSpec but are linked to the Container object,
initContainers ([]Container).

How did you select the text for the sub-headings? Would it help to list the fields alphabetically?
What are the headings Alpha level, Beta level, Deprecated? Does this mean that the fields under these heading are not GA?

I am reviewing this page:
https://deploy-preview-23294--kubernetes-io-master-staging.netlify.app/docs/reference/kubernetes-api/workloads-resources/pod-v1/#PodSpec

  • It think it would help provide a link for every field. If the fields used headings (instead of a list), then Hugo would add anchors. The generator could add anchors relative to the main headings on the page.
  • I noticed that some links in the text are not normalized. See the readinessGates field in PodSpec,
    https://git.k8s.io/enhancements/keps/sig-network/0007-pod-ready%2B%2B.md
  • Should the reference separate out fields that are deprecated, such as PodSpec.serviceAccount:
     "serviceAccount": {
           "description": "DeprecatedServiceAccount is a depreciated alias for ServiceAccountName. Deprecated: Use serviceAccountName instead.",
           "type": "string"
         },
    

@kbhawkey
Copy link
Contributor

kbhawkey commented Dec 20, 2020

Should I log an issue (to update a template) for separating the resource description (that contains a list) from the list of fields?
Possibly add a separator between the top description and the body of the resource (fields). Otherwise, the two lists blend together.

For example, StatefulSet:

StatefulSet represents a set of pods with consistent identities. Identities are defined as:

    * Network: A single stable DNS and hostname.

    * Storage: As many VolumeClaims as requested. The StatefulSet guarantees that a given network identity will always map to the same storage identity.

https://deploy-preview-23294--kubernetes-io-master-staging.netlify.app/docs/reference/kubernetes-api/workloads-resources/stateful-set-v1/#StatefulSet

@feloy
Copy link
Contributor Author

feloy commented Dec 20, 2020

Yes, please create an issue for this problem, I didn't see this problem before.

@kbhawkey
Copy link
Contributor

Some more thoughts about intra-page links:

It would be useful to link to any field in an object or resource from another page.
Right now, the fields are list items and a heading serves as the link to the set of fields contained under a heading.
These headings are not directly related to other k8s objects/resources but instead represent configurable categories per page.

What do you think about creating links for each field/list item?
The categories help divide the page and add navigable content, but it is not clear that the names of the categories help in understanding the object hierarchy and information about the fields.

@kbhawkey
Copy link
Contributor

Yes, please create an issue for this problem, I didn't see this problem before.

👍 See issue #188.

@feloy
Copy link
Contributor Author

feloy commented Dec 20, 2020

Some more thoughts about intra-page links:

It would be useful to link to any field in an object or resource from another page.
Right now, the fields are list items and a heading serves as the link to the set of fields contained under a heading.
These headings are not directly related to other k8s objects/resources but instead represent configurable categories per page.

What do you think about creating links for each field/list item?
The categories help divide the page and add navigable content, but it is not clear that the names of the categories help in understanding the object hierarchy and information about the fields.

Yes, I agree.
When I updated the links in the Concepts and Tasks sections to the new API reference, I realized lots of links were targeting specific fields. For the moment, I made the links target the category to which the field belongs, but it would be nice to have targetable fields.

@feloy
Copy link
Contributor Author

feloy commented Dec 29, 2020

I'm not sure, is there something to do on my side for this PR?

@kbhawkey
Copy link
Contributor

kbhawkey commented Jan 5, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 5, 2021
@kbhawkey
Copy link
Contributor

kbhawkey commented Jan 5, 2021

Thanks @feloy .
Reviewed generated files in kubernetes/website@7c4fc1c
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feloy, kbhawkey

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 5, 2021
@k8s-ci-robot k8s-ci-robot merged commit 6d86d27 into kubernetes-sigs:master Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants