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

OCPBUGS-19916: Fix MachineSetList capacity logic #13259

Merged
merged 1 commit into from Nov 2, 2023

Conversation

TheRealJon
Copy link
Member

  • Use MachineSet label selector to find related Machine and Node.
  • Address some minor issues with TypeScript, React, and style conventions.

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Oct 18, 2023
@openshift-ci-robot
Copy link
Contributor

@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
  • bug is open, matching expected state (open)
  • bug target version (4.15.0) matches configured target version for branch (4.15.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

  • Use MachineSet label selector to find related Machine and Node.
  • Address some minor issues with TypeScript, React, and style conventions.

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.

@openshift-ci openshift-ci bot added component/core Related to console core functionality kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 18, 2023
Copy link
Member Author

@TheRealJon TheRealJon left a 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.

Comment on lines 101 to +106

const { common } = Kebab.factory;
const menuActions = [
editCountAction,
configureMachineAutoscaler,
...Kebab.getExtensionsActionsForKind(MachineSetModel),
...common,
...Kebab.factory.common,
Copy link
Member Author

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.

Comment on lines +112 to +113
export const getDesiredReplicas = (machineSet: MachineSetKind | MachineDeploymentKind) =>
machineSet?.spec?.replicas ?? 1;
Copy link
Member Author

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 }) => {
Copy link
Member Author

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 }) => (
Copy link
Member Author

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 }) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Remove deprecated 'SFC' type

Comment on lines +360 to +363
const { cpu, memory } = capacityResolver(obj);
const readyReplicas = getReadyReplicas(obj);
const desiredReplicas = getDesiredReplicas(obj);
const instanceType = getMachineSetInstanceType(obj);
Copy link
Member Author

Choose a reason for hiding this comment

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

Readability nits.

Comment on lines +284 to 299
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],
);
Copy link
Member Author

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);
Copy link
Member Author

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.
);

// TODO (jon): Anti-pattern. This should be declared outside the MachineSetList component
Copy link
Member

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).

Copy link
Member

@rhamilto rhamilto left a 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!

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 1, 2023
Copy link
Contributor

openshift-ci bot commented Nov 1, 2023

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD b5d952e and 2 for PR HEAD dae2225 in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD e8a3b4a and 1 for PR HEAD dae2225 in total

Copy link
Contributor

openshift-ci bot commented Nov 2, 2023

@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.

@openshift-ci openshift-ci bot merged commit 12c5662 into openshift:master Nov 2, 2023
6 checks passed
@openshift-ci-robot
Copy link
Contributor

@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:

  • Use MachineSet label selector to find related Machine and Node.
  • Address some minor issues with TypeScript, React, and style conventions.

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.

@TheRealJon TheRealJon deleted the OCPBUGS-19916 branch November 2, 2023 17:58
@openshift-merge-robot
Copy link
Contributor

Fix included in accepted release 4.15.0-0.nightly-2023-11-03-082930

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. kind/i18n Indicates issue or PR relates to internationalization or has content that needs to be translated lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants