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

Add cluster resource modeling api #2386

Merged

Conversation

halfrost
Copy link
Contributor

@halfrost halfrost commented Aug 16, 2022

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR introduced a feature of cluster resource modeling

Which issue(s) this PR fixes:
Part of #772

Special notes for your reviewer:
This pr is for issue #772 cluster resource modeling API part.

Does this PR introduce a user-facing change?:

The `Cluster` API introduced an optional field named `ResourceModels` to specify resource modelings.

@karmada-bot karmada-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Aug 16, 2022
@halfrost
Copy link
Contributor Author

@Poor12 This is API part of cluster resource modeling. Please help me review it. Thx.

@halfrost
Copy link
Contributor Author

@Poor12 I have already changed the resource name into an enum. We can maintain by ourselves in the future. We can add more resource names in the enum. Please review it.

@RainbowMango
Copy link
Member

@halfrost Please squash your commits and use PR templates.

@halfrost halfrost force-pushed the cluster-resource-modeling-api branch 2 times, most recently from d6fc8e0 to 97fd9ca Compare August 16, 2022 08:48
@halfrost halfrost force-pushed the cluster-resource-modeling-api branch 4 times, most recently from a9892d2 to 0f3a668 Compare August 16, 2022 09:05
@Poor12
Copy link
Member

Poor12 commented Aug 16, 2022

/lgtm
cc @RainbowMango

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 16, 2022
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

Generally looks good to me.
Some small touches.
/assign @kevin-wangzefeng

pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
@halfrost halfrost force-pushed the cluster-resource-modeling-api branch from 0f3a668 to e76a2b7 Compare August 16, 2022 22:23
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 16, 2022
@halfrost halfrost force-pushed the cluster-resource-modeling-api branch from e76a2b7 to ce8e26b Compare August 16, 2022 22:23
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
@halfrost halfrost force-pushed the cluster-resource-modeling-api branch 2 times, most recently from dfd241c to 928ebbd Compare August 17, 2022 03:59
pkg/apis/cluster/types.go Outdated Show resolved Hide resolved
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

This is probably my last comment.
Thanks @halfrost for your hard and excellent work.

pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
@halfrost halfrost force-pushed the cluster-resource-modeling-api branch 2 times, most recently from 3a2f317 to 1eb9380 Compare August 17, 2022 07:20
pkg/apis/cluster/v1alpha1/types.go Outdated Show resolved Hide resolved
pkg/apis/cluster/types.go Outdated Show resolved Hide resolved
@halfrost halfrost force-pushed the cluster-resource-modeling-api branch 3 times, most recently from 1b4c833 to caeb54a Compare August 17, 2022 08:25
@RainbowMango
Copy link
Member

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 17, 2022
Copy link
Member

@kevin-wangzefeng kevin-wangzefeng left a comment

Choose a reason for hiding this comment

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

Minor comments, thanks

Comment on lines +215 to +225
// Max is the maximum amount of this resource represented by resource name.
// Special Instructions, for the last ResourceModelRange, which no matter what Max value you pass,
// the meaning is infinite. Because for the last item,
// any ResourceModelRange's quota larger than Min will be classified to the last one.
// Of course, the value of the Max field is always greater than the value of the Min field.
// It should be true in any case.
// +optional
Max resource.Quantity
Copy link
Member

Choose a reason for hiding this comment

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

Special Instructions, for the last ResourceModelRange, which no matter what Max value you pass,
the meaning is infinite. Because for the last item
Shall we make the last grade ignore user-input max value, or, add a computed last/largest grade according to last/largest user-input max value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My current implementation is that whatever value the last max is, those greater than min will be placed in the last group. This ensures that there will be no missing ResourceModelRange. Do you think my solution is reasonable?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with the implementation behavior, I guess what @kevin-wangzefeng mean is we should clearly note the behavior on API comments.

Copy link
Member

Choose a reason for hiding this comment

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

By the way, the behavior description should be added to ResourceModels(.spec.ResourceModels), not on ResourceModelRange which just represents the range. How we use/treat ranges is decided at ResourceModels.

Comment on lines 211 to 216
// Min is the minimum amount of this resource represented by resource name.
// +optional
Min resource.Quantity
Copy link
Member

Choose a reason for hiding this comment

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

Describing the default value would be very helpful here, e.g. Min of grade 0 defaults to zero

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +190 to +192
// Grade is the index for the resource modeling.
// +optional
Grade int
Copy link
Member

Choose a reason for hiding this comment

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

Nit: what's the expected behavior when user sets ResourceModels with grade 1:CPU[2,4), grade 3:CPU[8,16), grade 4:CPU[16,32)?

Copy link
Member

Choose a reason for hiding this comment

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

BTW, IIRC we currently don't define the output of kubectl describe cluster, but it might be great if we can define a human readable format of ResourceModels like:

ResourceModels:
	Grade 1:	CPU [2,4)	Memory [4G,8G)
	Grade 2:	CPU [4,8)	Memory [8G,16G)
	Grade 3:	CPU [8,16)	Memory [16G,32G)

A method like ResourceModel.Stringify() shall be helpful in this feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when user sets ResourceModels with grade 1:CPU[2,4), grade 3:CPU[8,16), grade 4:CPU[16,32), if some resource's CPU is 6, this resource will be assigned to a higher grade. In other words, it will belong to grade 3:CPU[8,16). Does it make sense?

By the way, in this case, grade2 doesn't exist? Or the user forgot to enter it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ResourceModel.Stringify() feature is very nice. If time is enough, I can do it together in this version.

Copy link
Member

Choose a reason for hiding this comment

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

when user sets ResourceModels with grade 1:CPU[2,4), grade 3:CPU[8,16), grade 4:CPU[16,32), if some resource's CPU is 6, this resource will be assigned to a higher grade.

+1. We can take this as the default behavior. But I don't think we should note this case.

By the way, in this case, grade2 doesn't exist? Or the user forgot to enter it?

This is an abnormal case, probably due to a mistake.
This usage is ambiguous, my suggestion is to validate the input at webhook(Validation Plugin) to avoid discontinuous ranges.

@halfrost halfrost force-pushed the cluster-resource-modeling-api branch from caeb54a to ec74e48 Compare August 17, 2022 19:57
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 17, 2022
@halfrost halfrost force-pushed the cluster-resource-modeling-api branch from ec74e48 to 3182fc7 Compare August 17, 2022 19:57
Name ResourceName `json:"name,omitempty"`

// Min is the minimum amount of this resource represented by resource name.
// E.g. Min of grade 0 defaults to zero.
Copy link
Member

Choose a reason for hiding this comment

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

// Note: The Min value of first grade(usually 0) always acts as zero.
// E.g. [1,2) equal to [0,2).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@halfrost halfrost force-pushed the cluster-resource-modeling-api branch from 3182fc7 to b72dd61 Compare August 18, 2022 05:06
Signed-off-by: halfrost <ydz627@gmail.com>
@halfrost halfrost force-pushed the cluster-resource-modeling-api branch from b72dd61 to 77cf4be Compare August 18, 2022 05:06
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 18, 2022
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 18, 2022
@karmada-bot karmada-bot merged commit 121ae39 into karmada-io:master Aug 18, 2022
@imageslr
Copy link

This is a good case for learning code review :)

@halfrost halfrost deleted the cluster-resource-modeling-api branch August 19, 2022 04:47
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. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants