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 kube lib for lua #2871

Merged
merged 1 commit into from
Dec 9, 2022
Merged

Conversation

ikaven1024
Copy link
Member

@ikaven1024 ikaven1024 commented Nov 26, 2022

Signed-off-by: yingjinhui yingjinhui@didiglobal.com

What type of PR is this?
/kind feature

What this PR does / why we need it:
When users use customization to implement GetReplicas, it's difficult to accurate the sum of resource quantity. This PR load the kube library to help do this work.

See the demo:

local kube = require("kube")
function GetReplicas(desiredObj)
replica = desiredObj.spec.replicas
requires = kube.accuratePodRequirements(desiredObj.spec.template)
return replica, requires
end`,

Which issue(s) this PR fixes:
part of #2371

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 26, 2022
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 26, 2022
@codecov-commenter
Copy link

codecov-commenter commented Nov 26, 2022

Codecov Report

Merging #2871 (6dd348f) into master (472ccb5) will increase coverage by 0.09%.
The diff coverage is 64.70%.

@@            Coverage Diff             @@
##           master    #2871      +/-   ##
==========================================
+ Coverage   37.80%   37.90%   +0.09%     
==========================================
  Files         200      201       +1     
  Lines       18461    18511      +50     
==========================================
+ Hits         6980     7016      +36     
- Misses      11073    11084      +11     
- Partials      408      411       +3     
Flag Coverage Δ
unittests 37.90% <64.70%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...reter/configurableinterpreter/luavm/lua_convert.go 73.91% <0.00%> (ø)
...ceinterpreter/configurableinterpreter/luavm/lua.go 56.97% <50.00%> (-0.12%) ⬇️
...einterpreter/configurableinterpreter/luavm/kube.go 67.39% <67.39%> (ø)
pkg/search/proxy/store/util.go 94.31% <0.00%> (+1.42%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@ikaven1024 ikaven1024 force-pushed the feature/lua-resource branch 2 times, most recently from ada4814 to 081a1d6 Compare November 26, 2022 17:48
@RainbowMango RainbowMango added this to the v1.5 milestone Nov 28, 2022
@RainbowMango
Copy link
Member

I like the idea. Sounds like it makes easier for users to write the scripts.

@ikaven1024 ikaven1024 force-pushed the feature/lua-resource branch 4 times, most recently from 0744a22 to b728378 Compare November 29, 2022 04:42
@XiShanYongYe-Chang
Copy link
Member

/assign

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

LGTM

Do we need to update the getReplicas example in the examples at the same time?

@ikaven1024
Copy link
Member Author

Do we need to update the getReplicas example in the examples at the same time?

OK. I will do it.

@ikaven1024 ikaven1024 force-pushed the feature/lua-resource branch from b728378 to 6dd348f Compare December 5, 2022 07:51
@XiShanYongYe-Chang
Copy link
Member

/lgtm
/assign @RainbowMango

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 5, 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.

Good job!
Only some nits and questions.

return 1
}

func checkResourceQuantity(ls *lua.LState, n int) 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.

This function isn't about to check, but parse a resource to resource.Quantity.

Rename to ParseResourceQuantity or one more accurate?

Copy link
Member Author

Choose a reason for hiding this comment

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

This naming follows gopher-lua's function CheckXxx

func (ls *LState) CheckAny(n int) LValue {
if n > ls.GetTop() {
ls.ArgError(n, "value expected")
}
return ls.Get(n)
}
func (ls *LState) CheckInt(n int) int {
v := ls.Get(n)
if intv, ok := v.(LNumber); ok {
return int(intv)
}
ls.TypeError(n, LTNumber)
return 0
}
func (ls *LState) CheckInt64(n int) int64 {

Comment on lines +42 to +53
func resourceAdd(ls *lua.LState) int {
res := resource.Quantity{}
n := ls.GetTop()
for i := 1; i <= n; i++ {
q := checkResourceQuantity(ls, i)
res.Add(q)
}

s := res.String()
ls.Push(lua.LString(s))
return 1
}
Copy link
Member

Choose a reason for hiding this comment

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

When this function would be used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Users may want to accurate resource quantity with their logic, rather accuratePodRequirements.

@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 8, 2022
@ikaven1024 ikaven1024 force-pushed the feature/lua-resource branch from b5bdd35 to 3b1a404 Compare December 8, 2022 13:26
Signed-off-by: yingjinhui <yingjinhui@didiglobal.com>
@ikaven1024 ikaven1024 force-pushed the feature/lua-resource branch from 3b1a404 to 0f5e377 Compare December 8, 2022 14:14
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 Dec 9, 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 Dec 9, 2022
@karmada-bot karmada-bot merged commit 54b7aa2 into karmada-io:master Dec 9, 2022
@ikaven1024 ikaven1024 deleted the feature/lua-resource branch December 9, 2022 02:58
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants