Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] PoC support for shim v2 to run kata containers v2 #11238

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/podman/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
_ "github.com/containers/podman/v3/cmd/podman/pods"
"github.com/containers/podman/v3/cmd/podman/registry"
_ "github.com/containers/podman/v3/cmd/podman/secrets"
_ "github.com/containers/podman/v3/cmd/podman/shimv2"
_ "github.com/containers/podman/v3/cmd/podman/system"
_ "github.com/containers/podman/v3/cmd/podman/system/connection"
_ "github.com/containers/podman/v3/cmd/podman/volumes"
Expand Down
5 changes: 5 additions & 0 deletions cmd/podman/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {

pFlags.BoolVar(&opts.Trace, "trace", false, "Enable opentracing output (default false)")

// shimv2 flags
addressFlagName := "address"
pFlags.String(addressFlagName, "", "Address used by podman publish command and shimv2")

// Hide these flags for both ABI and Tunneling
for _, f := range []string{
"cpu-profile",
Expand All @@ -398,6 +402,7 @@ func rootFlags(cmd *cobra.Command, opts *entities.PodmanConfig) {
"memory-profile",
"registries-conf",
"trace",
"address",
} {
if err := pFlags.MarkHidden(f); err != nil {
logrus.Warnf("Unable to mark %s flag as hidden: %s", f, err.Error())
Expand Down
80 changes: 80 additions & 0 deletions cmd/podman/shimv2/publish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package shimv2

import (
"io/ioutil"
"os"

apievents "github.com/containerd/containerd/api/events"
"github.com/containerd/typeurl"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/gogo/protobuf/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

var (
// Hidden option, only used by shimv2 runtime to publish container events
publishCmd = &cobra.Command{
Use: "publish [options]",
Short: "Handle shimv2 events to update container state",
Long: "Handle shimv2 events to update container state",
RunE: publish,
Example: `podman --address [ADDRESS] publish --topic [TOPIC] --namespace [NAMESPACE]`,
Hidden: true,
}
)

func runFlags(cmd *cobra.Command) {
flags := cmd.Flags()

topicFlagName := "topic"
flags.String(topicFlagName, "", "")

namespaceFlagName := "namespace"
flags.String(namespaceFlagName, "", "")
}

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: publishCmd,
})

runFlags(publishCmd)
}

func publish(cmd *cobra.Command, args []string) error {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return errors.Wrap(err, "can not read stdin")
}

var any types.Any
if err := any.Unmarshal(data); err != nil {
return errors.Wrap(err, "can not unmarshal stdin")
}

e, err := typeurl.UnmarshalAny(&any)
if err != nil {
return errors.Wrap(err, "can not unmarshal shimv2 event")
}

// There are more shimv2 events but as of now only the exit event
// produced by the shimv2 runtime will trigger a container state update
containerID := ""
exitCode := 0
switch e.(type) {
case *apievents.TaskExit:
te, _ := e.(*apievents.TaskExit)
containerID = te.ContainerID
exitCode = int(te.ExitStatus)

if err := registry.ContainerEngine().Shimv2ContainerCleanup(
registry.Context(), containerID, exitCode); err != nil {
return errors.Wrap(err, "can not clean up shimv2 container")
}
default:
return nil
}

return nil
}
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ require (
github.com/checkpoint-restore/checkpointctl v0.0.0-20210922093614-c31748bec9f2
github.com/checkpoint-restore/go-criu/v5 v5.1.0
github.com/container-orchestrated-devices/container-device-interface v0.0.0-20210325223243-f99e8b6c10b9
github.com/containerd/containerd v1.5.5
github.com/containerd/fifo v1.0.0
github.com/containerd/ttrpc v1.0.2
github.com/containerd/typeurl v1.0.2
github.com/containernetworking/cni v1.0.1
github.com/containernetworking/plugins v1.0.1
github.com/containers/buildah v1.23.1
Expand All @@ -32,6 +36,7 @@ require (
github.com/fsnotify/fsnotify v1.5.1
github.com/ghodss/yaml v1.0.0
github.com/godbus/dbus/v5 v5.0.5
github.com/gogo/protobuf v1.3.2
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
github.com/google/uuid v1.3.0
github.com/gorilla/handlers v0.0.0-20150720190736-60c7bfde3e33
Expand Down Expand Up @@ -67,7 +72,10 @@ require (
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0
google.golang.org/grpc v1.41.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.22.2
k8s.io/apimachinery v0.22.2
)

replace google.golang.org/genproto => google.golang.org/genproto v0.0.0-20200117163144-32f20d992d24
Loading