Merge pull request #2869 from RainbowMango/pr_update_interpreter_api

Update ResourceInterpreterCustomization comments according to implementation
This commit is contained in:
karmada-bot 2022-11-28 18:42:11 +08:00 committed by GitHub
commit 1545f16454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 152 additions and 74 deletions

View File

@ -56,11 +56,13 @@ spec:
~= \"default\" then dependency = {} dependency.apiVersion
= \"v1\" dependency.kind = \"ServiceAccount\" dependency.name
= desiredObj.spec.serviceAccountName dependency.namespace
= desiredObj.namespace dependencies[0] = {} dependencies[0]
= dependency end return dependencies end \n LuaScript only
holds the function body part, take the `desiredObj` as the
function parameters or global variables, and finally returns
the dependent resources."
= desiredObj.namespace dependencies[1] = {} dependencies[1]
= dependency end return dependencies end \n The content
of the LuaScript needs to be a whole function including
both declaration and implementation. \n The parameters will
be supplied by the system: - desiredObj: the object represents
the configuration to be applied to the member cluster. \n
The returned value should be expressed by a slice of DependentObjectReference."
type: string
required:
- luaScript
@ -76,9 +78,12 @@ spec:
should implement a function as follows: luaScript: > function
InterpretHealth(observedObj) if observedObj.status.readyReplicas
== observedObj.spec.replicas then return true end end \n
LuaScript only holds the function body part, take the `observedObj`
as the function parameters or global variables, and finally
returns the boolean health state."
The content of the LuaScript needs to be a whole function
including both declaration and implementation. \n The parameters
will be supplied by the system: - observedObj: the object
represents the configuration that is observed from a specific
member cluster. \n The returned boolean value indicates
the health status."
type: string
required:
- luaScript
@ -95,16 +100,21 @@ spec:
luaScript:
description: "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:
> function GetReplicas(desiredObj) nodeClaim = {} resourceRequest
= {} result = {} \n result.replica = desiredObj.spec.replicas
result.resourceRequest = desiredObj.spec.template.spec.containers[0].resources.limits
\n nodeClaim.nodeSelector = desiredObj.spec.template.spec.nodeSelector
nodeClaim.tolerations = desiredObj.spec.template.spec.tolerations
result.nodeClaim = nodeClaim \n return result end \n LuaScript
only holds the function body part, take the `desiredObj`
as the function parameters or global variable, and finally
returns the replica number and required resources."
\n The script should implement a function as follows: luaScript:
> function GetReplicas(desiredObj) replica = desiredObj.spec.replicas
requirement = {} requirement.nodeClaim = {} requirement.nodeClaim.nodeSelector
= desiredObj.spec.template.spec.nodeSelector requirement.nodeClaim.tolerations
= desiredObj.spec.template.spec.tolerations requirement.resourceRequest
= desiredObj.spec.template.spec.containers[1].resources.limits
return replica, requirement end \n The content of the LuaScript
needs to be a whole function including both declaration
and implementation. \n The parameters will be supplied by
the system: - desiredObj: the object represents the configuration
to be applied to the member cluster. \n The function expects
two return values: - replica: the declared replica number
- requirement: the resource required by each replica expressed
with a ResourceBindingSpec.ReplicaRequirements. The returned
values will be set into a ResourceBinding or ClusterResourceBinding."
type: string
required:
- luaScript
@ -122,10 +132,14 @@ spec:
to revise replicas in the desired specification. The script
should implement a function as follows: luaScript: > function
ReviseReplica(desiredObj, desiredReplica) desiredObj.spec.replicas
= desiredReplica return desiredObj end \n LuaScript only
holds the function body part, take the `desiredObj` and
`desiredReplica` as the function parameters or global variables,
and finally returns a revised specification."
= desiredReplica return desiredObj end \n The content of
the LuaScript needs to be a whole function including both
declaration and implementation. \n The parameters will be
supplied by the system: - desiredObj: the object represents
the configuration to be applied to the member cluster. -
desiredReplica: the replica number should be applied with.
\n The returned object should be a revised configuration
which will be applied to member cluster eventually."
type: string
required:
- luaScript
@ -142,13 +156,18 @@ spec:
properties:
luaScript:
description: "LuaScript holds the Lua script that is used
to retain runtime values to the desired specification. The
script should implement a function as follows: luaScript:
to retain runtime values to the desired specification. \n
The script should implement a function as follows: luaScript:
> function Retain(desiredObj, observedObj) desiredObj.spec.fieldFoo
= observedObj.spec.fieldFoo return desiredObj end \n LuaScript
only holds the function body part, take the `desiredObj`
and `observedObj` as the function parameters or global variables,
and finally returns a retained specification."
= observedObj.spec.fieldFoo return desiredObj end \n The
content of the LuaScript needs to be a whole function including
both declaration and implementation. \n The parameters will
be supplied by the system: - desiredObj: the object represents
the configuration to be applied to the member cluster. -
observedObj: the object represents the configuration that
is observed from a specific member cluster. \n The returned
object should be a retained configuration which will be
applied to member cluster eventually."
type: string
required:
- luaScript
@ -165,11 +184,15 @@ spec:
to aggregate decentralized statuses to the desired specification.
The script should implement a function as follows: luaScript:
> function AggregateStatus(desiredObj, statusItems) for
i = 1, #items do desiredObj.status.readyReplicas = desiredObj.status.readyReplicas
+ items[i].readyReplicas end return desiredObj end \n LuaScript
only holds the function body part, take the `desiredObj`
and `statusItems` as the function parameters or global variables,
and finally returns the desiredObj."
i = 1, #statusItems do desiredObj.status.readyReplicas =
desiredObj.status.readyReplicas + items[i].readyReplicas
end return desiredObj end \n The content of the LuaScript
needs to be a whole function including both declaration
and implementation. \n The parameters will be supplied by
the system: - desiredObj: the object represents a resource
template. - statusItems: the slice of status expressed with
AggregatedStatusItem. \n The returned object should be a
whole object with status aggregated."
type: string
required:
- luaScript
@ -185,10 +208,13 @@ spec:
to get the status from the observed specification. The script
should implement a function as follows: luaScript: > function
ReflectStatus(observedObj) status = {} status.readyReplicas
= observedObj.status.observedObj return status end \n LuaScript
only holds the function body part, take the `observedObj`
as the function parameters or global variables, and finally
returns the status."
= observedObj.status.observedObj return status end \n The
content of the LuaScript needs to be a whole function including
both declaration and implementation. \n The parameters will
be supplied by the system: - observedObj: the object represents
the configuration that is observed from a specific member
cluster. \n The returned status could be the whole status
or part of it and will be set into both Work and ResourceBinding(ClusterResourceBinding)."
type: string
required:
- luaScript

