Skip to content

Commit 52231db

Browse files
fix(actions): don't run empty Lua scripts (#22084) (cherry-pick #22161) (#22172)
Signed-off-by: Michael Crenshaw <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]>
1 parent 2eab10a commit 52231db

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

util/lua/lua.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,12 @@ func (vm VM) GetResourceActionDiscovery(obj *unstructured.Unstructured) ([]strin
398398
// Fetch predefined Lua scripts
399399
discoveryKey := fmt.Sprintf("%s/actions/", key)
400400
discoveryScript, err := vm.getPredefinedLuaScripts(discoveryKey, actionDiscoveryScriptFile)
401-
402-
// Ignore the error if the script does not exist.
403-
var doesNotExistErr *ScriptDoesNotExistError
404-
if err != nil && !errors.As(err, &doesNotExistErr) {
401+
if err != nil {
402+
var doesNotExistErr *ScriptDoesNotExistError
403+
if errors.As(err, &doesNotExistErr) {
404+
// No worries, just return what we have.
405+
return discoveryScripts, nil
406+
}
405407
return nil, fmt.Errorf("error while fetching predefined lua scripts: %w", err)
406408
}
407409

util/lua/lua_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func TestGetResourceActionDiscoveryNoPredefined(t *testing.T) {
325325
vm := VM{}
326326
discoveryLua, err := vm.GetResourceActionDiscovery(testObj)
327327
require.NoError(t, err)
328-
assert.Equal(t, "", discoveryLua[0])
328+
assert.Empty(t, discoveryLua)
329329
}
330330

331331
func TestGetResourceActionDiscoveryWithOverride(t *testing.T) {

0 commit comments

Comments
 (0)