Build & enable ctr with k3s server

This commit is contained in:
Erik Wilson 2019-06-30 09:30:25 -07:00
parent 9ccf3cbc9d
commit ed72856d27
6 changed files with 71 additions and 47 deletions

View File

@ -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()
}

View File

@ -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)

View File

@ -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)

11
pkg/cli/ctr/ctr.go Normal file
View File

@ -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
}

51
pkg/ctr/main.go Normal file
View File

@ -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)
}
}

View File

@ -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