Skip to content

Allow member fields from other operations in spec #139

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

Merged

Conversation

RedbackThomson
Copy link
Contributor

Description of changes:
Allow the use of member fields contained within other API operations within a resource's spec. For example, LoggingStatus for S3 is only in the PutBucketLogging operation, but should be settable from spec.

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

@vijtrip2
Copy link
Contributor

Is this a PR in progress?
From the code changes, I could not relate how these change will allow mentioning spec fields from another operation. Can you please elaborate for me?
Also No unit tests added?

@RedbackThomson
Copy link
Contributor Author

RedbackThomson commented Jul 28, 2021

Is this a PR in progress?

Nope. This is just a small PR.

From the code changes, I could not relate how these change will allow mentioning spec fields from another operation. Can you please elaborate for me?

I want to add LoggingStatus as a spec field for S3. To do this, I would add a new field in the configuration and set the operation to PutBucketLogging with path LoggingStatus. When I go to generate this code, the generator will add the LoggingStatus field to the CRD, but the underlying go type for that field (and any of its members) are not added to the type defs. This is because this part of the generator ensures that all type defs are in the input or output of some API - but in this case PutBucketLogging is neither.

Also No unit tests added?

I don't see any unit tests for the type defs methods. Any pointers?

@vijtrip2
Copy link
Contributor

Is this a PR in progress?

Nope. This is just a small PR.

From the code changes, I could not relate how these change will allow mentioning spec fields from another operation. Can you please elaborate for me?

I want to add LoggingStatus as a spec field for S3. To do this, I would add a new field in the configuration and set the operation to PutBucketLogging with path LoggingStatus. When I go to generate this code, the generator will add the LoggingStatus field to the CRD, but the underlying go type for that field (and any of its members) are not added to the type defs. This is because this part of the generator ensures that all type defs are in the input or output of some API - but in this case PutBucketLogging is neither.

Also No unit tests added?

I don't see any unit tests for the type defs methods. Any pointers?

Thanks for explaining. We should ideally make an effort to increase test coverage of our codebase (maybe a collective effort as a team in coming sprints) but it's definitely out of scope for this PR.

LGTM. I'll let one more team member review this before merging.

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

@RedbackThomson please see my inline comment.

Also, to unit test this functionality, simply add the generator config changes you are testing out for the S3 controller's update code paths to the testdata/ generator yaml for S3:

https://github.com/aws-controllers-k8s/code-generator/blob/5a40e37032506f12a07b7de12a6005b525d13ad9/pkg/testdata/models/apis/s3/0000-00-00/generator.yaml

and add a test for the now-expected new Spec field for Logging in this unit test file:

expSpecFieldCamel := []string{

and a test for the now-expected LoggingStatus type defs in the same model_s3_test.go file. You can use the testutil.GetTypeDefByName utility function from here:

func GetTypeDefByName(

@RedbackThomson
Copy link
Contributor Author

Cleaned up unnecessary methods and added unit tests for the S3 Logging type

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.

👍

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

Bingo. ++

}
for _, typeDef := range expTypeDefCamel {
assert.NotNil(testutil.GetTypeDefByName(t, g, typeDef))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@jaypipes
Copy link
Collaborator

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 29, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Jul 29, 2021

[APPROVALNOTIFIER] This PR is APPROVED

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

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,vijtrip2]

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 merged commit 24d2344 into aws-controllers-k8s:main Jul 29, 2021
ack-bot pushed a commit to aws-controllers-k8s/s3-controller that referenced this pull request Aug 2, 2021
Adds custom hooks to detect changes to the `Logging` spec field and optionally calls the `PutBucketLogging` SDK method. Currently errors are not populated into terminal conditions, and updates are not supported.

Uses aws-controllers-k8s/code-generator#139 and aws-controllers-k8s/code-generator#140
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants