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

refactor: patch with context #732

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

MiahaCybersec
Copy link
Contributor

Closes #723

Miaha Cybersec and others added 9 commits July 29, 2024 16:15
Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

Attention: Patch coverage is 32.43243% with 75 lines in your changes missing coverage. Please review.

Project coverage is 49.35%. Comparing base (10fd0c7) to head (c1edca8).

Files Patch % Lines
pkg/patch/patch.go 32.43% 75 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #732      +/-   ##
==========================================
+ Coverage   47.46%   49.35%   +1.88%     
==========================================
  Files          18       18              
  Lines        1677     1702      +25     
==========================================
+ Hits          796      840      +44     
+ Misses        826      805      -21     
- Partials       55       57       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Copy link

@RobertKielty RobertKielty left a comment

Choose a reason for hiding this comment

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

@MiahaCybersec I have submitted some review comments on the tests and code.

This is good work that will make it easier for the Copa project to on-board new contributors, well done!

My requested changes are largely around improving the story telling around how copa works which will benefit both early adopting end-users and new contributors.

I have one question on the TrivyOpts and why that include non-trivy related fields (there's a bk client in there)

The most important thing to do with work like this is to test it extensively and ensure that no behaviour has changed as a result of the submitted changes.

pkg/patch/patch.go Outdated Show resolved Hide resolved
pkg/patch/patch.go Outdated Show resolved Hide resolved
pkg/patch/patch.go Show resolved Hide resolved
pkg/patch/patch.go Outdated Show resolved Hide resolved
@@ -291,3 +298,228 @@ func TestGetOSVersion(t *testing.T) {
})
}
}

func TestGeneratePatchedTag(t *testing.T) {

Choose a reason for hiding this comment

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

I like this test!

It is easy to understand from having worked with you this.

That test names could be even more explicit so as to differentiate between two types of tag that we are considering here in this test.

We have two tags

  1. The user-supplied tag which leaves a breadcrumb indicating that the image was patched by copa
  2. The imagename tag which appears at the end of the image

If you use ImageTag and UserSuppliedTag in the test names a new contributor (or a curious end-user) would more easily understand this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the test case we are only supplying a user patched tag, which can either be empty "", or supplied "example-supplied-tag". The differentiation is done within the function itself, not the parameters being passed in.

This is why for some of the test cases, an empty string is passed in but the expected result contains defaultPatchedTagSuffix

pkg/patch/patch_test.go Show resolved Hide resolved
…tion

Extracted BuildKit client configurations from TrivyOpts into a new BkClient struct. Updated related functions and tests to accommodate this change, improving modularity and readability.

Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
pkg/patch/patch.go Outdated Show resolved Hide resolved
pkg/patch/patch_test.go Show resolved Hide resolved
pkg/patch/patch_test.go Show resolved Hide resolved
pkg/patch/patch.go Outdated Show resolved Hide resolved
Miaha Cybersec and others added 2 commits August 14, 2024 09:45
Renamed the `TrivyOpts` struct to `ScannerOpts` to better reflect its purpose. Added an explicit channel parameter `ch` for error handling throughout the functions to improve code clarity and maintainability. Added new test cases to cover scenarios with digest-referenced Docker images.

Signed-off-by: Miaha Cybersec <MiahaCybersec@gmail.com>
Signed-off-by: Miaha <143584635+MiahaCybersec@users.noreply.github.com>
@ashnamehrotra
Copy link
Contributor

LGTM, will wait to merge. @MiahaCybersec @RobertKielty and I discussed adding canary testing before merging large changes.

@MiahaCybersec
Copy link
Contributor Author

Changing PR to draft until it gets further review 👍

@MiahaCybersec MiahaCybersec marked this pull request as draft August 21, 2024 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

[REQ] Refactor patchWithContext()
3 participants