diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index f4f0848..d981ba2 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -36,7 +36,7 @@ jobs: name: test strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - name: Check out code diff --git a/mdz/pkg/server/agentd_run.go b/mdz/pkg/server/agentd_run.go index 9c16080..fab6e3a 100644 --- a/mdz/pkg/server/agentd_run.go +++ b/mdz/pkg/server/agentd_run.go @@ -3,7 +3,6 @@ package server import ( "fmt" "os/exec" - "syscall" ) type agentDRunStep struct { @@ -15,9 +14,7 @@ type agentDRunStep struct { func (s *agentDRunStep) Run() error { fmt.Fprintf(s.options.OutputStream, "🚧 Running the agent for docker runtime...\n") cmd := exec.Command("/bin/sh", "-c", "mdz local-agent &") - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) if s.options.Verbose { cmd.Stderr = s.options.OutputStream cmd.Stdout = s.options.OutputStream diff --git a/mdz/pkg/server/gpu_install.go b/mdz/pkg/server/gpu_install.go index a3f2786..ea2dd4f 100644 --- a/mdz/pkg/server/gpu_install.go +++ b/mdz/pkg/server/gpu_install.go @@ -8,7 +8,6 @@ import ( "os/exec" "path/filepath" "regexp" - "syscall" ) //go:embed gpu-resource.yaml @@ -60,9 +59,7 @@ func (s *gpuInstallStep) Run() error { fmt.Fprintf(s.options.OutputStream, "🚧 Initializing the GPU resource...\n") cmd := exec.Command("/bin/sh", "-c", "sudo k3s kubectl apply -f -") - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) stdin, err := cmd.StdinPipe() if err != nil { diff --git a/mdz/pkg/server/k3s_destroy.go b/mdz/pkg/server/k3s_destroy.go index 38158b3..03f3f77 100644 --- a/mdz/pkg/server/k3s_destroy.go +++ b/mdz/pkg/server/k3s_destroy.go @@ -3,7 +3,6 @@ package server import ( "fmt" "os/exec" - "syscall" ) // k3sDestroyAllStep installs k3s and related tools. @@ -15,9 +14,7 @@ func (s *k3sDestroyAllStep) Run() error { fmt.Fprintf(s.options.OutputStream, "🚧 Destroy the OpenModelz Cluster...\n") // TODO(gaocegege): Embed the script into the binary. cmd := exec.Command("/bin/sh", "-c", "/usr/local/bin/k3s-uninstall.sh") - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) if s.options.Verbose { cmd.Stderr = s.options.OutputStream cmd.Stdout = s.options.OutputStream diff --git a/mdz/pkg/server/k3s_install.go b/mdz/pkg/server/k3s_install.go index 6a823ec..228435a 100644 --- a/mdz/pkg/server/k3s_install.go +++ b/mdz/pkg/server/k3s_install.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os/exec" - "syscall" ) //go:embed k3s-install.sh @@ -18,9 +17,7 @@ type k3sInstallStep struct { func (s *k3sInstallStep) Run() error { checkCmd := exec.Command("/bin/sh", "-c", "sudo k3s kubectl get nodes") - checkCmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(checkCmd) checkCmd.Stdout = nil checkCmd.Stderr = nil err := checkCmd.Run() @@ -33,10 +30,8 @@ func (s *k3sInstallStep) Run() error { // TODO(gaocegege): Embed the script into the binary. // Always run start, do not check the hash to decide. cmd := exec.Command("/bin/sh", "-c", "INSTALL_K3S_VERSION=v1.27.3+k3s1 INSTALL_K3S_EXEC='--disable=traefik' INSTALL_K3S_FORCE_RESTART=true K3S_KUBECONFIG_MODE=644 K3S_TOKEN=openmodelz sh -") - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) stdin, err := cmd.StdinPipe() if err != nil { return err diff --git a/mdz/pkg/server/k3s_join.go b/mdz/pkg/server/k3s_join.go index 253365f..bc2b58b 100644 --- a/mdz/pkg/server/k3s_join.go +++ b/mdz/pkg/server/k3s_join.go @@ -4,7 +4,6 @@ import ( "fmt" "io" "os/exec" - "syscall" ) // k3sJoinStep installs k3s and related tools. @@ -18,9 +17,7 @@ func (s *k3sJoinStep) Run() error { cmdStr := fmt.Sprintf("INSTALL_K3S_FORCE_RESTART=true K3S_KUBECONFIG_MODE=644 K3S_TOKEN=openmodelz K3S_URL=https://%s:6443 sh -", s.options.ServerIP) cmd := exec.Command("/bin/sh", "-c", cmdStr) - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) if s.options.Verbose { cmd.Stderr = s.options.OutputStream cmd.Stdout = s.options.OutputStream diff --git a/mdz/pkg/server/k3s_killall.go b/mdz/pkg/server/k3s_killall.go index b797d31..efe55e5 100644 --- a/mdz/pkg/server/k3s_killall.go +++ b/mdz/pkg/server/k3s_killall.go @@ -3,7 +3,6 @@ package server import ( "fmt" "os/exec" - "syscall" ) // k3sKillAllStep installs k3s and related tools. @@ -15,9 +14,7 @@ func (s *k3sKillAllStep) Run() error { fmt.Fprintf(s.options.OutputStream, "🚧 Stopping the OpenModelz Cluster...\n") // TODO(gaocegege): Embed the script into the binary. cmd := exec.Command("/bin/sh", "-c", "/usr/local/bin/k3s-killall.sh") - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) if s.options.Verbose { cmd.Stderr = s.options.OutputStream cmd.Stdout = s.options.OutputStream diff --git a/mdz/pkg/server/k3s_prepare.go b/mdz/pkg/server/k3s_prepare.go index 2e3d77d..027d138 100644 --- a/mdz/pkg/server/k3s_prepare.go +++ b/mdz/pkg/server/k3s_prepare.go @@ -6,7 +6,6 @@ import ( "os/exec" "path/filepath" "strings" - "syscall" "text/template" ) @@ -43,9 +42,7 @@ func (s *k3sPrepare) Run() error { filepath.Join(mirrorPath, mirrorFile), buf.String(), )) - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) if s.options.Verbose { cmd.Stderr = s.options.OutputStream cmd.Stdout = s.options.OutputStream diff --git a/mdz/pkg/server/nginx_install.go b/mdz/pkg/server/nginx_install.go index 651b4e4..e5f550a 100644 --- a/mdz/pkg/server/nginx_install.go +++ b/mdz/pkg/server/nginx_install.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os/exec" - "syscall" ) //go:embed nginx-dep.yaml @@ -20,9 +19,7 @@ func (s *nginxInstallStep) Run() error { fmt.Fprintf(s.options.OutputStream, "🚧 Initializing the load balancer...\n") cmd := exec.Command("/bin/sh", "-c", "sudo k3s kubectl apply -f -") - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) stdin, err := cmd.StdinPipe() if err != nil { diff --git a/mdz/pkg/server/openmodelz_install.go b/mdz/pkg/server/openmodelz_install.go index f5a4e0a..844d87a 100644 --- a/mdz/pkg/server/openmodelz_install.go +++ b/mdz/pkg/server/openmodelz_install.go @@ -8,7 +8,6 @@ import ( "os/exec" "regexp" "strings" - "syscall" "github.com/sirupsen/logrus" ) @@ -27,9 +26,7 @@ func (s *openModelZInstallStep) Run() error { fmt.Fprintf(s.options.OutputStream, "🚧 Initializing the server...\n") cmd := exec.Command("/bin/sh", "-c", "sudo k3s kubectl apply -f -") - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) stdin, err := cmd.StdinPipe() if err != nil { @@ -92,9 +89,7 @@ func (s *openModelZInstallStep) Run() error { func (s *openModelZInstallStep) Verify() error { fmt.Fprintf(s.options.OutputStream, "🚧 Verifying the load balancer...\n") cmd := exec.Command("/bin/sh", "-c", "sudo k3s kubectl get svc -n ingress-nginx ingress-nginx-controller -o jsonpath={@.status.loadBalancer.ingress}") - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + sysProcAttr(cmd) output, err := cmd.CombinedOutput() if err != nil { logrus.Debugf("failed to get the ingress ip: %v", err) diff --git a/mdz/pkg/server/proc_attr_linux.go b/mdz/pkg/server/proc_attr_linux.go new file mode 100644 index 0000000..be978ae --- /dev/null +++ b/mdz/pkg/server/proc_attr_linux.go @@ -0,0 +1,15 @@ +//go:build linux + +package server + +import ( + "os/exec" + "syscall" +) + +func sysProcAttr(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + Pdeathsig: syscall.SIGINT, + } +} diff --git a/mdz/pkg/server/proc_attr_other.go b/mdz/pkg/server/proc_attr_other.go new file mode 100644 index 0000000..ccc82ad --- /dev/null +++ b/mdz/pkg/server/proc_attr_other.go @@ -0,0 +1,14 @@ +//go:build !linux + +package server + +import ( + "os/exec" + "syscall" +) + +func sysProcAttr(cmd *exec.Cmd) { + cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + } +}