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-19916: Fix MachineSetList capacity logic #13259
Conversation
TheRealJon
commented
Oct 18, 2023
- Use MachineSet label selector to find related Machine and Node.
- Address some minor issues with TypeScript, React, and style conventions.
@TheRealJon: This pull request references Jira Issue OCPBUGS-19916, which is valid. The bug has been moved to the POST state. 3 validation(s) were run on this bug
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 kubernetes/test-infra 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.
Just some clarifying comments for whoever reviews.
|
||
const { common } = Kebab.factory; | ||
const menuActions = [ | ||
editCountAction, | ||
configureMachineAutoscaler, | ||
...Kebab.getExtensionsActionsForKind(MachineSetModel), | ||
...common, | ||
...Kebab.factory.common, |
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.
Get rid of unnecessary destructuring.
export const getDesiredReplicas = (machineSet: MachineSetKind | MachineDeploymentKind) => | ||
machineSet?.spec?.replicas ?? 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.
Use implicit return shortcut consistently
resourceKind: K8sKind; | ||
resource: MachineSetKind | MachineDeploymentKind; | ||
}) => { | ||
export const MachineCounts: React.FC<MachineCountsProps> = ({ resourceKind, resource }) => { |
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.
Get rid of redundant type defs
}: { | ||
obj: MachineSetKind; | ||
}) => ( | ||
export const MachineTabPage: React.FC<MachineTabPageProps> = ({ obj }) => ( |
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.
Get rid of redundant type defs.
<MachinePage namespace={obj.metadata.namespace} showTitle={false} selector={obj.spec.selector} /> | ||
); | ||
|
||
const MachineSetDetails: React.SFC<MachineSetDetailsProps> = ({ obj }) => { | ||
const MachineSetDetails: React.FC<MachineSetDetailsProps> = ({ obj }) => { |
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.
Remove deprecated 'SFC' type
const { cpu, memory } = capacityResolver(obj); | ||
const readyReplicas = getReadyReplicas(obj); | ||
const desiredReplicas = getDesiredReplicas(obj); | ||
const instanceType = getMachineSetInstanceType(obj); |
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.
Readability nits.
const capacityResolver = React.useCallback( | ||
(obj: MachineSetKind) => { | ||
const machine = (machines ?? [])?.find((m) => { | ||
return new LabelSelector(obj.spec.selector).matches(m); | ||
}); | ||
const node = (nodes ?? []).find( | ||
(n) => machine && machine.status?.nodeRef?.uid === n.metadata.uid, | ||
); | ||
const { cpu, memory } = node?.status?.capacity ?? {}; | ||
return { | ||
cpu: convertToBaseValue(cpu) ?? 0, | ||
memory: formatBytesAsGiB(convertToBaseValue(memory) ?? 0), | ||
}; | ||
}, | ||
[getRelatedNodes, nodesLoaded], | ||
[machines, nodes], | ||
); |
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.
Use one callback to calculate memory and CPU capacity to reduce repetitive logic. We also only need one Machine and Node to determine capacity. We can use 'find' instead of 'filter', which is more efficient and simplifies the logic.
const capacityResolver = React.useCallback( | ||
(obj: MachineSetKind) => { | ||
const machine = (machines ?? [])?.find((m) => { | ||
return new LabelSelector(obj.spec.selector).matches(m); |
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.
Can't use implicit return with new
- Use MachineSet label selector to find related Machine and Node. - Address some minor issues with TypeScript, React, and style conventions.
a1ca122
to
dae2225
Compare
); | ||
|
||
// TODO (jon): Anti-pattern. This should be declared outside the MachineSetList component |
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.
Yes, but I'm guessing it was done to make i18n easier (no need to refactor).
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
Thank you for the helpful comments on the code!
[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 |
@TheRealJon: 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. |
@TheRealJon: Jira Issue OCPBUGS-19916: All pull requests linked via external trackers have merged: Jira Issue OCPBUGS-19916 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 kubernetes/test-infra repository. |
Fix included in accepted release 4.15.0-0.nightly-2023-11-03-082930 |