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

⚠️ Marker Parsing and Structure #190

Merged

Conversation

DirectXMan12
Copy link
Contributor

@DirectXMan12 DirectXMan12 commented Apr 16, 2019

This re-implements our parsing and generation logic in a more structured form.
I've tried to write up extended guides in the godoc for each new package, so check that
out until I put together a cohesive guide.

TODO:

  • a couple of documentation spots
  • design doc overview
  • better tests
  • iron out last few backwards-incompatibilities
  • support type-level schema modifications

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 16, 2019
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Apr 16, 2019
@DirectXMan12
Copy link
Contributor Author

DirectXMan12 commented Apr 16, 2019

cc @mengqiy this has both the comment extraction and marker parsing.
There's a rough example in crd/v3/cmd/main.go

@DirectXMan12 DirectXMan12 force-pushed the feature/marker-parsing branch 2 times, most recently from 133bc92 to 536a72d Compare April 24, 2019 06:17
Don't accidentally check in ViM swap files, etc.
@DirectXMan12
Copy link
Contributor Author

@redborian FYI

return err
}

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

RBAC Parser Reviewed. Looks good.

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.

Reviewing commit-by-commit.
Reviewed the marker collector/parsing, looks good, have couple of nits.

pkg/markers/doc.go Outdated Show resolved Hide resolved
pkg/markers/doc.go Outdated Show resolved Hide resolved
pkg/markers/doc.go Outdated Show resolved Hide resolved
//
// Markers can be collected from a loader.Package using a Collector. The
// Collector will read from a given Registry, collecting comments that look
// like markers and parsing them if they match some definition on the registry.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the most important part which helped me understand how all these fit together.

pkg/markers/doc.go Outdated Show resolved Hide resolved
pkg/markers/doc.go Show resolved Hide resolved
// associated.
//
// PackageMarkers can be used to fetch just package-level markers.
package markers
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent description.

pkg/markers/parse.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.

Reviewed genall and looks good to me.

pkg/genall/doc.go Outdated Show resolved Hide resolved
pkg/genall/genall.go Outdated Show resolved Hide resolved
}

p.CustomResourceDefinitions[groupKind] = crd
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Reviewed crd parsing. This is bulk of the code I guess, looks pretty good on a high level.

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.

Reviewed the controller-gen changes, looks good overall.

cmd/controller-gen/main.go 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.

reviewed dep update, have one comment about controller-runtime deps.

go.sum Outdated Show resolved Hide resolved
@droot
Copy link
Contributor

droot commented May 2, 2019

Have reviewed all the changes (except deepcopy-gen) and looks good overall, have minor comments. You can probably submit deepcopy-gen in a separate PR if you would like to get the other changes in.

@DirectXMan12 DirectXMan12 force-pushed the feature/marker-parsing branch 4 times, most recently from 00aaaa9 to 8a2a6fe Compare May 2, 2019 06:03
@DirectXMan12
Copy link
Contributor Author

Forgot webhook-gen. We'll need to make sure webhook gen works with our new plans before release -- I stripped out the parts I thought we no longer needed, but I just want to make sure.

@DirectXMan12
Copy link
Contributor Author

DirectXMan12 commented May 2, 2019

Added better tests for the low-level stuff. High-level stuff and schema operations need tests. We can follow up with those before release. Let's try and get this part merged tomorrow after I make sure all the ancillary tests pass (e.g. test project stuff), etc.

This introduces utilities for incremental/filtered package loading,
based on go/packages (the new replacement for go/build and friends
when importing).  It'll work with modules properly, too.
@DirectXMan12 DirectXMan12 force-pushed the feature/marker-parsing branch 2 times, most recently from e6adb51 to 1a9e63e Compare May 3, 2019 06:33
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.

reviewed webhook generation commit, looks reasonable to me.

//
// The markers take the form:
//
// +kubebuilder:rbac:failurePolicy=<string>,groups=<[]string>,resources=<[]string>,verbs=<[]string>,versions=<[]string>,name=<string>,path=<string>,mutating=<bool>
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: s/rbac/webhook ?

Copy link
Member

@mengqiy mengqiy May 4, 2019

Choose a reason for hiding this comment

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

s/rbac/webhook

@DirectXMan12 Please fix 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.

Reviewed testData import path commit, looks good.

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.

Looks good to me.

pkg/loader/loader.go Show resolved Hide resolved
pkg/markers/collect.go Outdated Show resolved Hide resolved
pkg/markers/doc.go Show resolved Hide resolved
//
// The markers take the form:
//
// +kubebuilder:rbac:failurePolicy=<string>,groups=<[]string>,resources=<[]string>,verbs=<[]string>,versions=<[]string>,name=<string>,path=<string>,mutating=<bool>
Copy link
Member

@mengqiy mengqiy May 4, 2019

Choose a reason for hiding this comment

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

s/rbac/webhook

@DirectXMan12 Please fix this.

//
// The markers take the form:
//
// +kubebuilder:rbac:failurePolicy=<string>,groups=<[]string>,resources=<[]string>,verbs=<[]string>,versions=<[]string>,name=<string>,path=<string>,mutating=<bool>
Copy link
Member

Choose a reason for hiding this comment

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

It seems it now requires all arguments to be in the same line. We need to remember to update the book.

This introduces a framework for collecting and parsing "marker" comments
into structured Go data, much like the "json" package.
This removed the generation and parsing logic that's being superseded
by loader, markers, etc.
This adds a generator framework that ties together running multiple
generators from the same marker data, and describe how they can
read and write artifacts.
This adds RBAC generation (as per our existing RBAC markers) on top of
the new generator framework.
This defines the framework for CRD generation, and uses markers with
that implement interfaces to modify the schema and CRD.
This implements deepcopy generation, mostly copying from deepcopy-gen
but using the generator framework.  It slightly scopes down things to
only implement parts we care about for custom types that represent CRDs.
This updates controller-gen to make use of the new generator framework.
Generators and ouput rules are treated as markers to parse commandline
options.
This adds WebhookConfig generation (as per our existing webhook markers, with
slight modifications) on top of the new generator framework.
It had an old import path pointing to the wrong place,
which causes all sorts of build failures.
Update deps to required versions.
It's no longer used by any tests.  We can always add it back in if we
need to.
Some of the enabled checkers were deprecated, had known issues, or
returned erroneous results.  They've been commented out, with comments
as to why they're not run.
@DirectXMan12
Copy link
Contributor Author

discussed with @mengqiy in person, will merge as per previous approval, then to master

@DirectXMan12
Copy link
Contributor Author

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

@DirectXMan12: you cannot LGTM your own PR.

In response to this:

/lgtm
/approve

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.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: DirectXMan12

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

@DirectXMan12 DirectXMan12 changed the title [WIP] ⚠️ Marker Parsing and Structure ⚠️ Marker Parsing and Structure May 4, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 4, 2019
@mengqiy
Copy link
Member

mengqiy commented May 4, 2019

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 4, 2019
@k8s-ci-robot k8s-ci-robot merged commit a22fb39 into kubernetes-sigs:crdgenerator May 4, 2019
@DirectXMan12 DirectXMan12 deleted the feature/marker-parsing branch May 30, 2019 22:20
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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants