lua

package
v1.0.34 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfigMapKey

func GetConfigMapKey(gvk schema.GroupVersionKind) string

func GetWildcardConfigMapKey

func GetWildcardConfigMapKey(vm VM, gvk schema.GroupVersionKind) string

func Match

func Match(pattern, text string, separators ...rune) bool

func OpenSafeOs

func OpenSafeOs(L *lua.LState) int

func SafeOsLoader

func SafeOsLoader(L *lua.LState) int

func UnmarshalToUnstructured

func UnmarshalToUnstructured(resource string) (*unstructured.Unstructured, error)

UnmarshalToUnstructured unmarshals a resource representation in JSON to unstructured data

Types

type ImpactedResource

type ImpactedResource struct {
	UnstructuredObj *unstructured.Unstructured `json:"resource"`
	K8SOperation    K8SOperation               `json:"operation"`
}

func UnmarshalToImpactedResources

func UnmarshalToImpactedResources(resources string) ([]ImpactedResource, error)

UnmarshalToImpactedResources unmarshals an ImpactedResource array representation in JSON to ImpactedResource array

type K8SOperation

type K8SOperation string

This struct represents a wrapper, that is returned from Lua custom action script, around the unstructured k8s resource + a k8s operation that will need to be performed on this returned resource. Currently only "create" and "patch" operations are supported for custom actions. This replaces the traditional architecture of "Lua action returns the source resource for ArgoCD to patch". This enables ArgoCD to create NEW resources upon custom action. Note that the Lua code in the custom action is coupled to this type, since Lua json output is then unmarshalled to this struct. Avoided using iota, since need the mapping of the string value the end users will write in Lua code ("create" and "patch"). TODO: maybe there is a nicer general way to marshal and unmarshal, instead of explicit iteration over the enum values.

const (
	CreateOperation K8SOperation = "create"
	PatchOperation  K8SOperation = "patch"
)

func (K8SOperation) MarshalJSON

func (op K8SOperation) MarshalJSON() ([]byte, error)

func (*K8SOperation) UnmarshalJSON

func (op *K8SOperation) UnmarshalJSON(data []byte) error

type KnownTypeField

type KnownTypeField struct {
	Field string `json:"field,omitempty" protobuf:"bytes,1,opt,name=field"`
	Type  string `json:"type,omitempty" protobuf:"bytes,2,opt,name=type"`
}

type OverrideIgnoreDiff

type OverrideIgnoreDiff struct {
	// JSONPointers is a JSON path list following the format defined in RFC4627 (https://datatracker.ietf.org/doc/html/rfc6902#section-3)
	JSONPointers []string `json:"jsonPointers" protobuf:"bytes,1,rep,name=jSONPointers"`
	// JQPathExpressions is a JQ path list that will be evaludated during the diff process
	JQPathExpressions []string `json:"jqPathExpressions" protobuf:"bytes,2,opt,name=jqPathExpressions"`
	// ManagedFieldsManagers is a list of trusted managers. Fields mutated by those managers will take precedence over the
	// desired state defined in the SCM and won't be displayed in diffs
	ManagedFieldsManagers []string `json:"managedFieldsManagers" protobuf:"bytes,3,opt,name=managedFieldsManagers"`
}

OverrideIgnoreDiff contains configurations about how fields should be ignored during diffs between the desired state and live state

type ResourceAction

type ResourceAction struct {
	Name     string                `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
	Params   []ResourceActionParam `json:"params,omitempty" protobuf:"bytes,2,rep,name=params"`
	Disabled bool                  `json:"disabled,omitempty" protobuf:"varint,3,opt,name=disabled"`
}

TODO: describe this type TODO: describe members of this type

type ResourceActionDefinition

type ResourceActionDefinition struct {
	Name      string `json:"name" protobuf:"bytes,1,opt,name=name"`
	ActionLua string `json:"action.lua" yaml:"action.lua" protobuf:"bytes,2,opt,name=actionLua"`
}

TODO: describe this type TODO: describe members of this type

type ResourceActionParam

type ResourceActionParam struct {
	Name    string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
	Value   string `json:"value,omitempty" protobuf:"bytes,2,opt,name=value"`
	Type    string `json:"type,omitempty" protobuf:"bytes,3,opt,name=type"`
	Default string `json:"default,omitempty" protobuf:"bytes,4,opt,name=default"`
}

TODO: describe this type TODO: describe members of this type

type ResourceActions

type ResourceActions struct {
	ActionDiscoveryLua string                     `json:"discovery.lua,omitempty" yaml:"discovery.lua,omitempty" protobuf:"bytes,1,opt,name=actionDiscoveryLua"`
	Definitions        []ResourceActionDefinition `json:"definitions,omitempty" protobuf:"bytes,2,rep,name=definitions"`
}

TODO: describe this type TODO: describe members of this type

type ResourceHealthOverrides

type ResourceHealthOverrides map[string]ResourceOverride

func (ResourceHealthOverrides) GetResourceHealth

func (overrides ResourceHealthOverrides) GetResourceHealth(obj *unstructured.Unstructured) (*health.HealthStatus, error)

type ResourceOverride

type ResourceOverride struct {
	HealthLua             string             `protobuf:"bytes,1,opt,name=healthLua"`
	UseOpenLibs           bool               `protobuf:"bytes,5,opt,name=useOpenLibs"`
	Actions               string             `protobuf:"bytes,3,opt,name=actions"`
	IgnoreDifferences     OverrideIgnoreDiff `protobuf:"bytes,2,opt,name=ignoreDifferences"`
	IgnoreResourceUpdates OverrideIgnoreDiff `protobuf:"bytes,6,opt,name=ignoreResourceUpdates"`
	KnownTypeFields       []KnownTypeField   `protobuf:"bytes,4,opt,name=knownTypeFields"`
}

ResourceOverride holds configuration to customize resource diffing and health assessment TODO: describe the members of this type

func (*ResourceOverride) GetActions

func (o *ResourceOverride) GetActions() (ResourceActions, error)

TODO: describe this method

func (ResourceOverride) MarshalJSON

func (s ResourceOverride) MarshalJSON() ([]byte, error)

TODO: describe this method

func (*ResourceOverride) UnmarshalJSON

func (s *ResourceOverride) UnmarshalJSON(data []byte) error

TODO: describe this method

type VM

type VM struct {
	ResourceOverrides map[string]ResourceOverride
	// 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
}

VM Defines a struct that implements the luaVM

func (VM) ExecuteHealthLua

func (vm VM) ExecuteHealthLua(obj *unstructured.Unstructured, script string) (*health.HealthStatus, error)

ExecuteHealthLua runs the lua script to generate the health status of a resource

func (VM) ExecuteResourceAction

func (vm VM) ExecuteResourceAction(obj *unstructured.Unstructured, script string) ([]ImpactedResource, error)

func (VM) ExecuteResourceActionDiscovery

func (vm VM) ExecuteResourceActionDiscovery(obj *unstructured.Unstructured, script string) ([]ResourceAction, error)

func (VM) GetHealthScript

func (vm VM) GetHealthScript(obj *unstructured.Unstructured) (string, bool, error)

GetHealthScript attempts to read lua script from config and then filesystem for that resource

func (VM) GetResourceAction

func (vm VM) GetResourceAction(obj *unstructured.Unstructured, actionName string) (ResourceActionDefinition, error)

GetResourceAction attempts to read lua script from config and then filesystem for that resource

func (VM) GetResourceActionDiscovery

func (vm VM) GetResourceActionDiscovery(obj *unstructured.Unstructured) (string, error)

Jump to

Keyboard shortcuts

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