-
Notifications
You must be signed in to change notification settings - Fork 102
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
Refactored packages
#1047
Refactored packages
#1047
Conversation
Summary: `packages` package (!) has been restructured to better separate the underlying concerns. The new structure looks like following: ``` pkg/kudoctl/packages/ ├── reader │ ├── parser.go │ ├── read_dir.go │ ├── reader.go │ ├── reader_tar.go │ └── reader_test.go ├── resolver │ ├── resolver.go │ ├── resolver_local.go │ ├── resolver_local_test.go │ ├── resolver_test.go │ └── resolver_url.go ├── writer │ ├── writer_tar.go │ └── writer_test.go ├── testdata │ └── ... ├── types.go └── package.go ``` **tl;dr:** - methods and files has been split across three concerns: `reader`, `writer` and `resolver` - `finder` got renamed to `resolver`: it doesn't so much search for packages as it does resolving passed package name to an underlying location - eliminated code duplication e.g. `util/kudo/resources.go` was reimplementing what resolver is doing - all the types now live in `packages/types.go` and are addressed with package prefix e.g. `packages.Files`. This allowed to shorten type names. - moved other methods to where they were used e.g. new `digest.go` is living in the `repo` now - `install.go` and `upgrade.go` commands are now using the `resolver` directly
bad := ` | ||
apiVersion: kudo.dev/v1beta1 | ||
parameters: | ||
- oops: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun fact: bad
test case was throwing an error, but not for the reason assumed in this test. - oops
is simply ignored by the unmarshaller since it is an unknown field, however it has \t
in front of it instead of spaces and that's what was causing an error! I removed this test case since all params fields are currently omitempty
and hence there is no real bad case to test.
Most of the code changes in this PR are non-functional: a lot of code was reshuffled, methods renamed, code duplication eliminated. Biggest functional change:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is almost unreal to review on github so I recommend everyone just opening IDEA and going through the package there. I have some small nits to the internal structure of some files but I have postponed that until we merge this, since this is about the overall structure of the package and I absolutely love that direction 👏
I have just one general suggestion/question. As I understand it, you have package "name" as a string, so you pass it to resolver (which is url, local or repo). What do you think about hiding a reader package into resolvers? What I am thinking is something along these lines:
- resolver
-- file
--- basically contents of reader package
-- url
--- url.go
-- repo
--- repo.go
That way we have three resolvers all packaged under resolver package
Both packages, while working closely together have different purposes IMHO. (1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great and super useful refactoring. This will help solve potential circular package reference issues in further refactoring. Some small suggestions regarding some names here.
I am not sure I agree but maybe I am missing something. I see resolver as the most top-level object. It resolves a package from string, that string can be url, it can be a local file or name in the repo. If it is a local file, it calls reader.Read() so in my mind, the file reader is just one implementation of the resolver. Right now, the localFinder (which I still think should be a local resolver) does not do anything else than call It's not a big issue though :) it makes sense to me that way but I won't be blocking this PR on that. |
ah, I'm starting to see what you mean. The |
...however, when trying to do so, it created circular dependencies. Maybe we could improve on it in a followup PR. |
…r` to `OperatorFile`
…esolve` since that's what resolver is supposed to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but please check if the integration test failure is a new flake or caused by the latest changes.
which holds all the methods related to resolving a package in a repo. This is a minor followup cleanup PR to #1047.
which holds all the methods related to resolving a package in a repo. This is a minor followup cleanup PR to #1047.
Summary:
packages
package (!) has been restructured to better separate the underlying concerns. The new structure looks like following:tl;dr:
reader
,writer
andresolver
finder
got renamed toresolver
: it doesn't so much search for packages as it does resolving passed package name to an underlying location (ulr, local)util/kudo/resources.go
was reimplementing what resolver is doingpackages/types.go
and are addressed with package prefix e.g.packages.Files
. This allowed shortening type names.digest.go
is living in therepo
nowinstall.go
andupgrade.go
commands are now using theresolver
directly