feat: 自动清理终态 Pod 执行器
This commit is contained in:
@@ -87,10 +87,22 @@ func runController(ctx context.Context) error {
|
||||
}
|
||||
registry := runnerfacade.NewRegistry()
|
||||
gate := taskscheduler.NewSingleFlightGate()
|
||||
var podExecutorBackend *podbackend.Backend
|
||||
giteaClient := giteaactions.NewClient(giteaactions.DefaultHTTPClient(), config.GiteaURL, config.GiteaUUID, config.GiteaToken)
|
||||
facade := &runnerfacade.Facade{
|
||||
Registry: registry, Capabilities: capabilities, Upstream: giteaClient,
|
||||
OnTerminal: func(taskassignment.Assignment) { gate.Release() },
|
||||
OnTerminal: func(ctx context.Context, assignment taskassignment.Assignment) error {
|
||||
if assignment.Backend == taskassignment.BackendPod {
|
||||
if podExecutorBackend == nil {
|
||||
return errors.New("Pod lifecycle backend is not configured")
|
||||
}
|
||||
if err := podExecutorBackend.MarkTerminal(ctx, assignment.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
gate.Release()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
bootstrap := runnerbootstrap.Bootstrap{
|
||||
Capabilities: capabilities, FacadeURL: config.FacadeURL, FacadeSPIFFEID: config.FacadeSPIFFEID,
|
||||
@@ -136,11 +148,18 @@ func runController(ctx context.Context) error {
|
||||
SPIRECluster: config.SPIRECluster, SPIREClass: config.SPIREClass,
|
||||
SPIREAgentID: config.SPIREAgentID, ExecutorUID: config.PodExecutorUID,
|
||||
}}
|
||||
podExecutorBackend = &backend
|
||||
component, err := workerComponent(ctx, workerJS, config, taskassignment.BackendPod, config.PodCapacity, taskworker.Worker{Backend: backend, Bootstrap: bootstrap}, registry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
components[controller.PodWorker] = component
|
||||
lifecycle := podbackend.Lifecycle{Backend: backend, OnError: func(err error) { log.Printf("pod lifecycle: %v", err) }}
|
||||
components[controller.PodWorker] = runComponent(func(ctx context.Context) error {
|
||||
group, groupContext := errgroup.WithContext(ctx)
|
||||
group.Go(func() error { return component.Run(groupContext) })
|
||||
group.Go(func() error { return lifecycle.Run(groupContext) })
|
||||
return group.Wait()
|
||||
})
|
||||
}
|
||||
if slices.Contains(config.Components, controller.VMWorker) {
|
||||
lifecycle := opensandboxbackend.NewLifecycleClient(config.OpenSandboxURL, config.OpenSandboxAPIKey, &http.Client{Timeout: 60 * time.Second})
|
||||
|
||||
Reference in New Issue
Block a user