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

support field custom documentation strings #394

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

jaypipes
Copy link
Collaborator

Adds support for extending the documentation strings for fields and setting docstrings for custom fields.

A new FieldConfig.Documentation configuration option is now supported. When present, this string extends any documentation provided for the existing field by the doc-2.json files. If no such documentation is provided by the existing field OR if the field is a custom field, the FieldConfig.Documentation configuration option is used for the field's docstring in the Go type files.

Example usage for an existing nested field (from a hypothetical ec2 generator.yaml file). The
LaunchTemplateData.HibernationOptions.Configured field has a docstring already that contains the following:

// If you set this parameter to true, the instance is enabled for hibernation.
//
// Default: false

Setting the generator.yaml file to the following:

resources:
  LaunchTemplate:
    fields:
      LaunchTemplateData.HibernationOptions.Configured:
        documentation: XXX extended docs XXX

would cause the field's Documentation string to look like this:

// If you set this parameter to true, the instance is enabled for hibernation.
//
// Default: false
//
// XXX extended docs XXX",

Issue aws-controllers-k8s/community#1223

Signed-off-by: Jay Pipes jaypipes@gmail.com

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Adds support for extending the documentation strings for fields and
setting docstrings for custom fields.

A new `FieldConfig.Documentation` configuration option is now supported.
When present, this string *extends* any documentation provided for the
existing field by the doc-2.json files. If no such documentation is
provided by the existing field OR if the field is a custom field, the
`FieldConfig.Documentation` configuration option is used for the field's
docstring in the Go type files.

Example usage for an existing nested field (from a hypothetical ec2
generator.yaml file). The
`LaunchTemplateData.HibernationOptions.Configured` field has a docstring
already that contains the following:

```
// If you set this parameter to true, the instance is enabled for hibernation.
//
// Default: false
```

Setting the `generator.yaml` file to the following:

```yaml
resources:
  LaunchTemplate:
    fields:
      LaunchTemplateData.HibernationOptions.Configured:
        documentation: XXX extended docs XXX
```

would cause the field's Documentation string to look like this:

```
// If you set this parameter to true, the instance is enabled for hibernation.
//
// Default: false
//
// XXX extended docs XXX",
```

Issue aws-controllers-k8s/community#1223

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
@ack-bot
Copy link
Collaborator

ack-bot commented Jan 27, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jaypipes
To complete the pull request process, please assign jljaco after the PR has been reviewed.
You can assign the PR to them by writing /assign @jljaco in a comment when ready.

The full list of commands accepted by this bot can be found 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

@ack-bot ack-bot requested review from jljaco and vijtrip2 January 27, 2023 22:20
@ack-bot ack-bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 27, 2023
@ack-bot
Copy link
Collaborator

ack-bot commented Jan 27, 2023

Hi @jaypipes. Thanks for your PR.

I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jaypipes
Copy link
Collaborator Author

@RedbackThomson @jljaco @a-hilaly please note the changes to comment formatting is from using go1.19 gofmt changes...

@RedbackThomson
Copy link
Contributor

I have some concerns about how unruly the generator.yaml file will become if there are going to be lots of custom fields. (cough S3). Rather, I'd prefer if we could track the documentation in a separate file and instead add pointers to that file on a per-resource level. That way documentation could stay within the apis/v1alpha1 directory? So either we could have:

resource:
  Cluster:
    documentation_file: docs/cluster.yaml

and then a apis/v1alpha1/docs/cluster.yaml file containing:

field1: >
  Multi-line
  Documentation
  Here
field2: ...

Or we could have a per-controller version of that where we define a top-level config in the generator.yaml like so:

documentation_file: docs.yaml

Then at apis/v1alpha1/docs.yaml

Cluster:
  field1: ...
Addons:
  field1: ...

@jaypipes
Copy link
Collaborator Author

I have some concerns about how unruly the generator.yaml file will become if there are going to be lots of custom fields. (cough S3). Rather, I'd prefer if we could track the documentation in a separate file and instead add pointers to that file on a per-resource level. That way documentation could stay within the apis/v1alpha1 directory? So either we could have:

resource:
  Cluster:
    documentation_file: docs/cluster.yaml

and then a apis/v1alpha1/docs/cluster.yaml file containing:

