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

feat(cve): add compare cves feature for 2 images #420

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

laurentiuNiculae
Copy link
Contributor

What type of PR is this?

Which issue does this PR fix:
Closes #2152

What does this PR do / Why do we need it:

If an issue # is not available please add repro steps and logs from IPAMD/CNI showing the issue:

Testing done on this change:

Automation added to e2e:

Will this break upgrades or downgrades. Has updating a running cluster been tested?:

Does this change require updates to the CNI daemonset config files to work?:

Does this PR introduce any user-facing change?:


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

Attention: 154 lines in your changes are missing coverage. Please review.

Comparison is base (0edfe0f) 88.77% compared to head (1efbad2) 81.73%.

Files Patch % Lines
src/components/Tag/Tabs/ImageSelector.jsx 0.80% 123 Missing ⚠️
src/components/Tag/Tabs/CompareImages.jsx 48.71% 20 Missing ⚠️
src/api.js 0.00% 8 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #420      +/-   ##
==========================================
- Coverage   88.77%   81.73%   -7.05%     
==========================================
  Files          56       58       +2     
  Lines        1720     1894     +174     
  Branches      463      508      +45     
==========================================
+ Hits         1527     1548      +21     
- Misses        182      333     +151     
- Partials       11       13       +2     

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

@@ -104,6 +104,19 @@ const endpoints = {
},
allVulnerabilitiesForRepo: (name) =>
`/v2/_zot/ext/search?query={CVEListForImage(image: "${name}"){Tag Page {TotalCount ItemCount} CVEList {Id Title Description Severity Reference PackageList {Name InstalledVersion FixedVersion}}}}`,
cveDiffForImages: (minuend = {}, subtrahend = {}, { pageNumber = 1, pageSize = 3 }) => {
let imageInput = (img) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the value for the variable doesn't change, please use 'const' for declaration

@@ -104,6 +104,19 @@ const endpoints = {
},
allVulnerabilitiesForRepo: (name) =>
`/v2/_zot/ext/search?query={CVEListForImage(image: "${name}"){Tag Page {TotalCount ItemCount} CVEList {Id Title Description Severity Reference PackageList {Name InstalledVersion FixedVersion}}}}`,
cveDiffForImages: (minuend = {}, subtrahend = {}, { pageNumber = 1, pageSize = 3 }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

'minuend' and 'subtrahend' don't sound very suggestive of what the parameter represents. Is there a better name we can use perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I struggled finding a better name, minuend means "from which you subtract" and subtrahend "how much you subtract". These are the most concise terms I know but I agree that they're quite mathematical and unfriendly

Copy link
Contributor

@andaaron andaaron Mar 5, 2024

Choose a reason for hiding this comment

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

Add a comment in the JS code explaining these.

@@ -104,6 +104,19 @@ const endpoints = {
},
allVulnerabilitiesForRepo: (name) =>
`/v2/_zot/ext/search?query={CVEListForImage(image: "${name}"){Tag Page {TotalCount ItemCount} CVEList {Id Title Description Severity Reference PackageList {Name InstalledVersion FixedVersion}}}}`,
cveDiffForImages: (minuend = {}, subtrahend = {}, { pageNumber = 1, pageSize = 3 }) => {
let imageInput = (img) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we will want to reuse this imageInput function in the future for other endpoints. We should declare it outside 'cveDiffForImages'

let platform = img.platform ? `, platform: {os: ${img.platform.os}, arch: ${img.platform.arch}}` : '';
return `{repo: "${img.repo}", tag: "${img.tag}"${digest}${platform}}`;
};
let query = `/v2/_zot/ext/search?query={CVEDiffListForImages(minuend: ${imageInput(
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need for the 'query' variable, we can just return the interpolated string directly

@@ -150,6 +163,11 @@ const endpoints = {
const paginationParam = `requestedPage: {limit:${pageSize} offset:${(pageNumber - 1) * pageSize} sortBy:RELEVANCE}`;
return `/v2/_zot/ext/search?query={GlobalSearch(${searchParam}, ${paginationParam}) {Images {RepoName Tag}}}`;
},
imageSuggestionsWithPlatforms: ({ searchQuery = '""', pageNumber = 1, pageSize = 15 }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a point for this endpoint? Can we not achieve this already with the 'globalSearch'?

const [platform, setPlatform] = useState('');
const [suggestionData, setSuggestionData] = useState([]);
const [queryParams] = useSearchParams();
const search = queryParams.get('search') || '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

similar story, do we want the query string to control the value of this search component?

} else {
setInputHelpText('Image Selected');
setActivePlatformSelection(true);
let platforms = getImagePlatforms(event.selectedItem);
Copy link
Collaborator

Choose a reason for hiding this comment

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

doesn't seem like we need this variable

};

const imageSearch = (value) => {
let tag = value.split(':')[1];
Copy link
Collaborator

@raulkele raulkele Feb 18, 2024

Choose a reason for hiding this comment

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

we can use const here

if (suggestionResponse.data.data.GlobalSearch.Images) {
const suggestionParsedData = suggestionResponse.data.data.GlobalSearch.Images.map((el) => mapToImage(el));
setSuggestionData(suggestionParsedData);
setActivePlatformSelection(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

duplicate 'setActivePlatformSelection'

@@ -1,5 +1,5 @@
const hostConfig = {
auto: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

we shouldn't include dev settings in the commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants