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

Add a resource reference generator #50515

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ptgott
Copy link
Contributor

@ptgott ptgott commented Dec 20, 2024

Closes #16948
Closes #9949

Implements RFD 130.

See the included README for information about how the generator works.

This implementation breaks from RFD 130 in the following ways:

  • The reference includes separate pages for dynamic resources in order to make it easier to read.
  • The generator specifies the kind and version of each dynamic resource. To do this, the generator looks up a method called for each resource type to assign the type's version and kind.
  • The generator uses a YAML configuration file. This is because the config ended up including more fields than specified in the RFD, so separating the config from the source made sense to give users less noise to deal with.
  • In the example YAML blocks and type table values, leave types empty if we can't process them.

Edit the RFD:

  • Be less specific about the output template so this isn't wedded to implementation details.
  • Remove the description of example YAML delimiters. These are no longer viable, as we maintain several documentation generators that extract comments from the source.

@public-teleport-github-review-bot

@ptgott - this PR will require admin approval to merge due to its size. Consider breaking it up into a series smaller changes.

Copy link

🤖 Vercel preview here: https://docs-771hg03b4-goteleport.vercel.app/docs

@ptgott
Copy link
Contributor Author

ptgott commented Dec 20, 2024

Reviewer note: this PR doesn't include generated docs, since that would make the diff even larger than it is now.

Closes #16948
Closes #9949

Implements RFD 130.

See the included README for information about how the generator works.

This implementation breaks from RFD 130 in the following ways:

- The reference includes separate pages for dynamic resources in order
  to make it easier to read.
- The generator specifies the kind and version of each dynamic resource.
  To do this, the generator looks up a method called for each resource
  type to assign the type's version and kind.
- The generator uses a YAML configuration file. This is because the
  config ended up including more fields than specified in the RFD, so
  separating the config from the source made sense to give users less
  noise to deal with.
- In the example YAML blocks and type table values, leave types empty if
  we can't process them.

Edit the RFD:

- Be less specific about the output template so this isn't wedded to
  implementation details.
- Remove the description of example YAML delimiters. These are no longer
  viable, as we maintain several documentation generators that extract
  comments from the source.
@ptgott ptgott force-pushed the paul.gottschling/2024-12-9949-resources branch from 145bf35 to 04d814b Compare December 24, 2024 13:58
Copy link

github-actions bot commented Dec 24, 2024

Amplify deployment status

Branch Commit Job ID Status Preview Updated (UTC)
paul.gottschling/2024-12-9949-resources HEAD 1 ✅SUCCEED paul-gottschling-2024-12-9949-resources 2024-12-24 14:06:20

Copy link
Collaborator

@zmb3 zmb3 left a comment

Choose a reason for hiding this comment

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

Seems reasonable, I'll have to test it out soon!


// Intended to be executed with a ReferenceContent.
// Ampersands are replaced with backticks.
var referenceTemplate string = strings.ReplaceAll(`---
Copy link
Collaborator

Choose a reason for hiding this comment

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

Alternatively, we could avoid the awkward strings.ReplaceAll and &&& by putting the contents of this template in a file and pulling it into a string via //go:embed.

"golang.org/x/tools/go/ast/astutil"
)

// Package is used to look up a Go declaration in a map of declaration names to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Package is used to look up a Go declaration in a map of declaration names to
// PackageInfo is used to look up a Go declaration in a map of declaration names to

`

func main() {
conf := flag.String("config", "./conf.yaml", configHelp)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
conf := flag.String("config", "./conf.yaml", configHelp)
conf := flag.String("config", "conf.yaml", configHelp)

pc.Resource.Version = verName

filename := strings.ReplaceAll(strings.ToLower(pc.Resource.SectionName), " ", "-")
doc, err := destFS.Create(path.Join(conf.DestinationDirectory, filename+".mdx"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be filepath.Join, or does the afero FS take care of that for you?

errs.messages = append(errs.messages, err)
}

if err := template.Must(template.New("Main reference").Parse(referenceTemplate)).Execute(doc, pc); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would parse the template once outside of the loop (potentially even in an init func) and then reuse it here. Otherwise we're wasting time re-parsing the same template multiple times.

@@ -69,6 +69,8 @@ require (
sigs.k8s.io/yaml v1.4.0 // indirect
)

require github.com/spf13/afero v1.9.2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this up into the main require block. (The go tool doesn't do this for you sometimes, but you can just move the line manually)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation rfd Request for Discussion size/xl
Projects
None yet
2 participants