-
Notifications
You must be signed in to change notification settings - Fork 564
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
[RFC] tools: refactor all binary packages as library packages #2983
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
The internal directory in Go is a special directory. Any packages inside the 'internal' directory can't be imported across projects. This change exposes the 'logger' package as an exportable package. Signed-off-by: Muhammad Falak R Wani <[email protected]>
The internal directory in Go is a special directory. Any packages inside the 'internal' directory can't be imported across projects. This change exposes the 'pkggraph' as an exportable package. Signed-off-by: Muhammad Falak R Wani <[email protected]>
eb0445d
to
0583fae
Compare
Signed-off-by: Muhammad Falak R Wani <[email protected]>
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 love the clean-up done here but would it be possible to split this change into smaller chunks? It's somewhat challenging to review all of this at once while maintaining full focus.
The individual commits in the PR are the smaller changes that achieve it. |
0583fae
to
b30d3ab
Compare
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
Signed-off-by: Muhammad Falak R Wani <[email protected]>
4633033
to
202773d
Compare
ImageTag: *imageTag, | ||
} | ||
} | ||
|
||
func main() { |
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.
Please let's keep main
as the first function after the arguments and consts list - I wouldn't want to change that "convention".
app = kingpin.New("boilerplate", "A sample golang tool for Mariner.") | ||
|
||
logFile = exe.LogFileFlag(app) | ||
logLevel = exe.LogLevelFlag(app) |
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.
Why did we remove this one? I believe we were using it as a template for new tooling. If anything, we could update it now to follow your idea of organizing the tools.
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
package hello |
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.
Since we're removing this piece of code as well (and for good reasons, I believe), the commit message seems to vague. There's no indication this got removed.
"github.com/microsoft/CBL-Mariner/toolkit/tools/internal/safechroot" | ||
) | ||
|
||
type fileSignaturesWrapper struct { |
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.
Just double-checking, because it's hard to tell from the diff (this shows as a brand new file): there are no changes in the code, comments, sections or functions ordering, etc., correct? It's moved 1:1 to a new directory and we're only adding the Config
struct?
@@ -122,6 +52,27 @@ var ( | |||
signatureHandling = app.Flag("signature-handling", "Specifies how to handle signature mismatches for source files.").Default(signatureEnforceString).PlaceHolder(exe.PlaceHolderize(validSignatureLevels)).Enum(validSignatureLevels...) | |||
) | |||
|
|||
func populateSrpmPackerConfig() *srpmpacker.Config { |
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.
Similar request here and all other commits - let's keep main
as the first function.
@@ -0,0 +1,249 @@ | |||
package grapher |
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.
Typo in file name grahper.go
.
@@ -37,7 +36,7 @@ go_tool_targets = $(foreach target,$(go_tool_list),$(TOOL_BINS_DIR)/$(target)) | |||
# Common files to monitor for all go targets | |||
go_module_files = $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/go.sum | |||
go_internal_files = $(shell find $(TOOLS_DIR)/internal/ -type f -name '*.go') |
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'm curious if we still need go_internal_files
after all these changes.
} | ||
|
||
if err != nil { | ||
logger.Log.Infof("Failed to clone RPM repo. Error: %s", err) |
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.
Why are errors logged on info level now? We can go down to error and make sure the caller does the right thing or keep the original code, like what we did in other commits.
return | ||
cfg := populateImagePkgFetcherConfig() | ||
err := pkgfetcher.FetchPkgsAndCreateRepo(cfg) | ||
logger.PanicOnError(err, "Failed to save cloned repo contents") |
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.
This looks incorrect now since pkgfetcher.FetchPkgsAndCreateRepo
can fail for multiple different reasons.
// the install directory | ||
sshPubKeysTempDirectory = "/tmp/sshpubkeys" | ||
func populateImagerConfig() *imager.Config { | ||
const defaultSystemConfig = 0 |
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.
Looks like a duplicate from main
and I think you're also not using the SystemConfig
field below.
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 left a few comments. The ones I'm mostly interested in:
- It seems we're not entirely consistent in how we deal with
logger.log.Panic
. In most cases we've left them unchanged, which seems fine, since we don't want to change the logic, just refactor, but there's at least one commit where I've seen them converted tologger.log.Info
. - Related to the above comment: it's insanely difficult to go through all the changes and make sure the logic was not modified. Since the granularity of accepted changes is a whole PR, not separate commits, I'm finding it hard to maintain enough focus to feel safe about approving the whole thing. I'd strongly recommend splitting this into separate PRs to ease with te review process.
I appreciate the feedback comments. I think Yes, Let me pluck them one-by-one and try to create seperate PRs for an individual tool, using the same PR. I agree that this is a ginormous PR and reviewing it while keep full focus and not breaking anything is difficult :) Again appreciate all the reviewers spending time on this PR. |
Thanks for your understanding, @mfrw! I understand this PR is an immense amount of work on your end. It looks super helpful and IMO close to done, so I'm going to keep an eye out for your updates and help with the review as much as possible. |
Request for Comments
Closes: #2982
Merge Checklist
All boxes should be checked before merging the PR (just tick any boxes which don't apply to this PR)
./cgmanifest.json
,./toolkit/tools/cgmanifest.json
,./toolkit/scripts/toolchain/cgmanifest.json
,.github/workflows/cgmanifest.json
)./SPECS/LICENSES-AND-NOTICES/data/licenses.json
,./SPECS/LICENSES-AND-NOTICES/LICENSES-MAP.md
,./SPECS/LICENSES-AND-NOTICES/LICENSE-EXCEPTIONS.PHOTON
)*.signatures.json
filessudo make go-tidy-all
andsudo make go-test-coverage
passSummary
What does the PR accomplish, why was it needed?
In the current form, all the code in the binary packages is not re-useable to enable building on top of the great work we have.
This PR abstracts all the binary packages as library packages which can be imported in other packages as well to enable code-reuse.
The changes in this PR are 100% backward compatible and it does not break anything. To achieve this, the path of least resistance seemed
to expose a
Config
structure from the library package and pass all the relevant details that are passed asflags
.Change Log
Does this affect the toolchain?
YES
Associated issues
Links to CVEs
Test Methodology