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

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

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

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.