-
Notifications
You must be signed in to change notification settings - Fork 919
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 configurable interpreter api #2681
Add configurable interpreter api #2681
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2681 +/- ##
==========================================
- Coverage 27.50% 27.48% -0.02%
==========================================
Files 190 190
Lines 19061 19061
==========================================
- Hits 5242 5239 -3
- Misses 13458 13461 +3
Partials 361 361
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
pkg/apis/config/v1alpha1/resourceinterpretercustomization_types.go
Outdated
Show resolved
Hide resolved
pkg/apis/config/v1alpha1/resourceinterpretercustomization_types.go
Outdated
Show resolved
Hide resolved
I'm mainly worried that the lua code is too long, which makes the yaml file of the Can you share the yaml file of the |
564fe79
to
f875b9d
Compare
pkg/apis/config/v1alpha1/resourceinterpretercustomization_types.go
Outdated
Show resolved
Hide resolved
I don't think it s a big matter. People can read and edit it in IDE. I either think defining the rules of one resource in different ResourceInterpreterCustomization has little benefit, but introducing too much matters: rule conflicting, unreadable for user... @RainbowMango |
+1 |
Signed-off-by: RainbowMango <qdurenhongcai@gmail.com>
f875b9d
to
b2b53cd
Compare
@ikaven1024 @chaunceyjiang Please take look. |
// LuaScript holds the Lua script that is used to discover the resource's | ||
// replica as well as resource requirements | ||
// The script should implement a function as follows: | ||
// luaScript: > |
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.
This line is necessary? It seems redundant:
...
retention:
luaScript:
luaScript: >
...
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.
retention:
luaScript: >
desiredObj.spec.fieldFoo = observedObj.spec.fieldFoo
return desiredObj
This is expected.
LuaScript only holds the function body part
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.
Got it.
Just a question: If I add a script with bad grammar, where and when this mistake will be reported? Do it in apiserver validating, or just throw error in runtime. And how to report these errors, in |
Good question.
I don't if there is a kind of tool that can verify the grammar issue. If so we can validate it by admission webhook. I'm thinking to introduce a tool to help user to verify/testing their customizations, like:
People can test their scripts before applying. |
If this works, I think it's going to be a new and meaningful job. |
LGTM |
Like argo-cd, we can also provide a directory to customize lua scripts for well-known projects. |
if add a script with bad grammar,the mistake will throw error in runtime. i think we can introduce a tool to verify script before applying |
+1 |
Do we need to introduce an implicit priority for this? |
What priority? |
As @ikaven1024 said, if the user applies the following two yaml files, which one will work? apiVersion: config.karmada.io/v1alpah1
kind: ResourceInterpreterCustomization
metadata:
name: foo
target:
apiVersion: v1
kind: Pod
customizations:
retention:
luaScript: >
desiredObj.spec.fieldFoo = observedObj.spec.fieldFoo
return desiredObj
replicaResource:
... apiVersion: config.karmada.io/v1alpah1
kind: ResourceInterpreterCustomization
metadata:
name: bar
target:
apiVersion: v1
kind: Pod
customizations:
retention:
luaScript: >
desiredObj.spec.fieldFoo = desiredObj.spec.fieldFoo
return desiredObj
replicaResource:
... |
// return status | ||
// end | ||
// | ||
// LuaScript only holds the function body part, take the `observedObj` as the function |
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.
Example A
luaScript: >
function ReflectStatus(observedObj)
status = {}
status.readyReplicas = observedObj.status.observedObj
return status
end
Example B
luaScript: >
status = {}
status.readyReplicas = observedObj.status.observedObj
return status
Which one is right?
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.
Example
B is expected because it has been proved by @jameszhangyukun's demo.
But I'd prefer Example A
which is easier to understand and straightforward. @jameszhangyukun Can we load a whole function to Lua runtime instead of a piece of code?
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.
I think is Example B.
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.
But I'd prefer
Example A
which is easier to understand and straightforward.
+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.
Maybe we can refer to nginx lua.
https://github.com/openresty/lua-nginx-module#data-sharing-within-an-nginx-worker
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 you make a demo with it?
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.
Example
B is expected because it has been proved by @jameszhangyukun's demo.But I'd prefer
Example A
which is easier to understand and straightforward. @jameszhangyukun Can we load a whole function to Lua runtime instead of a piece of code?
We can. this is the demo call funciton. this is the lua script
function say()
print("Hello World.")
end
function add( a, b )
ret1 = a + b
ret2 = a - b
return ret1, ret2
end
the go code
package main
import (
"fmt"
)
import (
"github.com/yuin/gopher-lua"
)
func main() {
L := lua.NewState()
L.DoFile("mylua.lua")
// Get say function in lua script
f := L.GetGlobal("say")
// Push say function to stack
L.Push(f)
// Call Lua Func
L.Call(0, 0)
// Get add function in lua script
f = L.GetGlobal("add")
L.Push(f)
// set parameter
L.Push(lua.LNumber(2))
L.Push(lua.LNumber(2))
// Call
L.Call(2, 2)
value := L.GetTop()
fmt.Println(L.Get(value)) // ret2:0
L.Pop(1)
value = L.GetTop()
fmt.Println(L.Get(value)) //re1:4
}
we can use GetGlobal
function get function in the script
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.
Great!, Let's do it by the function way, I'll update the API description later.
It's obviously an ambiguous situation. I think we can add an admission webhook to deny the second configuration. |
Let's do it as per the previous plan and iterate it once we have a better solution. |
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: 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 |
What type of PR is this?
/kind feature
/kind api-change
What this PR does / why we need it:
This PR proposes the new API of the
Configurable Interpreter
.Which issue(s) this PR fixes:
Part of #2371
Special notes for your reviewer:
Does this PR introduce a user-facing change?: