Skip to content

Commit

Permalink
Fix nil pointer when task plugin load returns error (#5622)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sovietaced authored Aug 2, 2024
1 parent 17719e2 commit 89fd084
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 4 additions & 3 deletions flytepropeller/pkg/controller/nodes/task/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,14 @@ func (t *Handler) Setup(ctx context.Context, sCtx interfaces.SetupContext) error
logger.Infof(ctx, "Loading Plugin [%s] ENABLED", p.ID)
cp, err := pluginCore.LoadPlugin(ctx, sCtxFinal, p)

if err != nil {
return regErrors.Wrapf(err, "failed to load plugin - %s", p.ID)
}

if cp.GetID() == agent.ID {
t.agentService.CorePlugin = cp
}

if err != nil {
return regErrors.Wrapf(err, "failed to load plugin - %s", p.ID)
}
// For every default plugin for a task type specified in flytepropeller config we validate that the plugin's
// static definition includes that task type as something it is registered to handle.
for _, tt := range p.RegisteredTaskTypes {
Expand Down
18 changes: 18 additions & 0 deletions flytepropeller/pkg/controller/nodes/task/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func Test_task_Setup(t *testing.T) {
k8sPluginDefault := &pluginK8sMocks.Plugin{}
k8sPluginDefault.OnGetProperties().Return(pluginK8s.PluginProperties{})

loadErrorPluginType := "loadError"

corePluginEntry := pluginCore.PluginEntry{
ID: corePluginType,
RegisteredTaskTypes: []pluginCore.TaskType{corePluginType},
Expand Down Expand Up @@ -154,6 +156,13 @@ func Test_task_Setup(t *testing.T) {
RegisteredTaskTypes: []pluginCore.TaskType{k8sPluginDefaultType},
ResourceToWatch: &v1.Pod{},
}
loadErrorPluginEntry := pluginCore.PluginEntry{
ID: loadErrorPluginType,
RegisteredTaskTypes: []pluginCore.TaskType{loadErrorPluginType},
LoadPlugin: func(ctx context.Context, iCtx pluginCore.SetupContext) (pluginCore.Plugin, error) {
return nil, fmt.Errorf("test")
},
}

type wantFields struct {
pluginIDs map[pluginCore.TaskType]string
Expand Down Expand Up @@ -232,6 +241,15 @@ func Test_task_Setup(t *testing.T) {
},
},
false},
{"load-error",
testPluginRegistry{
core: []pluginCore.PluginEntry{loadErrorPluginEntry},
k8s: []pluginK8s.PluginEntry{},
},
[]string{loadErrorPluginType},
map[string]string{corePluginType: loadErrorPluginType},
wantFields{},
true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 89fd084

Please sign in to comment.