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 flags to customize API path and contexts #144

Merged
merged 1 commit into from
Feb 25, 2019

Conversation

damemi
Copy link
Contributor

@damemi damemi commented Feb 13, 2019

We have some use cases where API types are defined in a different package or location than the default pkg/apis currently hardcoded. For example, we have vendored types in an API library that correspond to CRDs in multiple different repos; this would allow us to establish a workflow such as

  1. Update API types in library
  2. Bump that library in specific CRD repos
  3. Generate new CRDs in those repos (wherein those types exist under, eg, vendor/org/library/some-api/v1/)

By specifying a known directory and context, we can still use this tool with only minor changes (the optional flags added in this PR) and this gives us more ability to customize it to our use cases.

I'm aware that we could accomplish something similar with --output-dir, by going in the opposite direction and running this tool from our API library while specifying the output as those specific repos. But I think controlling the CRD updates from each repo itself couples the CRD update with the corresponding, necessary dependency bump well.

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

damemi commented Feb 13, 2019

If I'm way out of left field with this, I am totally open to course corrections. I'm still figuring this tool out totally

@damemi damemi force-pushed the vendor-pkg branch 3 times, most recently from 38b5027 to 91f29b6 Compare February 13, 2019 16:31
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 13, 2019
Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

comments inline

cmd/crd/cmd/generate.go Outdated Show resolved Hide resolved
cmd/crd/cmd/generate.go Outdated Show resolved Hide resolved
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Change seems reasonable to me, some minor comments.

cmd/crd/cmd/generate.go Outdated Show resolved Hide resolved
cmd/crd/cmd/generate.go Outdated Show resolved Hide resolved
@damemi
Copy link
Contributor Author

damemi commented Feb 19, 2019

@droot @DirectXMan12 I've updated this PR, could either of you please take another look at this?

@damemi
Copy link
Contributor Author

damemi commented Feb 25, 2019

bump, any more feedback on this?

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, looks good except a minor change.

@@ -112,7 +109,7 @@ func (c *Generator) Do() error {
return fmt.Errorf("failed switching working dir: %v", err)
}

if err := b.AddDirRecursive("./pkg/apis"); err != nil {
if err := b.AddDirRecursive(fmt.Sprintf("./%s", c.APIsPath)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is always relative, then we should update the help text for api-path commandline param to reflect that.

I wish filepath.Join(".", c.APIsPath) worked for this case, but looks like doesn't.

nit: probably "./" + c.APIsPath reads better in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@droot updated

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

minor nit, otherwise looks good

please add a comment somewhere explaining why apis-path and apis-pkg being different are useful.

@@ -112,7 +109,7 @@ func (c *Generator) Do() error {
return fmt.Errorf("failed switching working dir: %v", err)
}

if err := b.AddDirRecursive("./pkg/apis"); err != nil {
if err := b.AddDirRecursive("./%s" + c.APIsPath); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

"path/filepath".Join is probably safer here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that drops the leading ./ :(

@droot droot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 25, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: damemi

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

@droot droot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 25, 2019
@droot
Copy link
Contributor

droot commented Mar 13, 2019

@damemi I think this introduced regression #148 Can you pl. provide a fix ? (master branch is unusable because of that)

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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants