Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #54 from dweomer/containerd
Browse files Browse the repository at this point in the history
support running as containerd
  • Loading branch information
dweomer authored May 21, 2020
2 parents 96e2540 + 602f9a5 commit 18e5fb5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
13 changes: 13 additions & 0 deletions cmd/daemon/containerd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !linux

package daemon

import (
"os"

"github.com/sirupsen/logrus"
)

func Containerd() {
logrus.Fatalf("%s only supported on Linux", os.Args[0])
}
23 changes: 23 additions & 0 deletions cmd/daemon/containerd_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package daemon

import (
"fmt"
"os"

"github.com/urfave/cli"
"k8s.io/klog"
)

func Containerd() {
app := newApp()
app.Name = "containerd"
app.HelpName = app.Name
app.Before = func(clx *cli.Context) error {
klog.InitFlags(nil)
return nil
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", app.Name, err)
os.Exit(1)
}
}
17 changes: 10 additions & 7 deletions cmd/daemon/daemon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"k8s.io/klog"
)

func Command() *cliv2.Command {
func newApp() *cliv1.App {
app := command.App()
app.Name = "k3c daemon"
app.Usage = "containerd++ (cri, buildkit and k3c)"
Expand Down Expand Up @@ -145,7 +145,8 @@ the backend to support the Docker work-alike frontend of k3c.`
Destination: &cri.Config.SandboxImage,
},
}...)
app.Before = func(before cliv1.BeforeFunc) cliv1.BeforeFunc {

app.Action = func(action interface{}) cliv1.ActionFunc {
return func(clx *cliv1.Context) error {
// setup env
for i := range clx.App.Flags {
Expand Down Expand Up @@ -212,13 +213,15 @@ the backend to support the Docker work-alike frontend of k3c.`
if err := os.Setenv("PATH", fmt.Sprintf("%s%c%s", os.Getenv("PATH"), os.PathListSeparator, filepath.Join(root, "bin", "aux"))); err != nil {
return err
}
if before != nil {
return before(clx)
}
return nil
return cliv1.HandleAction(action, clx)
}
}(app.Before)
}(app.Action)

return app
}

func Command() *cliv2.Command {
app := newApp()
return &cliv2.Command{
Name: "daemon",
Usage: "Run the container daemon",
Expand Down
14 changes: 11 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ package main

import (
"os"
"path/filepath"

"github.com/containerd/containerd/pkg/seed"
"github.com/rancher/k3c/cmd/daemon"
"github.com/rancher/k3c/pkg/cli/app"
"github.com/sirupsen/logrus"
)

func main() {
seed.WithTimeAndRand()
app := app.New()
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
self := filepath.Base(os.Args[0])
switch self {
case "containerd":
daemon.Containerd()
default:
app := app.New()
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
}

0 comments on commit 18e5fb5

Please sign in to comment.