pull/22/head
Darren Shepherd 6 years ago
parent 76a191844c
commit 793ac4fb89

@ -0,0 +1,50 @@
/*
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()
}
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)
}
}

@ -18,7 +18,7 @@ import (
) )
func main() { func main() {
if runKubectl() { if runCLIs() {
return return
} }
@ -26,7 +26,9 @@ func main() {
app.Commands = []cli.Command{ app.Commands = []cli.Command{
cmds.NewServerCommand(wrap("k3s-server", os.Args)), cmds.NewServerCommand(wrap("k3s-server", os.Args)),
cmds.NewAgentCommand(wrap("k3s-agent", os.Args)), cmds.NewAgentCommand(wrap("k3s-agent", os.Args)),
cmds.NewKubectlCommand(kubectlCLI), cmds.NewKubectlCommand(externalCLIAction("kubectl")),
//cmds.NewCtrCommand(externalCLIAction("ctr")),
cmds.NewCRICTL(externalCLIAction("crictl")),
} }
err := app.Run(os.Args) err := app.Run(os.Args)
@ -35,26 +37,30 @@ func main() {
} }
} }
func runKubectl() bool { func runCLIs() bool {
if filepath.Base(os.Args[0]) == "kubectl" { for _, cmd := range []string{"kubectl", "ctr", "crictl"} {
if err := kubectl("", os.Args[1:]); err != nil { if filepath.Base(os.Args[0]) == cmd {
logrus.Fatal(err) if err := externalCLI(cmd, "", os.Args[1:]); err != nil {
logrus.Fatal(err)
}
return true
} }
return true
} }
return false return false
} }
func kubectlCLI(cli *cli.Context) error { func externalCLIAction(cmd string) func(cli *cli.Context) error {
return kubectl(cli.String("data-dir"), cli.Args()) return func(cli *cli.Context) error {
return externalCLI(cmd, cli.String("data-dir"), cli.Args())
}
} }
func kubectl(dataDir string, args []string) error { func externalCLI(cli, dataDir string, args []string) error {
dataDir, err := datadir.Resolve(dataDir) dataDir, err := datadir.Resolve(dataDir)
if err != nil { if err != nil {
return err return err
} }
return stageAndRun(dataDir, "kubectl", append([]string{"kubectl"}, args...)) return stageAndRun(dataDir, cli, append([]string{cli}, args...))
} }
func wrap(cmd string, args []string) func(ctx *cli.Context) error { func wrap(cmd string, args []string) func(ctx *cli.Context) error {

@ -5,8 +5,10 @@ import (
"path/filepath" "path/filepath"
"github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/reexec"
crictl2 "github.com/kubernetes-sigs/cri-tools/cmd/crictl"
"github.com/rancher/k3s/pkg/cli/agent" "github.com/rancher/k3s/pkg/cli/agent"
"github.com/rancher/k3s/pkg/cli/cmds" "github.com/rancher/k3s/pkg/cli/cmds"
"github.com/rancher/k3s/pkg/cli/crictl"
"github.com/rancher/k3s/pkg/cli/kubectl" "github.com/rancher/k3s/pkg/cli/kubectl"
"github.com/rancher/k3s/pkg/cli/server" "github.com/rancher/k3s/pkg/cli/server"
"github.com/rancher/k3s/pkg/containerd" "github.com/rancher/k3s/pkg/containerd"
@ -18,6 +20,7 @@ import (
func init() { func init() {
reexec.Register("containerd", containerd.Main) reexec.Register("containerd", containerd.Main)
reexec.Register("kubectl", kubectl2.Main) reexec.Register("kubectl", kubectl2.Main)
reexec.Register("crictl", crictl2.Main)
} }
func main() { func main() {
@ -33,6 +36,7 @@ func main() {
cmds.NewServerCommand(server.Run), cmds.NewServerCommand(server.Run),
cmds.NewAgentCommand(agent.Run), cmds.NewAgentCommand(agent.Run),
cmds.NewKubectlCommand(kubectl.Run), cmds.NewKubectlCommand(kubectl.Run),
cmds.NewCRICTL(crictl.Run),
} }
err := app.Run(os.Args) err := app.Run(os.Args)

@ -10,6 +10,7 @@ import (
"github.com/rancher/k3s/pkg/cli/agent" "github.com/rancher/k3s/pkg/cli/agent"
"github.com/rancher/k3s/pkg/cli/cmds" "github.com/rancher/k3s/pkg/cli/cmds"
"github.com/rancher/k3s/pkg/cli/crictl"
"github.com/rancher/k3s/pkg/cli/kubectl" "github.com/rancher/k3s/pkg/cli/kubectl"
"github.com/rancher/k3s/pkg/cli/server" "github.com/rancher/k3s/pkg/cli/server"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -22,6 +23,7 @@ func main() {
cmds.NewServerCommand(server.Run), cmds.NewServerCommand(server.Run),
cmds.NewAgentCommand(agent.Run), cmds.NewAgentCommand(agent.Run),
cmds.NewKubectlCommand(kubectl.Run), cmds.NewKubectlCommand(kubectl.Run),
cmds.NewCRICTL(crictl.Run),
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {

@ -0,0 +1,15 @@
package cmds
import (
"github.com/urfave/cli"
)
func NewCRICTL(action func(*cli.Context) error) cli.Command {
return cli.Command{
Name: "crictl",
Usage: "Run crictl",
SkipFlagParsing: true,
SkipArgReorder: true,
Action: action,
}
}

@ -0,0 +1,15 @@
package cmds
import (
"github.com/urfave/cli"
)
func NewCtrCommand(action func(*cli.Context) error) cli.Command {
return cli.Command{
Name: "ctr",
Usage: "Run ctr",
SkipFlagParsing: true,
SkipArgReorder: true,
Action: action,
}
}

@ -0,0 +1,11 @@
package crictl
import (
"github.com/kubernetes-sigs/cri-tools/cmd/crictl"
"github.com/urfave/cli"
)
func Run(ctx *cli.Context) error {
crictl.Main()
return nil
}

@ -19,7 +19,11 @@ fi
mkdir -p bin mkdir -p bin
rm -f bin/k3s-agent bin/hyperkube bin/containerd bin/cni ./bin/runc bin/containerd-shim bin/k3s-server bin/kubectl 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
# echo Building agent # echo Building agent
# CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o bin/k3s-agent ./cmd/agent/main.go # CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o bin/k3s-agent ./cmd/agent/main.go
echo Building server echo Building server
@ -27,8 +31,11 @@ CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC_SQLITE" -o bin/c
ln -s containerd ./bin/k3s-agent ln -s containerd ./bin/k3s-agent
ln -s containerd ./bin/k3s-server ln -s containerd ./bin/k3s-server
ln -s containerd ./bin/kubectl ln -s containerd ./bin/kubectl
ln -s containerd ./bin/crictl
echo Building hyperkube echo Building hyperkube
CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC_SQLITE" -o bin/hyperkube ./vendor/k8s.io/kubernetes/cmd/hyperkube/ CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC_SQLITE" -o bin/hyperkube ./vendor/k8s.io/kubernetes/cmd/hyperkube/
#echo Building ctr
#CGO_ENABLED=1 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC_SQLITE" -o bin/ctr ./cmd/ctr/main.go
# echo Building containerd # echo Building containerd
# CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o bin/containerd ./cmd/containerd/ # CGO_ENABLED=0 go build -tags "$TAGS" -ldflags "$LDFLAGS $STATIC" -o bin/containerd ./cmd/containerd/
echo Building cni echo Building cni

@ -7,10 +7,11 @@ cd $(dirname $0)/..
./scripts/download ./scripts/download
rm -rf bin/kubectl bin/k3s-agent bin/k3s-server bin/kubectl bin/k3s build/data rm -rf bin/crictl bin/kubectl bin/k3s-agent bin/k3s-server bin/kubectl bin/k3s build/data
ln -s containerd bin/k3s-agent ln -s containerd bin/k3s-agent
ln -s containerd bin/k3s-server ln -s containerd bin/k3s-server
ln -s containerd bin/kubectl ln -s containerd bin/kubectl
ln -s containerd bin/crictl
for i in bridge flannel host-local loopback portmap; do for i in bridge flannel host-local loopback portmap; do
if [ -e ./bin/$i ]; then if [ -e ./bin/$i ]; then
rm -f ./bin/$i rm -f ./bin/$i

Loading…
Cancel
Save