Browse Source

Merge pull request #591 from erikwilson/add-ctr

Build & enable ctr with k3s server
pull/601/head v0.7.0-rc2
Erik Wilson 5 years ago committed by GitHub
parent
commit
853708c8ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      cmd/ctr/main.go
  2. 2
      cmd/k3s/main.go
  3. 4
      cmd/server/main.go
  4. 11
      pkg/cli/ctr/ctr.go
  5. 51
      pkg/ctr/main.go
  6. 3
      scripts/build

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

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

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

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

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

3
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

Loading…
Cancel
Save