|
7 | 7 | "fmt" |
8 | 8 | "os" |
9 | 9 | "os/exec" |
| 10 | + "strconv" |
10 | 11 | "strings" |
| 12 | + "syscall" |
11 | 13 | "sync" |
12 | 14 | "time" |
13 | 15 |
|
@@ -556,6 +558,12 @@ func New(log *logger.Logger) (*Deployer, error) { |
556 | 558 | d.roxCACertFile = caCert |
557 | 559 | } |
558 | 560 |
|
| 561 | + if pidStr := os.Getenv("ROXIE_PORT_FORWARD_PID"); pidStr != "" { |
| 562 | + if pid, err := strconv.Atoi(pidStr); err == nil { |
| 563 | + d.portForwardPID = pid |
| 564 | + } |
| 565 | + } |
| 566 | + |
559 | 567 | d.kubeContext = env.GetCurrentContext() |
560 | 568 |
|
561 | 569 | clusterResourceKinds, err := d.getClusterResourceKinds() |
@@ -602,6 +610,22 @@ func (d *Deployer) Cleanup() { |
602 | 610 | } |
603 | 611 | } |
604 | 612 |
|
| 613 | +func (d *Deployer) stopDetachedPortForward() { |
| 614 | + if d.portForwardPID == 0 { |
| 615 | + return |
| 616 | + } |
| 617 | + proc, err := os.FindProcess(d.portForwardPID) |
| 618 | + if err != nil { |
| 619 | + return |
| 620 | + } |
| 621 | + if err := proc.Signal(syscall.SIGKILL); err != nil { |
| 622 | + d.logger.Dimf("Detached port-forward (pid %d) already gone", d.portForwardPID) |
| 623 | + return |
| 624 | + } |
| 625 | + d.logger.Dimf("Stopped detached port-forward (pid %d)", d.portForwardPID) |
| 626 | + d.portForwardPID = 0 |
| 627 | +} |
| 628 | + |
605 | 629 | // Deploy deploys the specified components to the cluster. |
606 | 630 | func (d *Deployer) Deploy(ctx context.Context, components component.Component, resources, exposure string) error { |
607 | 631 | adjustedResources, adjustedExposure, adjustedPortForward := d.clusterDefaults.ApplyConvenienceDefaults( |
@@ -757,6 +781,7 @@ func (d *Deployer) teardownCentral(ctx context.Context) error { |
757 | 781 | } |
758 | 782 |
|
759 | 783 | d.portForward.Stop() |
| 784 | + d.stopDetachedPortForward() |
760 | 785 |
|
761 | 786 | // Add pause-reconcile annotation to not have the operator interfere during resource deletion. |
762 | 787 | if d.doesResourceExist(ctx, "central", "stackrox-central-services", d.centralNamespace) { |
|
0 commit comments