field1: >
  Multi-line
  Documentation
  Here
field2: ...

Or we could have a per-controller version of that where we define a top-level config in the generator.yaml like so:

documentation_file: docs.yaml

Then at apis/v1alpha1/docs.yaml

Cluster:
  field1: ...
Addons:
  field1: ...

@RedbackThomson I guess I see where you're coming from if the controller has a LOT of custom fields. s3-controller only actually has 4 fields though :) So not too onerous to have the docs in a single generator.yaml file IMHO.

Then again, I do like your suggestion about having a documentation_file top-level configuration option. I could also see a possible doc_from configuration option where, say for custom fields, you tell ack-generate where to find the documentation for a particular field (basically give it the Shape and Member path in the doc-2.json file to use)

@RedbackThomson
Copy link
Contributor

@RedbackThomson I guess I see where you're coming from if the controller has a LOT of custom fields. s3-controller only actually has 4 fields though :) So not too onerous to have the docs in a single generator.yaml file IMHO.

Then again, I do like your suggestion about having a documentation_file top-level configuration option. I could also see a possible doc_from configuration option where, say for custom fields, you tell ack-generate where to find the documentation for a particular field (basically give it the Shape and Member path in the doc-2.json file to use)

Both sound great! How about:

resources:
  Cluster:
    fields:
      MyCustomField:
        documentation: # Supports XOR `from_sdk` and `from_custom`
          from_sdk:
            operation: ...
            path: ...
          from_custom: ... 

@a-hilaly
Copy link
Member

I'm a bit mixed regarding using new files different than generator.yaml, but i also agree that adding documentation in the "fields" config can be super verbose, how about doing something similar to what's below?

resources:
  User:
    fields:
       newField:
          documentation:
             from: X
  Group:
     fields:
        newField:
           documentation:
              from: X

documentation:
  X: is an option that does ... # This can be reused many times (thinking resources that have similar fields like ARN etc...)
  Y: is an option that does ...

@a-hilaly
Copy link
Member

a-hilaly commented Feb 7, 2023

/ok-to-test

@ack-prow ack-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 7, 2023
@a-hilaly
Copy link
Member

/test all

@a-hilaly
Copy link
Member

/retest

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

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

👍

@ack-prow ack-prow bot added the approved label Mar 10, 2023
@RedbackThomson
Copy link
Contributor

/retest

@RedbackThomson
Copy link
Contributor

Even though I still think there should be some UX changes to this feature, I am going to merge this because I want to use it to inject deprecation notices into fields.
/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Mar 10, 2023
@ack-prow
Copy link

ack-prow bot commented Mar 10, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, jaypipes, RedbackThomson

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:
  • OWNERS [A-Hilaly,RedbackThomson,jaypipes]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-prow
Copy link

ack-prow bot commented Mar 10, 2023

@jaypipes: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ec2-controller-test 5e1b51a link unknown /test ec2-controller-test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@RedbackThomson RedbackThomson merged commit 338374e into aws-controllers-k8s:main Mar 10, 2023
ack-prow bot pushed a commit that referenced this pull request May 20, 2023
Closes aws-controllers-k8s/community#1223
Expands upon #394

Description of changes:
This pull request moves the custom GoDoc overrides from inside the `generator.yaml` file to a new, separate `documentation.yaml` file. This `documentation.yaml` file currently supports modify field GoDocs (but could be extended to modify resource GoDocs as well) in the following ways:
- Prepend: Add a comment before the existing shape ref GoDoc
- Append: Add a comment after the existing shape ref GoDoc
- Override: Completely replace the existing shape ref GoDoc

The current RDS documentation modifications are now modeled in the `documentation.yaml` like so:
```yaml
resources:
  DBClusterParameterGroup:
    fields:
      Parameters: 
        override: |
          DEPRECATED - do not use.  Prefer ParameterOverrides instead.
      ParameterOverrides: 
        append: |
          These are ONLY user-defined parameter overrides for the
          DB cluster parameter group. This does not contain default or system
          parameters.
  DBParameterGroup:
    fields:
      ParameterOverrides: 
        append: |
          These are ONLY user-defined parameter overrides for the DB parameter
          group. This does not contain default or system parameters.
```

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants