fix: 从后端恢复 Runner claim
This commit is contained in:
@@ -116,6 +116,28 @@ type Backend struct {
|
||||
Config Config
|
||||
}
|
||||
|
||||
func (b Backend) RecoverAssignments(ctx context.Context) ([]taskassignment.Assignment, error) {
|
||||
if err := b.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pods, err := b.API.ListPods(ctx, b.Config.Namespace, "ci.ddupan.top/backend=pod")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list recoverable assignment Pods: %w", err)
|
||||
}
|
||||
assignments := make([]taskassignment.Assignment, 0, len(pods))
|
||||
for _, pod := range pods {
|
||||
if pod.Labels[terminalLabel] == "true" {
|
||||
continue
|
||||
}
|
||||
assignment, err := taskassignment.FromMetadata(pod.Labels, pod.Annotations, b.Config.TrustDomain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("recover Pod %s: %w", pod.Name, err)
|
||||
}
|
||||
assignments = append(assignments, assignment)
|
||||
}
|
||||
return assignments, nil
|
||||
}
|
||||
|
||||
func (b Backend) Find(ctx context.Context, assignmentID string) (*taskworker.Executor, error) {
|
||||
if err := b.validate(); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user