Skip to content

Commit 7790669

Browse files
committed
use status manager to fetch pid when stopping workload
1 parent 025dd77 commit 7790669

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pkg/workloads/manager.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (d *defaultManager) stopRemoteWorkload(ctx context.Context, name string, ru
266266

267267
// Stop proxy if running
268268
if runConfig.BaseName != "" {
269-
d.stopProxyIfNeeded(name, runConfig.BaseName)
269+
d.stopProxyIfNeeded(ctx, name, runConfig.BaseName)
270270
}
271271

272272
// For remote workloads, we only need to clean up client configurations
@@ -497,7 +497,7 @@ func (d *defaultManager) deleteRemoteWorkload(ctx context.Context, name string,
497497

498498
// Stop proxy if running
499499
if runConfig.BaseName != "" {
500-
d.stopProxyIfNeeded(name, runConfig.BaseName)
500+
d.stopProxyIfNeeded(ctx, name, runConfig.BaseName)
501501
}
502502

503503
// Clean up associated resources
@@ -532,7 +532,7 @@ func (d *defaultManager) deleteContainerWorkload(ctx context.Context, name strin
532532

533533
// Stop proxy if running
534534
if container.IsRunning() {
535-
d.stopProxyIfNeeded(name, baseName)
535+
d.stopProxyIfNeeded(ctx, name, baseName)
536536
}
537537

538538
// Remove the container
@@ -570,14 +570,14 @@ func (d *defaultManager) getWorkloadContainer(ctx context.Context, name string)
570570
}
571571

572572
// stopProcess stops the proxy process associated with the container
573-
func (*defaultManager) stopProcess(name string) {
573+
func (d *defaultManager) stopProcess(ctx context.Context, name string) {
574574
if name == "" {
575575
logger.Warnf("Warning: Could not find base container name in labels")
576576
return
577577
}
578578

579-
// Try to read the PID file and kill the process
580-
pid, err := process.ReadPIDFile(name)
579+
// Try to read the PID and kill the process
580+
pid, err := d.statuses.GetWorkloadPID(ctx, name)
581581
if err != nil {
582582
logger.Errorf("No PID file found for %s, proxy may not be running in detached mode", name)
583583
return
@@ -598,10 +598,10 @@ func (*defaultManager) stopProcess(name string) {
598598
}
599599

600600
// stopProxyIfNeeded stops the proxy process if the workload has a base name
601-
func (d *defaultManager) stopProxyIfNeeded(name, baseName string) {
601+
func (d *defaultManager) stopProxyIfNeeded(ctx context.Context, name, baseName string) {
602602
logger.Infof("Removing proxy process for %s...", name)
603603
if baseName != "" {
604-
d.stopProcess(baseName)
604+
d.stopProcess(ctx, baseName)
605605
}
606606
}
607607

@@ -992,7 +992,7 @@ func (d *defaultManager) stopSingleContainerWorkload(ctx context.Context, worklo
992992

993993
name := labels.GetContainerBaseName(workload.Labels)
994994
// Stop the proxy process
995-
d.stopProcess(name)
995+
d.stopProcess(ctx, name)
996996
// TODO: refactor the StopProcess function to stop dealing explicitly with PID files.
997997
// Note that this is not a blocker for k8s since this code path is not called there.
998998
if err := d.statuses.ResetWorkloadPID(ctx, name); err != nil {

pkg/workloads/statuses/file_status.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ func (f *fileStatusManager) ListWorkloads(ctx context.Context, listAll bool, lab
207207
// TODO: Fetch the runconfig if present to populate additional fields like package, tool type, group etc.
208208
// There's currently an import cycle between this package and the runconfig package
209209

210-
for _, fileWorkload := range fileWorkloads {
211-
if fileWorkload.Remote { // Remote workloads are not managed by the container runtime
212-
delete(fileWorkloads, fileWorkload.Name) // Skip remote workloads here, we add them in workload manager
210+
for _, fileWorkload := range fileWorkloadsWithPID {
211+
if fileWorkload.workload.Remote { // Remote workloads are not managed by the container runtime
212+
delete(fileWorkloadsWithPID, fileWorkload.workload.Name) // Skip remote workloads here, we add them in workload manager
213213
}
214214
}
215215

0 commit comments

Comments
 (0)