Skip to content

Commit

Permalink
Merge pull request containerd#87 from katiewasnothere/parse_signals_p…
Browse files Browse the repository at this point in the history
…latform

Parse container stop signal based on sandbox platform
  • Loading branch information
katiewasnothere authored Dec 3, 2020
2 parents bfec7b9 + 7a82672 commit 93e0504
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 22 deletions.
11 changes: 9 additions & 2 deletions pkg/server/container_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"syscall"
"time"

"github.com/containerd/containerd"
eventtypes "github.com/containerd/containerd/api/events"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/log"
"github.com/docker/docker/pkg/signal"
"github.com/pkg/errors"
"golang.org/x/net/context"

Expand Down Expand Up @@ -125,11 +125,18 @@ func (c *criService) stopContainer(ctx context.Context, container containerstore
}
}
}
sig, err := signal.ParseSignal(stopSignal)

sandboxPlatform, err := c.getSandboxPlatform(container.Metadata.SandboxID)
if err != nil {
return errors.Wrapf(err, "failed to get container's sandbox platform")
}

sig, err := containerd.ParsePlatformSignal(stopSignal, sandboxPlatform)
if err != nil {
return errors.Wrapf(err, "failed to parse stop signal %q", stopSignal)
}
log.G(ctx).Infof("Stop container %q with signal %v", id, sig)

if err = task.Kill(ctx, sig); err != nil && !errdefs.IsNotFound(err) {
return errors.Wrapf(err, "failed to stop container %q", id)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/helpers_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"regexp"

"github.com/containerd/containerd/platforms"
"github.com/opencontainers/selinux/go-selinux"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors"
Expand Down Expand Up @@ -65,3 +66,7 @@ func checkSelinuxLevel(level string) (bool, error) {
}
return true, nil
}

func (c *criService) getSandboxPlatform(_ string) (string, error) {
return platforms.DefaultString(), nil
}
28 changes: 28 additions & 0 deletions pkg/server/helpers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,38 @@ limitations under the License.
package server

import (
runhcsoptions "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
criconfig "github.com/containerd/cri/pkg/config"
"github.com/pkg/errors"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
)

// initSelinuxOpts is not supported on Windows.
func initSelinuxOpts(selinuxOpt *runtime.SELinuxOption) (string, string, error) {
return "", "", nil
}

func (c *criService) getSandboxPlatform(sandboxID string) (string, error) {
sandbox, err := c.sandboxStore.Get(sandboxID)
if err != nil {
return "", err
}

// Get the RuntimeHandler config overrides
var ociRuntime criconfig.Runtime
if sandbox.RuntimeHandler != "" {
ociRuntime = c.config.Runtimes[sandbox.RuntimeHandler]
} else {
ociRuntime = c.config.DefaultRuntime
}
runtimeOpts, err := generateRuntimeOptions(ociRuntime, c.config)
if err != nil {
return "", errors.Wrap(err, "failed to generate runtime options")
}
rhcso := runtimeOpts.(*runhcsoptions.Options)
sandboxPlatform := rhcso.SandboxPlatform
if sandboxPlatform == "" {
sandboxPlatform = "windows/amd64"
}
return sandboxPlatform, nil
}
2 changes: 1 addition & 1 deletion vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ github.com/blang/semver v3.1.0
github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895
github.com/containerd/cgroups caf71576c8b19daf80ab4685916e4d5b4c74887e
github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23
github.com/containerd/containerd 12e49bbd4d6124ebdbbc3f66919416f360b46dda https://github.com/kevpar/containerd.git # fork/release/1.4
github.com/containerd/containerd 4fd5652678e9650bfefd3a8de1e697e84c25844b https://github.com/kevpar/containerd.git # fork/release/1.4
github.com/containerd/continuity bd77b46c8352f74eb12c85bdc01f4b90f69d66b4
github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c
github.com/containerd/go-cni 40bcf8ec8acd7372be1d77031d585d5d8e561c90
Expand Down
12 changes: 8 additions & 4 deletions vendor/github.com/containerd/containerd/signals.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/containerd/containerd/signals_unix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 112 additions & 15 deletions vendor/github.com/containerd/containerd/signals_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/gogo/protobuf/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 93e0504

Please sign in to comment.