diff --git a/cmd/ctr/main.go b/cmd/ctr/main.go index 7361aee43d..378258c46e 100644 --- a/cmd/ctr/main.go +++ b/cmd/ctr/main.go @@ -1,50 +1,7 @@ -/* - Copyright The containerd Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - package main -import ( - "fmt" - "os" - - "github.com/containerd/containerd/cmd/ctr/app" - "github.com/containerd/containerd/pkg/seed" - "github.com/urfave/cli" -) - -func init() { - seed.WithTimeAndRand() -} +import "github.com/rancher/k3s/pkg/ctr" func main() { - app := app.New() - for i, flag := range app.Flags { - if sFlag, ok := flag.(cli.StringFlag); ok { - if sFlag.Name == "address, a" { - sFlag.Value = "/run/k3s/containerd/containerd.sock" - app.Flags[i] = sFlag - } else if sFlag.Name == "namespace, n" { - sFlag.Value = "k8s.io" - app.Flags[i] = sFlag - } - } - } - - if err := app.Run(os.Args); err != nil { - fmt.Fprintf(os.Stderr, "ctr: %s\n", err) - os.Exit(1) - } + ctr.Main() } diff --git a/cmd/k3s/main.go b/cmd/k3s/main.go index 055bed47f1..d02e7484a3 100644 --- a/cmd/k3s/main.go +++ b/cmd/k3s/main.go @@ -27,8 +27,8 @@ func main() { cmds.NewServerCommand(wrap("k3s-server", os.Args)), cmds.NewAgentCommand(wrap("k3s-agent", os.Args)), cmds.NewKubectlCommand(externalCLIAction("kubectl")), - //cmds.NewCtrCommand(externalCLIAction("ctr")), cmds.NewCRICTL(externalCLIAction("crictl")), + cmds.NewCtrCommand(externalCLIAction("ctr")), } err := app.Run(os.Args) diff --git a/cmd/server/main.go b/cmd/server/main.go index 1557e5d008..7fcd6e047b 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -9,9 +9,11 @@ import ( "github.com/rancher/k3s/pkg/cli/agent" "github.com/rancher/k3s/pkg/cli/cmds" "github.com/rancher/k3s/pkg/cli/crictl" + "github.com/rancher/k3s/pkg/cli/ctr" "github.com/rancher/k3s/pkg/cli/kubectl" "github.com/rancher/k3s/pkg/cli/server" "github.com/rancher/k3s/pkg/containerd" + ctr2 "github.com/rancher/k3s/pkg/ctr" kubectl2 "github.com/rancher/k3s/pkg/kubectl" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -21,6 +23,7 @@ func init() { reexec.Register("containerd", containerd.Main) reexec.Register("kubectl", kubectl2.Main) reexec.Register("crictl", crictl2.Main) + reexec.Register("ctr", ctr2.Main) } func main() { @@ -37,6 +40,7 @@ func main() { cmds.NewAgentCommand(agent.Run), cmds.NewKubectlCommand(kubectl.Run), cmds.NewCRICTL(crictl.Run), + cmds.NewCtrCommand(ctr.Run), } err := app.Run(os.Args) diff --git a/pkg/cli/ctr/ctr.go b/pkg/cli/ctr/ctr.go new file mode 100644 index 0000000000..a8aab2d60c --- /dev/null +++ b/pkg/cli/ctr/ctr.go @@ -0,0 +1,11 @@ +package ctr + +import ( + "github.com/rancher/k3s/pkg/ctr" + "github.com/urfave/cli" +) + +func Run(ctx *cli.Context) error { + ctr.Main() + return nil +} diff --git a/pkg/ctr/main.go b/pkg/ctr/main.go new file mode 100644 index 0000000000..fca1c40810 --- /dev/null +++ b/pkg/ctr/main.go @@ -0,0 +1,51 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package ctr + +import ( + "fmt" + "os" + + "github.com/containerd/containerd/cmd/ctr/app" + "github.com/containerd/containerd/pkg/seed" + "github.com/urfave/cli" +) + +func Main() { + main() +} + +func main() { + seed.WithTimeAndRand() + app := app.New() + for i, flag := range app.Flags { + if sFlag, ok := flag.(cli.StringFlag); ok { + if sFlag.Name == "address, a" { + sFlag.Value = "/run/k3s/containerd/containerd.sock" + app.Flags[i] = sFlag + } else if sFlag.Name == "namespace, n" { + sFlag.Value = "k8s.io" + app.Flags[i] = sFlag + } + } + } + + if err := app.Run(os.Args); err != nil { + fmt.Fprintf(os.Stderr, "ctr: %s\n", err) + os.Exit(1) + } +} diff --git a/scripts/build b/scripts/build index 9a38024b26..884eaedd27 100755 --- a/scripts/build +++ b/scripts/build @@ -23,7 +23,7 @@ if [ -z "$GOARM" ] && [ "arm" = "$(go env GOARCH)" ]; then GOARM=7 fi -rm -f bin/k3s-agent bin/hyperkube bin/containerd bin/cni ./bin/runc bin/containerd-shim bin/k3s-server bin/kubectl bin/crictl +rm -f bin/k3s-agent bin/hyperkube bin/containerd bin/cni ./bin/runc bin/containerd-shim bin/k3s-server bin/kubectl bin/crictl bin/ctr # echo Building agent # CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o bin/k3s-agent ./cmd/agent/main.go echo Building server @@ -32,6 +32,7 @@ ln -s containerd ./bin/k3s-agent ln -s containerd ./bin/k3s-server ln -s containerd ./bin/kubectl ln -s containerd ./bin/crictl +ln -s containerd ./bin/ctr echo Building hyperkube CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC_SQLITE" -o bin/hyperkube ./vendor/k8s.io/kubernetes/cmd/hyperkube/ #echo Building ctr