From 524c0d07aeb9a9a06c1f47582d1c903eb63d96f8 Mon Sep 17 00:00:00 2001 From: ashutosh16 Date: Mon, 9 Sep 2024 23:25:15 -0700 Subject: [PATCH] feat: add flag MergeBuiltinActions to include all actions Signed-off-by: ashutosh16 --- util/lua/lua.go | 4 +++- util/lua/lua_test.go | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/util/lua/lua.go b/util/lua/lua.go index ce64e7695a2562..b255836b5434e5 100644 --- a/util/lua/lua.go +++ b/util/lua/lua.go @@ -389,7 +389,9 @@ func (vm VM) GetResourceActionDiscovery(obj *unstructured.Unstructured) ([]strin discoveryScripts = append(discoveryScripts, discoveryScript) return discoveryScripts, nil -} // GetResourceAction attempts to read lua script from config and then filesystem for that resource +} + +// GetResourceAction attempts to read lua script from config and then filesystem for that resource func (vm VM) GetResourceAction(obj *unstructured.Unstructured, actionName string) (appv1.ResourceActionDefinition, error) { key := GetConfigMapKey(obj.GroupVersionKind()) override, ok := vm.ResourceOverrides[key] diff --git a/util/lua/lua_test.go b/util/lua/lua_test.go index 8d8e8e082b0bc2..063cac42c4f13e 100644 --- a/util/lua/lua_test.go +++ b/util/lua/lua_test.go @@ -367,7 +367,17 @@ scale = {name = 'scale', params = scaleParams} resume = {name = 'resume'} -a = {scale = scale, resume = resume, test = test} +a = {scale = scale, resume = resume} + +return a +` + +const additionalValidDiscoveryLua = ` +scaleParams = { {name = "override", type = "number"} } +scale = {name = 'scale', params = scaleParams} +prebuilt = {prebuilt = 'prebuilt', type = 'number'} + +a = {scale = scale, prebuilt = prebuilt} return a ` @@ -396,7 +406,7 @@ func TestExecuteResourceActionDiscovery(t *testing.T) { func TestExecuteResourceActionDiscoveryWithDuplicationActions(t *testing.T) { testObj := StrToUnstructured(objJSON) vm := VM{} - actions, err := vm.ExecuteResourceActionDiscovery(testObj, []string{validDiscoveryLua, validDiscoveryLua}) + actions, err := vm.ExecuteResourceActionDiscovery(testObj, []string{validDiscoveryLua, additionalValidDiscoveryLua}) require.NoError(t, err) expectedActions := []appv1.ResourceAction{ { @@ -408,6 +418,9 @@ func TestExecuteResourceActionDiscoveryWithDuplicationActions(t *testing.T) { Type: "number", }}, }, + { + Name: "prebuilt", + }, } for _, expectedAction := range expectedActions { assert.Contains(t, actions, expectedAction)