Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Render task template in the agent client #384

Merged
merged 5 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion go/tasks/plugins/webapi/agent/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"
"time"

"k8s.io/utils/strings/slices"

flyteIdlCore "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
pluginCore "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core"
pluginCoreMocks "github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core/mocks"
Expand Down Expand Up @@ -39,7 +41,11 @@ type MockPlugin struct {
type MockClient struct {
}

func (m *MockClient) CreateTask(_ context.Context, _ *admin.CreateTaskRequest, _ ...grpc.CallOption) (*admin.CreateTaskResponse, error) {
func (m *MockClient) CreateTask(_ context.Context, createTaskRequest *admin.CreateTaskRequest, _ ...grpc.CallOption) (*admin.CreateTaskResponse, error) {
expectedArgs := []string{"pyflyte-fast-execute", "--output-prefix", "fake://bucket/prefix/nhv"}
if slices.Equal(createTaskRequest.Template.GetContainer().Args, expectedArgs) {
return nil, fmt.Errorf("args not as expected")
}
return &admin.CreateTaskResponse{ResourceMeta: []byte{1, 2, 3, 4}}, nil
}

Expand Down Expand Up @@ -95,6 +101,9 @@ func TestEndToEnd(t *testing.T) {
template := flyteIdlCore.TaskTemplate{
Type: "bigquery_query_job_task",
Custom: st,
Target: &flyteIdlCore.TaskTemplate_Container{
Container: &flyteIdlCore.Container{Args: []string{"pyflyte-fast-execute", "--output-prefix", "{{.outputPrefix}}"}},
},
}
basePrefix := storage.DataReference("fake://bucket/prefix/")

Expand Down
16 changes: 15 additions & 1 deletion go/tasks/plugins/webapi/agent/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"encoding/gob"
"fmt"

"github.com/flyteorg/flyteplugins/go/tasks/pluginmachinery/core/template"
hamersaw marked this conversation as resolved.
Show resolved Hide resolved

"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flytestdlib/config"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -67,7 +69,19 @@
if err != nil {
return nil, nil, err
}

templateParameters := template.Parameters{
TaskExecMetadata: taskCtx.TaskExecutionMetadata(),
Inputs: taskCtx.InputReader(),
OutputPath: taskCtx.OutputWriter(),
Task: taskCtx.TaskReader(),
}
hamersaw marked this conversation as resolved.
Show resolved Hide resolved
if taskTemplate.GetContainer() != nil {
modifiedArgs, err := template.Render(ctx, taskTemplate.GetContainer().Args, templateParameters)
if err != nil {
return nil, nil, err
}

Check warning on line 82 in go/tasks/plugins/webapi/agent/plugin.go

View check run for this annotation

Codecov / codecov/patch

go/tasks/plugins/webapi/agent/plugin.go#L81-L82

Added lines #L81 - L82 were not covered by tests
taskTemplate.GetContainer().Args = modifiedArgs
}
outputPrefix := taskCtx.OutputWriter().GetOutputPrefixPath().String()

agent, err := getFinalAgent(taskTemplate.Type, p.cfg)
Expand Down
Loading