Skip to content

Commit

Permalink
make containerd restart code platform specific
Browse files Browse the repository at this point in the history
  • Loading branch information
phyrog committed Mar 4, 2024
1 parent fd043fa commit bd762b4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/containerd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewConfig(hostFs afero.Fs, configPath string) *Config {

func (c *Config) AddRuntime(shimPath string) error {
runtimeName := shim.RuntimeName(path.Base(shimPath))
l := slog.With("runtime", runtimeName)

cfg := generateConfig(shimPath, runtimeName)

Expand All @@ -52,7 +53,7 @@ func (c *Config) AddRuntime(shimPath string) error {

// Warn if config.toml already contains runtimeName
if strings.Contains(string(data), runtimeName) {
slog.Info(fmt.Sprintf("config for runtime '%s' already exists, skipping", runtimeName))
l.Info("runtime config already exists, skipping")
return nil
}

Expand All @@ -74,6 +75,7 @@ func (c *Config) AddRuntime(shimPath string) error {

func (c *Config) RemoveRuntime(shimPath string) (changed bool, err error) {
runtimeName := shim.RuntimeName(path.Base(shimPath))
l := slog.With("runtime", runtimeName)

cfg := generateConfig(shimPath, runtimeName)

Expand All @@ -85,7 +87,7 @@ func (c *Config) RemoveRuntime(shimPath string) (changed bool, err error) {

// Warn if config.toml does not contain the runtimeName
if !strings.Contains(string(data), runtimeName) {
slog.Warn(fmt.Sprintf("config for runtime '%s' does not exist, skipping", runtimeName))
l.Warn("runtime config does not exist, skipping")
return false, nil
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/containerd/restart.go → pkg/containerd/restart_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build unix
// +build unix

/*
Copyright The KWasm Authors.
Expand Down Expand Up @@ -31,7 +34,7 @@ func (c *Config) RestartRuntime() error {
if err != nil {
return err
}
slog.Info("found containerd pid", "pid", pid)
slog.Debug("found containerd process", "pid", pid)

err = syscall.Kill(pid, syscall.SIGHUP)

Expand All @@ -44,7 +47,6 @@ func (c *Config) RestartRuntime() error {
func getPid() (int, error) {
processes, err := psProcesses()
if err != nil {
slog.Info("psProcesses() Failed, are you using windows?")
return 0, fmt.Errorf("could not get processes: %+v", err)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build unix
// +build unix

package containerd

import (
Expand Down
8 changes: 8 additions & 0 deletions pkg/containerd/restart_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build windows
// +build windows

package containerd

func (c *Config) RestartRuntime() error {
panic("restarting containerd not implemented")
}

0 comments on commit bd762b4

Please sign in to comment.