Skip to content

Commit 9aed734

Browse files
authored
cmd/operator-sdk/internal: explicitly set GOROOT (#2754)
* cmd/operator-sdk/internal: explicitly set GOROOT If the user's GOROOT does not match the GOROOT used to build the binary, they would be required to explicitly set the GOROOT env variable to their go env GOROOT. To avoid this step for end-users we can explicitly pull the GOROOT from go env and explicitly set the GOROOT env variable. Fixes: #2744
1 parent 1e06378 commit 9aed734

File tree

1 file changed

+11
-0
lines changed
  • cmd/operator-sdk/internal/genutil

1 file changed

+11
-0
lines changed

cmd/operator-sdk/internal/genutil/k8s.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package genutil
1717
import (
1818
"fmt"
1919
"os"
20+
"os/exec"
2021
"path/filepath"
2122
"strings"
2223

@@ -34,6 +35,16 @@ import (
3435
func K8sCodegen() error {
3536
projutil.MustInProjectRoot()
3637

38+
goEnv, err := exec.Command("go", "env", "GOROOT").CombinedOutput()
39+
if err != nil {
40+
return fmt.Errorf("failed to get GOROOT from go env: %w", err)
41+
}
42+
goRoot := strings.TrimSuffix(string(goEnv), "\n")
43+
log.Debugf("Setting GOROOT=%s", goRoot)
44+
if err := os.Setenv("GOROOT", goRoot); err != nil {
45+
return fmt.Errorf("failed to set env GOROOT=%s: %w", goRoot, err)
46+
}
47+
3748
repoPkg := projutil.GetGoPkg()
3849

3950
gvMap, err := k8sutil.ParseGroupSubpackages(scaffold.ApisDir)

0 commit comments

Comments
 (0)