Skip to content

Commit 1f59315

Browse files
fanminshihasbro17
authored andcommitted
commands: update up local command to run cmd/manager/main.go
1 parent 159ee83 commit 1f59315

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

commands/operator-sdk/cmd/up/local.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package up
1616

1717
import (
1818
"fmt"
19+
"log"
1920
"os"
2021
"os/exec"
2122
"os/signal"
@@ -25,7 +26,6 @@ import (
2526
"syscall"
2627

2728
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd/cmdutil"
28-
cmdError "github.com/operator-framework/operator-sdk/commands/operator-sdk/error"
2929
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
3030

3131
"github.com/spf13/cobra"
@@ -56,18 +56,13 @@ var (
5656
)
5757

5858
const (
59-
gocmd = "go"
60-
run = "run"
61-
cmd = "cmd"
62-
main = "main.go"
6359
defaultConfigPath = ".kube/config"
6460
)
6561

6662
func upLocalFunc(cmd *cobra.Command, args []string) {
6763
mustKubeConfig()
6864
cmdutil.MustInProjectRoot()
69-
c := cmdutil.GetConfig()
70-
upLocal(c.ProjectName)
65+
upLocal()
7166
}
7267

7368
// mustKubeConfig checks if the kubeconfig file exists.
@@ -76,31 +71,31 @@ func mustKubeConfig() {
7671
if len(kubeConfig) == 0 {
7772
usr, err := user.Current()
7873
if err != nil {
79-
cmdError.ExitWithError(cmdError.ExitError, fmt.Errorf("failed to determine user's home dir: %v", err))
74+
log.Fatalf("failed to determine user's home dir: %v", err)
8075
}
8176
kubeConfig = filepath.Join(usr.HomeDir, defaultConfigPath)
8277
}
8378

8479
_, err := os.Stat(kubeConfig)
8580
if err != nil && os.IsNotExist(err) {
86-
cmdError.ExitWithError(cmdError.ExitError, fmt.Errorf("failed to find the kubeconfig file (%v): %v", kubeConfig, err))
81+
log.Fatalf("failed to find the kubeconfig file (%v): %v", kubeConfig, err)
8782
}
8883
}
8984

90-
func upLocal(projectName string) {
91-
args := []string{run, filepath.Join(cmd, projectName, main)}
85+
func upLocal() {
86+
args := []string{"run", filepath.Join("cmd", "manager", "main.go")}
9287
if operatorFlags != "" {
9388
extraArgs := strings.Split(operatorFlags, " ")
9489
args = append(args, extraArgs...)
9590
}
96-
dc := exec.Command(gocmd, args...)
91+
dc := exec.Command("go", args...)
9792
c := make(chan os.Signal)
9893
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
9994
go func() {
10095
<-c
10196
err := dc.Process.Kill()
10297
if err != nil {
103-
cmdError.ExitWithError(cmdError.ExitError, fmt.Errorf("failed to terminate the operator: %v", err))
98+
log.Fatalf("failed to terminate the operator: %v", err)
10499
}
105100
os.Exit(0)
106101
}()
@@ -109,6 +104,6 @@ func upLocal(projectName string) {
109104
dc.Env = append(os.Environ(), fmt.Sprintf("%v=%v", k8sutil.KubeConfigEnvVar, kubeConfig), fmt.Sprintf("%v=%v", k8sutil.WatchNamespaceEnvVar, namespace))
110105
err := dc.Run()
111106
if err != nil {
112-
cmdError.ExitWithError(cmdError.ExitError, fmt.Errorf("failed to run operator locally: %v", err))
107+
log.Fatalf("failed to run operator locally: %v", err)
113108
}
114109
}

0 commit comments

Comments
 (0)