Skip to content

Commit

Permalink
secretPtr
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw committed Apr 4, 2024
1 parent 18e91a2 commit 42bbe73
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions flyteplugins/go/tasks/plugins/webapi/agent/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ func (p Plugin) Create(ctx context.Context, taskCtx webapi.TaskExecutionContextR
taskCategory := admin.TaskCategory{Name: taskTemplate.Type, Version: taskTemplate.TaskTypeVersion}
agent, isSync := getFinalAgent(&taskCategory, p.cfg, p.agentRegistry)

secrets := make([]*admin.Secret, 0)
secrets := make([]admin.Secret, 0)
if taskTemplate.SecurityContext != nil {
for _, secret := range taskTemplate.SecurityContext.Secrets {
val, err := taskCtx.SecretManager().GetForSecret(ctx, secret)
if err != nil {
return nil, nil, err
}
secrets = append(secrets, &admin.Secret{Value: val})
secrets = append(secrets, admin.Secret{Value: val})

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

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/webapi/agent/plugin.go#L98-L103

Added lines #L98 - L103 were not covered by tests
}
}

Expand All @@ -114,7 +114,7 @@ func (p Plugin) Create(ctx context.Context, taskCtx webapi.TaskExecutionContextR
if err != nil {
return nil, nil, err
}
header := &admin.CreateRequestHeader{Template: taskTemplate, OutputPrefix: outputPrefix, TaskExecutionMetadata: &taskExecutionMetadata, Secrets: secrets}
header := &admin.CreateRequestHeader{Template: taskTemplate, OutputPrefix: outputPrefix, TaskExecutionMetadata: &taskExecutionMetadata, Secrets: secretPtr(secrets)}
return p.ExecuteTaskSync(finalCtx, client, header, inputs)
}

Expand All @@ -128,7 +128,7 @@ func (p Plugin) Create(ctx context.Context, taskCtx webapi.TaskExecutionContextR
Template: taskTemplate,
OutputPrefix: outputPrefix,
TaskExecutionMetadata: &taskExecutionMetadata,
Secrets: secrets,
Secrets: secretPtr(secrets),
}
res, err := client.CreateTask(finalCtx, request)
if err != nil {
Expand All @@ -139,6 +139,7 @@ func (p Plugin) Create(ctx context.Context, taskCtx webapi.TaskExecutionContextR
OutputPrefix: outputPrefix,
AgentResourceMeta: res.GetResourceMeta(),
TaskCategory: taskCategory,
Secrets: secrets,
}, nil, nil
}

Expand Down Expand Up @@ -212,16 +213,11 @@ func (p Plugin) Get(ctx context.Context, taskCtx webapi.GetContext) (latest weba
finalCtx, cancel := getFinalContext(ctx, "GetTask", agent)
defer cancel()

secrets := make([]*admin.Secret, 0)
for _, s := range metadata.Secrets {
secrets = append(secrets, &admin.Secret{Value: s.Value})
}

request := &admin.GetTaskRequest{
TaskType: metadata.TaskCategory.Name,
TaskCategory: &metadata.TaskCategory,
ResourceMeta: metadata.AgentResourceMeta,
Secrets: secrets,
Secrets: secretPtr(metadata.Secrets),
}
res, err := client.GetTask(finalCtx, request)
if err != nil {
Expand Down Expand Up @@ -251,16 +247,11 @@ func (p Plugin) Delete(ctx context.Context, taskCtx webapi.DeleteContext) error
finalCtx, cancel := getFinalContext(ctx, "DeleteTask", agent)
defer cancel()

secrets := make([]*admin.Secret, 0)
for _, s := range metadata.Secrets {
secrets = append(secrets, &admin.Secret{Value: s.Value})
}

request := &admin.DeleteTaskRequest{
TaskType: metadata.TaskCategory.Name,
TaskCategory: &metadata.TaskCategory,
ResourceMeta: metadata.AgentResourceMeta,
Secrets: secrets,
Secrets: secretPtr(metadata.Secrets),

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

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/webapi/agent/plugin.go#L254

Added line #L254 was not covered by tests
}
_, err = client.DeleteTask(finalCtx, request)
return err
Expand Down Expand Up @@ -344,6 +335,14 @@ func (p Plugin) getAsyncAgentClient(ctx context.Context, agent *Deployment) (ser
return client, nil
}

func secretPtr(secrets []admin.Secret) []*admin.Secret {
res := make([]*admin.Secret, 0)
for _, s := range secrets {
res = append(res, &s)
}

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

View check run for this annotation

Codecov / codecov/patch

flyteplugins/go/tasks/plugins/webapi/agent/plugin.go#L341-L342

Added lines #L341 - L342 were not covered by tests
return res
}

func writeOutput(ctx context.Context, taskCtx webapi.StatusContext, outputs *flyteIdl.LiteralMap) error {
taskTemplate, err := taskCtx.TaskReader().Read(ctx)
if err != nil {
Expand Down

0 comments on commit 42bbe73

Please sign in to comment.