View File

@ -108,7 +108,9 @@ type CustomizationRules struct {
// LocalValueRetention holds the scripts for retention.
// Now only supports Lua.
type LocalValueRetention struct {
// LuaScript holds the Lua script that is used to retain runtime values to the desired specification.
// LuaScript holds the Lua script that is used to retain runtime values
// to the desired specification.
//
// The script should implement a function as follows:
// luaScript: >
// function Retain(desiredObj, observedObj)
@ -116,8 +118,17 @@ type LocalValueRetention struct {
// return desiredObj
// end
//
// LuaScript only holds the function body part, take the `desiredObj` and `observedObj` as the function
// parameters or global variables, and finally returns a retained specification.
// The content of the LuaScript needs to be a whole function including both
// declaration and implementation.
//
// The parameters will be supplied by the system:
// - desiredObj: the object represents the configuration to be applied
// to the member cluster.
// - observedObj: the object represents the configuration that is observed
// from a specific member cluster.
//
// The returned object should be a retained configuration which will be
// applied to member cluster eventually.
// +required
LuaScript string `json:"luaScript"`
}
@ -127,25 +138,31 @@ type LocalValueRetention struct {
type ReplicaResourceRequirement struct {
// 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: >
// function GetReplicas(desiredObj)
// nodeClaim = {}
// resourceRequest = {}
// result = {}
//
// result.replica = desiredObj.spec.replicas
// result.resourceRequest = desiredObj.spec.template.spec.containers[0].resources.limits
//
// nodeClaim.nodeSelector = desiredObj.spec.template.spec.nodeSelector
// nodeClaim.tolerations = desiredObj.spec.template.spec.tolerations
// result.nodeClaim = nodeClaim
//
// return result
// replica = desiredObj.spec.replicas
// requirement = {}
// requirement.nodeClaim = {}
// requirement.nodeClaim.nodeSelector = desiredObj.spec.template.spec.nodeSelector
// requirement.nodeClaim.tolerations = desiredObj.spec.template.spec.tolerations
// requirement.resourceRequest = desiredObj.spec.template.spec.containers[1].resources.limits
// return replica, requirement
// end
//
// LuaScript only holds the function body part, take the `desiredObj` as the function
// parameters or global variable, and finally returns the replica number and required resources.
// The content of the LuaScript needs to be a whole function including both
// declaration and implementation.
//
// The parameters will be supplied by the system:
// - desiredObj: the object represents the configuration to be applied
// to the member cluster.
//
// The function expects two return values:
// - replica: the declared replica number
// - requirement: the resource required by each replica expressed with a
// ResourceBindingSpec.ReplicaRequirements.
// The returned values will be set into a ResourceBinding or ClusterResourceBinding.
// +required
LuaScript string `json:"luaScript"`
}
@ -160,8 +177,16 @@ type ReplicaRevision struct {
// return desiredObj
// end
//
// LuaScript only holds the function body part, take the `desiredObj` and `desiredReplica` as the function
// parameters or global variables, and finally returns a revised specification.
// The content of the LuaScript needs to be a whole function including both
// declaration and implementation.
//
// The parameters will be supplied by the system:
// - desiredObj: the object represents the configuration to be applied
// to the member cluster.
// - desiredReplica: the replica number should be applied with.
//
// The returned object should be a revised configuration which will be
// applied to member cluster eventually.
// +required
LuaScript string `json:"luaScript"`
}
@ -177,8 +202,15 @@ type StatusReflection struct {
// return status
// end
//
// LuaScript only holds the function body part, take the `observedObj` as the function
// parameters or global variables, and finally returns the status.
// The content of the LuaScript needs to be a whole function including both
// declaration and implementation.
//
// The parameters will be supplied by the system:
// - observedObj: the object represents the configuration that is observed
// from a specific member cluster.
//
// The returned status could be the whole status or part of it and will
// be set into both Work and ResourceBinding(ClusterResourceBinding).
// +required
LuaScript string `json:"luaScript"`
}
@ -190,14 +222,21 @@ type StatusAggregation struct {
// The script should implement a function as follows:
// luaScript: >
// function AggregateStatus(desiredObj, statusItems)
// for i = 1, #items do
// for i = 1, #statusItems do
// desiredObj.status.readyReplicas = desiredObj.status.readyReplicas + items[i].readyReplicas
// end
// return desiredObj
// end
//
// LuaScript only holds the function body part, take the `desiredObj` and `statusItems` as the function
// parameters or global variables, and finally returns the desiredObj.
// The content of the LuaScript needs to be a whole function including both
// declaration and implementation.
//
// The parameters will be supplied by the system:
// - desiredObj: the object represents a resource template.
// - statusItems: the slice of status expressed with AggregatedStatusItem.
//
// The returned object should be a whole object with status aggregated.
//
// +required
LuaScript string `json:"luaScript"`
}
@ -214,8 +253,15 @@ type HealthInterpretation struct {
// end
// end
//
// LuaScript only holds the function body part, take the `observedObj` as the function
// parameters or global variables, and finally returns the boolean health state.
// The content of the LuaScript needs to be a whole function including both
// declaration and implementation.
//
// The parameters will be supplied by the system:
// - observedObj: the object represents the configuration that is observed
// from a specific member cluster.
//
// The returned boolean value indicates the health status.
//
// +required
LuaScript string `json:"luaScript"`
}
@ -235,14 +281,20 @@ type DependencyInterpretation struct {
// dependency.kind = "ServiceAccount"
// dependency.name = desiredObj.spec.serviceAccountName
// dependency.namespace = desiredObj.namespace
// dependencies[0] = {}
// dependencies[0] = dependency
// dependencies[1] = {}
// dependencies[1] = dependency
// end
// return dependencies
// end
//
// LuaScript only holds the function body part, take the `desiredObj` as the function
// parameters or global variables, and finally returns the dependent resources.
// The content of the LuaScript needs to be a whole function including both
// declaration and implementation.
//
// The parameters will be supplied by the system:
// - desiredObj: the object represents the configuration to be applied
// to the member cluster.
//
// The returned value should be expressed by a slice of DependentObjectReference.
// +required
LuaScript string `json:"luaScript"`
}

View File

@ -1177,7 +1177,7 @@ func schema_pkg_apis_config_v1alpha1_DependencyInterpretation(ref common.Referen
Properties: map[string]spec.Schema{
"luaScript": {
SchemaProps: spec.SchemaProps{
Description: "LuaScript holds the Lua script that is used to interpret the dependencies of a specific resource. The script should implement a function as follows:\n luaScript: >\n function GetDependencies(desiredObj)\n dependencies = {}\n if desiredObj.spec.serviceAccountName ~= \"\" and desiredObj.spec.serviceAccountName ~= \"default\" then\n dependency = {}\n dependency.apiVersion = \"v1\"\n dependency.kind = \"ServiceAccount\"\n dependency.name = desiredObj.spec.serviceAccountName\n dependency.namespace = desiredObj.namespace\n dependencies[0] = {}\n dependencies[0] = dependency\n end\n return dependencies\n end\n\nLuaScript only holds the function body part, take the `desiredObj` as the function parameters or global variables, and finally returns the dependent resources.",
Description: "LuaScript holds the Lua script that is used to interpret the dependencies of a specific resource. The script should implement a function as follows:\n luaScript: >\n function GetDependencies(desiredObj)\n dependencies = {}\n if desiredObj.spec.serviceAccountName ~= \"\" and desiredObj.spec.serviceAccountName ~= \"default\" then\n dependency = {}\n dependency.apiVersion = \"v1\"\n dependency.kind = \"ServiceAccount\"\n dependency.name = desiredObj.spec.serviceAccountName\n dependency.namespace = desiredObj.namespace\n dependencies[1] = {}\n dependencies[1] = dependency\n end\n return dependencies\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - desiredObj: the object represents the configuration to be applied\n to the member cluster.\n\nThe returned value should be expressed by a slice of DependentObjectReference.",
Default: "",
Type: []string{"string"},
Format: "",
@ -1244,7 +1244,7 @@ func schema_pkg_apis_config_v1alpha1_HealthInterpretation(ref common.ReferenceCa
Properties: map[string]spec.Schema{
"luaScript": {
SchemaProps: spec.SchemaProps{
Description: "LuaScript holds the Lua script that is used to assess the health state of a specific resource. The script should implement a function as follows:\n luaScript: >\n function InterpretHealth(observedObj)\n if observedObj.status.readyReplicas == observedObj.spec.replicas then\n return true\n end\n end\n\nLuaScript only holds the function body part, take the `observedObj` as the function parameters or global variables, and finally returns the boolean health state.",
Description: "LuaScript holds the Lua script that is used to assess the health state of a specific resource. The script should implement a function as follows:\n luaScript: >\n function InterpretHealth(observedObj)\n if observedObj.status.readyReplicas == observedObj.spec.replicas then\n return true\n end\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - observedObj: the object represents the configuration that is observed\n from a specific member cluster.\n\nThe returned boolean value indicates the health status.",
Default: "",
Type: []string{"string"},
Format: "",
@ -1266,7 +1266,7 @@ func schema_pkg_apis_config_v1alpha1_LocalValueRetention(ref common.ReferenceCal
Properties: map[string]spec.Schema{
"luaScript": {
SchemaProps: spec.SchemaProps{
Description: "LuaScript holds the Lua script that is used to retain runtime values to the desired specification. The script should implement a function as follows:\n luaScript: >\n function Retain(desiredObj, observedObj)\n desiredObj.spec.fieldFoo = observedObj.spec.fieldFoo\n return desiredObj\n end\n\nLuaScript only holds the function body part, take the `desiredObj` and `observedObj` as the function parameters or global variables, and finally returns a retained specification.",
Description: "LuaScript holds the Lua script that is used to retain runtime values to the desired specification.\n\nThe script should implement a function as follows:\n luaScript: >\n function Retain(desiredObj, observedObj)\n desiredObj.spec.fieldFoo = observedObj.spec.fieldFoo\n return desiredObj\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - desiredObj: the object represents the configuration to be applied\n to the member cluster.\n - observedObj: the object represents the configuration that is observed\n from a specific member cluster.\n\nThe returned object should be a retained configuration which will be applied to member cluster eventually.",
Default: "",
Type: []string{"string"},
Format: "",
@ -1288,7 +1288,7 @@ func schema_pkg_apis_config_v1alpha1_ReplicaResourceRequirement(ref common.Refer
Properties: map[string]spec.Schema{
"luaScript": {
SchemaProps: spec.SchemaProps{
Description: "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:\n luaScript: >\n function GetReplicas(desiredObj)\n nodeClaim = {}\n resourceRequest = {}\n result = {}\n\n result.replica = desiredObj.spec.replicas\n result.resourceRequest = desiredObj.spec.template.spec.containers[0].resources.limits\n\n nodeClaim.nodeSelector = desiredObj.spec.template.spec.nodeSelector\n nodeClaim.tolerations = desiredObj.spec.template.spec.tolerations\n result.nodeClaim = nodeClaim\n\n return result\n end\n\nLuaScript only holds the function body part, take the `desiredObj` as the function parameters or global variable, and finally returns the replica number and required resources.",
Description: "LuaScript holds the Lua script that is used to discover the resource's replica as well as resource requirements\n\nThe script should implement a function as follows:\n luaScript: >\n function GetReplicas(desiredObj)\n replica = desiredObj.spec.replicas\n requirement = {}\n requirement.nodeClaim = {}\n requirement.nodeClaim.nodeSelector = desiredObj.spec.template.spec.nodeSelector\n requirement.nodeClaim.tolerations = desiredObj.spec.template.spec.tolerations\n requirement.resourceRequest = desiredObj.spec.template.spec.containers[1].resources.limits\n return replica, requirement\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - desiredObj: the object represents the configuration to be applied\n to the member cluster.\n\nThe function expects two return values:\n - replica: the declared replica number\n - requirement: the resource required by each replica expressed with a\n ResourceBindingSpec.ReplicaRequirements.\nThe returned values will be set into a ResourceBinding or ClusterResourceBinding.",
Default: "",
Type: []string{"string"},
Format: "",
@ -1310,7 +1310,7 @@ func schema_pkg_apis_config_v1alpha1_ReplicaRevision(ref common.ReferenceCallbac
Properties: map[string]spec.Schema{
"luaScript": {
SchemaProps: spec.SchemaProps{
Description: "LuaScript holds the Lua script that is used to revise replicas in the desired specification. The script should implement a function as follows:\n luaScript: >\n function ReviseReplica(desiredObj, desiredReplica)\n desiredObj.spec.replicas = desiredReplica\n return desiredObj\n end\n\nLuaScript only holds the function body part, take the `desiredObj` and `desiredReplica` as the function parameters or global variables, and finally returns a revised specification.",
Description: "LuaScript holds the Lua script that is used to revise replicas in the desired specification. The script should implement a function as follows:\n luaScript: >\n function ReviseReplica(desiredObj, desiredReplica)\n desiredObj.spec.replicas = desiredReplica\n return desiredObj\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - desiredObj: the object represents the configuration to be applied\n to the member cluster.\n - desiredReplica: the replica number should be applied with.\n\nThe returned object should be a revised configuration which will be applied to member cluster eventually.",
Default: "",
Type: []string{"string"},
Format: "",
@ -2002,7 +2002,7 @@ func schema_pkg_apis_config_v1alpha1_StatusAggregation(ref common.ReferenceCallb
Properties: map[string]spec.Schema{
"luaScript": {
SchemaProps: spec.SchemaProps{
Description: "LuaScript holds the Lua script that is used to aggregate decentralized statuses to the desired specification. The script should implement a function as follows:\n luaScript: >\n function AggregateStatus(desiredObj, statusItems)\n for i = 1, #items do\n desiredObj.status.readyReplicas = desiredObj.status.readyReplicas + items[i].readyReplicas\n end\n return desiredObj\n end\n\nLuaScript only holds the function body part, take the `desiredObj` and `statusItems` as the function parameters or global variables, and finally returns the desiredObj.",
Description: "LuaScript holds the Lua script that is used to aggregate decentralized statuses to the desired specification. The script should implement a function as follows:\n luaScript: >\n function AggregateStatus(desiredObj, statusItems)\n for i = 1, #statusItems do\n desiredObj.status.readyReplicas = desiredObj.status.readyReplicas + items[i].readyReplicas\n end\n return desiredObj\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - desiredObj: the object represents a resource template.\n - statusItems: the slice of status expressed with AggregatedStatusItem.\n\nThe returned object should be a whole object with status aggregated.",
Default: "",
Type: []string{"string"},
Format: "",
@ -2024,7 +2024,7 @@ func schema_pkg_apis_config_v1alpha1_StatusReflection(ref common.ReferenceCallba
Properties: map[string]spec.Schema{
"luaScript": {
SchemaProps: spec.SchemaProps{
Description: "LuaScript holds the Lua script that is used to get the status from the observed specification. The script should implement a function as follows:\n luaScript: >\n function ReflectStatus(observedObj)\n status = {}\n status.readyReplicas = observedObj.status.observedObj\n return status\n end\n\nLuaScript only holds the function body part, take the `observedObj` as the function parameters or global variables, and finally returns the status.",
Description: "LuaScript holds the Lua script that is used to get the status from the observed specification. The script should implement a function as follows:\n luaScript: >\n function ReflectStatus(observedObj)\n status = {}\n status.readyReplicas = observedObj.status.observedObj\n return status\n end\n\nThe content of the LuaScript needs to be a whole function including both declaration and implementation.\n\nThe parameters will be supplied by the system:\n - observedObj: the object represents the configuration that is observed\n from a specific member cluster.\n\nThe returned status could be the whole status or part of it and will be set into both Work and ResourceBinding(ClusterResourceBinding).",
Default: "",
Type: []string{"string"},
Format: "",