Documentation ¶
Index ¶
- Constants
- func ConvertLuaResultInto(luaResult *lua.LTable, obj interface{}, references ...any) error
- func ConvertLuaResultToBool(luaResult lua.LValue) (bool, error)
- func ConvertLuaResultToInt(luaResult lua.LValue) (int32, error)
- func KubeLoader(ls *lua.LState) int
- func NewWithContext(ctx context.Context) (*lua.LState, error)
- type VM
- func (vm *VM) AggregateStatus(object *unstructured.Unstructured, items []workv1alpha2.AggregatedStatusItem, ...) (*unstructured.Unstructured, error)
- func (vm *VM) GetDependencies(object *unstructured.Unstructured, script string) (dependencies []configv1alpha1.DependentObjectReference, err error)
- func (vm *VM) GetReplicas(obj *unstructured.Unstructured, script string) (replica int32, requires *workv1alpha2.ReplicaRequirements, err error)
- func (vm *VM) InterpretHealth(object *unstructured.Unstructured, script string) (bool, error)
- func (vm *VM) NewLuaState() (*lua.LState, error)
- func (vm *VM) ReflectStatus(object *unstructured.Unstructured, script string) (status *runtime.RawExtension, err error)
- func (vm *VM) Retain(desired *unstructured.Unstructured, observed *unstructured.Unstructured, ...) (retained *unstructured.Unstructured, err error)
- func (vm *VM) ReviseReplica(object *unstructured.Unstructured, replica int64, script string) (*unstructured.Unstructured, error)
- func (vm *VM) RunScript(script string, fnName string, nRets int, args ...interface{}) ([]lua.LValue, error)
Constants ¶
const (
// KubeLibName is the name of the kube library.
KubeLibName = "kube"
)
Variables ¶
This section is empty.
Functions ¶
func ConvertLuaResultInto ¶
ConvertLuaResultInto convert lua result to obj @param references: the method of encoding a lua table is flawed and needs to be referenced by the same Kind object. take `Retain(desired, observed)` for example, we have problem to convert empty fields, but empty fields is most likely from desired or observed object, so take {desired, observed} object as references to obtain more accurate encoding values.
func ConvertLuaResultToBool ¶
ConvertLuaResultToBool convert lua result to bool.
func ConvertLuaResultToInt ¶
ConvertLuaResultToInt convert lua result to int.
func KubeLoader ¶
KubeLoader loads the kube library. Import this library before your script by:
local kube = require("kube")
Then you can call functions in this library by:
kube.xxx()
This library Contains:
- function resourceAdd(r1, r2, ...) accruing the quantity of resources. Example: cpu = kube.resourceAdd(r1.cpu, r2.cpu, r3.cpu)
- function accuratePodRequirements(pod) requirements accurate total resource requirements for pod. Example: requirements = kube.accuratePodRequirements(pod)
- function getPodDependencies(podTemplate, namespace) dependencies get total dependencies from podTemplate and namespace. Example: dependencies = kube.getPodDependencies(podTemplate, namespace)
Types ¶
type VM ¶
type VM struct { // UseOpenLibs flag to enable open libraries. Libraries are disabled by default while running, but enabled during testing to allow the use of print statements. UseOpenLibs bool Pool *fixedpool.FixedPool }
VM Defines a struct that implements the luaVM.
func (*VM) AggregateStatus ¶
func (vm *VM) AggregateStatus(object *unstructured.Unstructured, items []workv1alpha2.AggregatedStatusItem, script string) (*unstructured.Unstructured, error)
AggregateStatus returns the objects that based on the 'object' but with status aggregated by lua.
func (*VM) GetDependencies ¶
func (vm *VM) GetDependencies(object *unstructured.Unstructured, script string) (dependencies []configv1alpha1.DependentObjectReference, err error)
GetDependencies returns the dependent resources of the given object by lua.
func (*VM) GetReplicas ¶
func (vm *VM) GetReplicas(obj *unstructured.Unstructured, script string) (replica int32, requires *workv1alpha2.ReplicaRequirements, err error)
GetReplicas returns the desired replicas of the object as well as the requirements of each replica by lua script.
func (*VM) InterpretHealth ¶
func (vm *VM) InterpretHealth(object *unstructured.Unstructured, script string) (bool, error)
InterpretHealth returns the health state of the object by lua.
func (*VM) NewLuaState ¶
NewLuaState creates a new lua state.
func (*VM) ReflectStatus ¶
func (vm *VM) ReflectStatus(object *unstructured.Unstructured, script string) (status *runtime.RawExtension, err error)
ReflectStatus returns the status of the object by lua.
func (*VM) Retain ¶
func (vm *VM) Retain(desired *unstructured.Unstructured, observed *unstructured.Unstructured, script string) (retained *unstructured.Unstructured, err error)
Retain returns the objects that based on the "desired" object but with values retained from the "observed" object by lua.
func (*VM) ReviseReplica ¶
func (vm *VM) ReviseReplica(object *unstructured.Unstructured, replica int64, script string) (*unstructured.Unstructured, error)
ReviseReplica revises the replica of the given object by lua.