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
OCPBUGS-28856: make getGroupVersionKindForResource null safe #13574
Conversation
@rhamilto: This pull request references Jira Issue OCPBUGS-28856, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
/jira refresh |
@rhamilto: This pull request references Jira Issue OCPBUGS-28856, which is valid. The bug has been moved to the POST state. 3 validation(s) were run on this bug
Requesting review from QA contact: In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
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
No changes needed, just a couple of observations.
const apiVersion = resource?.apiVersion; | ||
const kind = resource?.kind; | ||
const apiVersionSplit = apiVersion?.split('/'); | ||
const apiVersionSplitLen = apiVersionSplit?.length; | ||
if (apiVersionSplitLen > 2) throw new Error('Provided resource has invalid apiVersion.'); |
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.
Not new, but is this check necessary? Wouldn't the API server reject resources with an invalid apiVersion
?
@@ -48,18 +48,21 @@ export const getAPIVersionForModel: GetAPIVersionForModel = (model) => | |||
* If the resource has an invalid apiVersion then it'll throw Error. |
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.
Line 47 says that this function returns group 'core' if the resource doesn't have an API group. As far as I can tell, that's not true.
export const getGroupVersionKindForResource: GetGroupVersionKindForResource = (resource) => { | ||
const { apiVersion, kind } = resource; | ||
const apiVersionSplit = apiVersion.split('/'); | ||
const apiVersionSplitLen = apiVersionSplit.length; | ||
const apiVersion = resource?.apiVersion; | ||
const kind = resource?.kind; | ||
const apiVersionSplit = apiVersion?.split('/'); | ||
const apiVersionSplitLen = apiVersionSplit?.length; | ||
if (apiVersionSplitLen > 2) throw new Error('Provided resource has invalid apiVersion.'); | ||
|
||
return { | ||
...(apiVersionSplitLen === 2 && { | ||
group: apiVersionSplit[0], | ||
}), | ||
version: apiVersionSplitLen === 2 ? apiVersionSplit[1] : apiVersion, | ||
kind, | ||
}; | ||
return !apiVersion || !kind | ||
? undefined | ||
: { | ||
...(apiVersionSplitLen === 2 && { | ||
group: apiVersionSplit[0], | ||
}), | ||
version: apiVersionSplitLen === 2 ? apiVersionSplit[1] : resource?.apiVersion, | ||
kind, | ||
}; | ||
}; |
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.
We could simplify this with a few tweaks:
export const getGroupVersionKindForResource: GetGroupVersionKindForResource = (resource) => {
const { apiVersion, kind } = resource ?? {};
if (!kind || !apiVersion) return undefined;
const [group, version, invalid] = apiVersion.split('/');
if (invalid) throw new Error('Provided apiVersion is invalid.'); // remove?
return version ? { group, version, kind } : { version: group, kind };
};
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: rhamilto, TheRealJon 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 |
@rhamilto: all tests passed! Full PR test history. Your PR dashboard. 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. I understand the commands that are listed here. |
@rhamilto: Jira Issue OCPBUGS-28856: All pull requests linked via external trackers have merged: Jira Issue OCPBUGS-28856 has been moved to the MODIFIED state. In response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
[ART PR BUILD NOTIFIER] This PR has been included in build openshift-enterprise-console-container-v4.16.0-202402060810.p0.g13f3942.assembly.stream for distgit openshift-enterprise-console. |
/cherry-pick release-4.15 |
@rhamilto: new pull request created: #13582 In response to this:
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. |
Fix included in accepted release 4.16.0-0.nightly-2024-02-07-073830 |
@rhamilto Hi, I'd like to reproduce/verify the bug, if you have example codes for the modal test like that in your demo? |
To test as shown in the video above, I added the useDeleteButton Example to the Pod details page. |
Demo:
getGroupVersionKindForResource
is now null safe and will returnundefined
ifapiVersion
orkind
areundefined
.useDeleteModal
will not work with anundefined
resource, but the run time error no longer occurs.Screen.Recording.2024-02-05.at.11.05.35.AM.mov