luavm

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KubeLibName is the name of the kube library.
	KubeLibName = "kube"
)

Variables

This section is empty.

Functions

func ConvertLuaResultInto

func ConvertLuaResultInto(luaResult lua.LValue, obj interface{}) error

ConvertLuaResultInto convert lua result to obj

func ConvertLuaResultToBool

func ConvertLuaResultToBool(luaResult lua.LValue) (bool, error)

ConvertLuaResultToBool convert lua result to bool.

func ConvertLuaResultToInt

func ConvertLuaResultToInt(luaResult lua.LValue) (int32, error)

ConvertLuaResultToInt convert lua result to int.

func KubeLoader

func KubeLoader(ls *lua.LState) int

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)

func NewWithContext

func NewWithContext(ctx context.Context) (*lua.LState, error)

NewWithContext creates a lua VM with the given context.

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 New

func New(useOpenLibs bool, poolSize int) *VM

New creates a manager for lua VM

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

func (vm *VM) NewLuaState() (*lua.LState, error)

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.

func (*VM) RunScript

func (vm *VM) RunScript(script string, fnName string, nRets int, args ...interface{}) ([]lua.LValue, error)

RunScript got a lua vm from pool, and execute script with given arguments.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL