Skip to content

Commit 75c0331

Browse files
authored
pkg/test/main_entry.go: build local binary instead of go run (#1089)
* pkg/test/main_entry.go: build local binary instead of `go run` This allows us to kill the process on exti correctly, which wouldn't always work correctly when using `go run`
1 parent e816ba7 commit 75c0331

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Bug Fixes
1212

13+
- Fix issue where running `operator-sdk test local --up-local` would sometimes leave a running process in the background after exit ([#1089](https://github.com/operator-framework/operator-sdk/pull/1020))
14+
1315
## v0.5.0
1416

1517
### Added

pkg/test/main_entry.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"k8s.io/client-go/tools/clientcmd"
3030

31+
"github.com/operator-framework/operator-sdk/internal/util/projutil"
3132
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
3233
"github.com/operator-framework/operator-sdk/pkg/scaffold"
3334
log "github.com/sirupsen/logrus"
@@ -63,10 +64,17 @@ func MainEntry(m *testing.M) {
6364
var localCmd *exec.Cmd
6465
var localCmdOutBuf, localCmdErrBuf bytes.Buffer
6566
if *localOperator {
66-
// TODO: make a generic 'up-local' function to deduplicate shared code between this and cmd/up/local
67-
// taken from commands/operator-sdk/cmd/up/local.go
68-
runArgs := append([]string{"run"}, []string{filepath.Join(scaffold.ManagerDir, scaffold.CmdFile)}...)
69-
localCmd = exec.Command("go", runArgs...)
67+
absProjectPath := projutil.MustGetwd()
68+
projectName := filepath.Base(absProjectPath)
69+
outputBinName := filepath.Join(scaffold.BuildBinDir, projectName+"-local")
70+
args := []string{"build", "-o", outputBinName}
71+
args = append(args, filepath.Join(scaffold.ManagerDir, scaffold.CmdFile))
72+
bc := exec.Command("go", args...)
73+
if err := projutil.ExecCmd(bc); err != nil {
74+
log.Fatalf("Failed to build local operator binary: %s", err)
75+
}
76+
77+
localCmd = exec.Command(outputBinName, args...)
7078
localCmd.Stdout = &localCmdOutBuf
7179
localCmd.Stderr = &localCmdErrBuf
7280
c := make(chan os.Signal)

0 commit comments

Comments
 (0)