-
Notifications
You must be signed in to change notification settings - Fork 44
fix/serviceaccount deletion β develop
#1392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
104b56d
92edb9e
dc02e7b
9665964
f967150
2021d2e
2bc183b
6f07339
4a96b7a
10bde50
a7fc01a
2bc8c53
775c24f
6946c9c
99b4bf6
5a567a2
206f414
957d200
ec64e00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -266,6 +266,16 @@ func (b *Backend) createResources(ctx context.Context, task *tes.Task, config *c | |||||||||||||||||||||||||||||||||||||||||||||||||
| func (b *Backend) cleanResources(ctx context.Context, taskId string) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| var errs error | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check whether this task used an externally-managed ServiceAccount (e.g. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // Gen3Workflow per-user SA supplied via _WORKER_SA tag). If so, skip SA | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // deletion β the SA is shared across tasks and must not be torn down here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| externalSA := false | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if task, err := b.database.GetTask(ctx, &tes.GetTaskRequest{Id: taskId, View: tes.View_FULL.String()}); err == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if saName, exists := task.Tags["_WORKER_SA"]; exists && saName != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| externalSA = true | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+292
to
+301
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Delete Job | ||||||||||||||||||||||||||||||||||||||||||||||||||
| b.log.Debug("deleting Job", "taskID", taskId) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| err := resources.DeleteJob(ctx, b.conf, taskId, b.client, b.log) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+295
to
306
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| externalSA := false | |
| if task, err := b.database.GetTask(ctx, &tes.GetTaskRequest{Id: taskId, View: tes.View_FULL.String()}); err == nil { | |
| if saName, exists := task.Tags["_WORKER_SA"]; exists && saName != "" { | |
| externalSA = true | |
| } | |
| } | |
| // Delete Job | |
| b.log.Debug("deleting Job", "taskID", taskId) | |
| err := resources.DeleteJob(ctx, b.conf, taskId, b.client, b.log) | |
| // If task lookup fails, conservatively skip SA deletion rather than risk | |
| // deleting a shared externally-managed ServiceAccount. | |
| externalSA := false | |
| task, err := b.database.GetTask(ctx, &tes.GetTaskRequest{Id: taskId, View: tes.View_FULL.String()}) | |
| if err != nil { | |
| externalSA = true | |
| b.log.Error("getting task for ServiceAccount ownership check", "taskID", taskId, "error", err) | |
| } else if saName, exists := task.Tags["_WORKER_SA"]; exists && saName != "" { | |
| externalSA = true | |
| } | |
| // Delete Job | |
| b.log.Debug("deleting Job", "taskID", taskId) | |
| err = resources.DeleteJob(ctx, b.conf, taskId, b.client, b.log) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -283,7 +283,7 @@ func TestDeleteServiceAccount(t *testing.T) { | |
| t.Fatalf("Failed to create test ServiceAccount: %v", err) | ||
| } | ||
|
|
||
| err = DeleteServiceAccount(context.Background(), testTaskID, namespace, fakeClient, l) | ||
| err = DeleteServiceAccount(context.Background(), testTaskID, namespace, fakeClient, l, false) | ||
|
||
| if err != nil { | ||
| t.Errorf("DeleteServiceAccount failed: %v", err) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanResourcesfetches the task withView_FULLjust to inspect tags. In BoltDB (and likely other DB implementations), FULL also loads executor stdout/stderr and system logs, which is significantly more work than needed here. Usetes.View_BASIC(or another minimal view that still includesTags) to avoid unnecessary IO/CPU during cleanup.