diff --git a/cmd/hepto.go b/cmd/hepto.go index d35771eecb75b3075f0b413d2b3628388c04c343..6d850abe506df8d8e11c628f21cbe9ad6fb0df91 100644 --- a/cmd/hepto.go +++ b/cmd/hepto.go @@ -2,18 +2,21 @@ package main import ( "context" + "fmt" + "io/ioutil" "os" "path/filepath" "forge.tedomum.net/acides/hepto/hepto/cmd/hepto" - "forge.tedomum.net/acides/hepto/hepto/cmd/shim" containerd "github.com/containerd/containerd/cmd/containerd/command" ctr "github.com/containerd/containerd/cmd/ctr/app" + runc "github.com/opencontainers/runc/cmd" + "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/runtime/v2/runc/manager" _ "github.com/containerd/containerd/runtime/v2/runc/pause" _ "github.com/containerd/containerd/runtime/v2/runc/task/plugin" shimv2 "github.com/containerd/containerd/runtime/v2/shim" - "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" //hostlocal "github.com/containernetworking/plugins/plugins/ipam/host-local" //"github.com/containernetworking/plugins/plugins/main/bridge" @@ -24,6 +27,15 @@ import ( kubectl "k8s.io/kubectl/pkg/cmd" ) +func init() { + ioutil.WriteFile("/dev/null", []byte(fmt.Sprintf("heptodebug... %v\n", os.Args)), 0o644) +} + +var shimPlugins = []string{ + "io.containerd.ttrpc.v1.pause", + "io.containerd.ttrpc.v1.task", +} + func main() { bin := filepath.Base(os.Args[0]) var err error @@ -33,21 +45,30 @@ func main() { // mount with very simple very formatted arguments in that order: // mount -t tmpfs -o size=1234 /src /dst err = unix.Mount(os.Args[5], os.Args[6], os.Args[2], 0, os.Args[4]) - } else if bin == "containerd" { + } else if bin == "containerd" || (bin == "hepto" && len(os.Args) > 1 && os.Args[1] == "publish") { // Containerd is also available under hepto name, guess based on // call arguments // This is some of an edge case, where containerd uses os.Executable // to get the current binary path (hence hepto single binary) then // passes that path as -publish-binary to its shim for callback err = containerd.App().Run(os.Args) - } else if bin == "containerd-shim" { - // Run the containerd shim itself - // This is called by the shim client as the proper long-term shim - shim.ShimApp() - } else if bin == "containerd-shim-runc-v2" || (len(os.Args) > 1 && os.Args[1] == "-namespace") { - // Run the containerd shim client - // This is called as a first stage shim by embedded containerd + } else if bin == "containerd-shim-runc-v2" || (bin == "hepto" && len(os.Args) > 1 && os.Args[1] == "-namespace") { + // Run the containerd shim + // It is also available under hepto name, for similar reasons as + // containerd, hence the different guess condition + plugins := plugin.Graph(func(*plugin.Registration) bool {return false}) + for _, plug := range plugins { + plug.Disable = true + for _, uri := range shimPlugins{ + if uri == plug.URI() { + plug.Disable = false + break + } + } + } shimv2.RunManager(context.Background(), manager.NewShimManager("io.containerd.runc.v2")) + } else if bin == "runc" { + runc.Run() } else if bin == "ctr" { // Run containerd cli client, for debugging purposes err = ctr.New().Run(os.Args) @@ -55,8 +76,7 @@ func main() { // Run kubectl client, for debugging purposes err = kubectl.NewDefaultKubectlCommand().Execute() } else { - // If no hook ran a different command, simply - // run hepto + // If no hook ran a different command, simply run hepto hepto.Execute() } if err != nil {