Skip to content

Commit

Permalink
feat: add flag MergeBuiltinActions to include all actions
Browse files Browse the repository at this point in the history
Signed-off-by: ashutosh16 <[email protected]>
  • Loading branch information
ashutosh16 committed Sep 10, 2024
1 parent e728a27 commit 524c0d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion util/lua/lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 15 additions & 2 deletions util/lua/lua_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`
Expand Down Expand Up @@ -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{
{
Expand All @@ -408,6 +418,9 @@ func TestExecuteResourceActionDiscoveryWithDuplicationActions(t *testing.T) {
Type: "number",
}},
},
{
Name: "prebuilt",
},
}
for _, expectedAction := range expectedActions {
assert.Contains(t, actions, expectedAction)
Expand Down

0 comments on commit 524c0d0

Please sign in to comment.