Merge pull request #586 from Random-Liu/add-ctrcri
Add a separate CLI for cri-containerd `ctrcri`.
This commit is contained in:
commit
34dd28ab32
17
Makefile
17
Makefile
@ -41,9 +41,9 @@ help:
|
|||||||
@echo "Usage: make <target>"
|
@echo "Usage: make <target>"
|
||||||
@echo
|
@echo
|
||||||
@echo " * 'install' - Install binaries to system locations"
|
@echo " * 'install' - Install binaries to system locations"
|
||||||
@echo " * 'binaries' - Build cri-containerd"
|
@echo " * 'binaries' - Build cri-containerd and ctrcri"
|
||||||
@echo " * 'plugin' - Build cri-containerd as a plugin package"
|
@echo " * 'plugin' - Build cri-containerd as a plugin package"
|
||||||
@echo " * 'static-binaries - Build static cri-containerd"
|
@echo " * 'static-binaries - Build static cri-containerd and ctrcri"
|
||||||
@echo " * 'release' - Build release tarball"
|
@echo " * 'release' - Build release tarball"
|
||||||
@echo " * 'push' - Push release tarball to GCS"
|
@echo " * 'push' - Push release tarball to GCS"
|
||||||
@echo " * 'test' - Test cri-containerd with unit test"
|
@echo " * 'test' - Test cri-containerd with unit test"
|
||||||
@ -86,6 +86,13 @@ $(BUILD_DIR)/cri-containerd: $(SOURCES)
|
|||||||
-gcflags '$(GO_GCFLAGS)' \
|
-gcflags '$(GO_GCFLAGS)' \
|
||||||
$(PROJECT)/cmd/cri-containerd
|
$(PROJECT)/cmd/cri-containerd
|
||||||
|
|
||||||
|
$(BUILD_DIR)/ctrcri: $(SOURCES)
|
||||||
|
$(GO) build -o $@ \
|
||||||
|
-tags '$(BUILD_TAGS)' \
|
||||||
|
-ldflags '$(GO_LDFLAGS)' \
|
||||||
|
-gcflags '$(GO_GCFLAGS)' \
|
||||||
|
$(PROJECT)/cmd/ctrcri
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GO) test -timeout=10m -race ./pkg/... \
|
$(GO) test -timeout=10m -race ./pkg/... \
|
||||||
-tags '$(BUILD_TAGS)' \
|
-tags '$(BUILD_TAGS)' \
|
||||||
@ -107,7 +114,7 @@ test-e2e-node: binaries
|
|||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR)/*
|
rm -rf $(BUILD_DIR)/*
|
||||||
|
|
||||||
binaries: $(BUILD_DIR)/cri-containerd
|
binaries: $(BUILD_DIR)/cri-containerd $(BUILD_DIR)/ctrcri
|
||||||
|
|
||||||
# TODO(random-liu): Make this only build when source files change and
|
# TODO(random-liu): Make this only build when source files change and
|
||||||
# add this to target all.
|
# add this to target all.
|
||||||
@ -117,13 +124,15 @@ plugin: $(PLUGIN_SOURCES) $(SOURCES)
|
|||||||
-gcflags '$(GO_GCFLAGS)' \
|
-gcflags '$(GO_GCFLAGS)' \
|
||||||
|
|
||||||
static-binaries: GO_LDFLAGS += -extldflags "-fno-PIC -static"
|
static-binaries: GO_LDFLAGS += -extldflags "-fno-PIC -static"
|
||||||
static-binaries: $(BUILD_DIR)/cri-containerd
|
static-binaries: $(BUILD_DIR)/cri-containerd $(BUILD_DIR)/ctrcri
|
||||||
|
|
||||||
install: binaries
|
install: binaries
|
||||||
install -D -m 755 $(BUILD_DIR)/cri-containerd $(BINDIR)/cri-containerd
|
install -D -m 755 $(BUILD_DIR)/cri-containerd $(BINDIR)/cri-containerd
|
||||||
|
install -D -m 755 $(BUILD_DIR)/ctrcri $(BINDIR)/ctrcri
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(BINDIR)/cri-containerd
|
rm -f $(BINDIR)/cri-containerd
|
||||||
|
rm -f $(BINDIR)/ctrcri
|
||||||
|
|
||||||
$(BUILD_DIR)/$(TARBALL): static-binaries hack/versions
|
$(BUILD_DIR)/$(TARBALL): static-binaries hack/versions
|
||||||
@BUILD_DIR=$(BUILD_DIR) TARBALL=$(TARBALL) ./hack/release.sh
|
@BUILD_DIR=$(BUILD_DIR) TARBALL=$(TARBALL) ./hack/release.sh
|
||||||
|
@ -13,7 +13,7 @@ export KUBE_MASTER_EXTRA_METADATA="user-data=${GCE_DIR}/cloud-init/master.yaml,c
|
|||||||
export KUBE_NODE_EXTRA_METADATA="user-data=${GCE_DIR}/cloud-init/node.yaml,cri-containerd-configure-sh=${GCE_DIR}/configure.sh,version=${version_file}"
|
export KUBE_NODE_EXTRA_METADATA="user-data=${GCE_DIR}/cloud-init/node.yaml,cri-containerd-configure-sh=${GCE_DIR}/configure.sh,version=${version_file}"
|
||||||
export KUBE_CONTAINER_RUNTIME="remote"
|
export KUBE_CONTAINER_RUNTIME="remote"
|
||||||
export KUBE_CONTAINER_RUNTIME_ENDPOINT="/var/run/cri-containerd.sock"
|
export KUBE_CONTAINER_RUNTIME_ENDPOINT="/var/run/cri-containerd.sock"
|
||||||
export KUBE_LOAD_IMAGE_COMMAND="/home/cri-containerd/usr/local/bin/cri-containerd load"
|
export KUBE_LOAD_IMAGE_COMMAND="/home/cri-containerd/usr/local/bin/ctrcri load"
|
||||||
export NETWORK_POLICY_PROVIDER="calico"
|
export NETWORK_POLICY_PROVIDER="calico"
|
||||||
export NON_MASQUERADE_CIDR="0.0.0.0/0"
|
export NON_MASQUERADE_CIDR="0.0.0.0/0"
|
||||||
export KUBE_KUBELET_ARGS="--runtime-cgroups=/runtime"
|
export KUBE_KUBELET_ARGS="--runtime-cgroups=/runtime"
|
||||||
|
@ -82,7 +82,6 @@ func main() {
|
|||||||
o.AddFlags(cmd.Flags())
|
o.AddFlags(cmd.Flags())
|
||||||
cmd.AddCommand(defaultConfigCommand())
|
cmd.AddCommand(defaultConfigCommand())
|
||||||
cmd.AddCommand(versionCommand())
|
cmd.AddCommand(versionCommand())
|
||||||
cmd.AddCommand(loadImageCommand())
|
|
||||||
|
|
||||||
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
setupDumpStacksTrap()
|
setupDumpStacksTrap()
|
||||||
|
@ -19,7 +19,6 @@ package options
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
@ -31,8 +30,6 @@ const (
|
|||||||
configFilePathArgName = "config"
|
configFilePathArgName = "config"
|
||||||
// defaultConfigFilePath is the default config file path.
|
// defaultConfigFilePath is the default config file path.
|
||||||
defaultConfigFilePath = "/etc/cri-containerd/config.toml"
|
defaultConfigFilePath = "/etc/cri-containerd/config.toml"
|
||||||
// connectionTimeout is the grpc connection timeout.
|
|
||||||
connectionTimeout = 10 * time.Second
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerdConfig contains toml config related to containerd
|
// ContainerdConfig contains toml config related to containerd
|
||||||
@ -234,13 +231,6 @@ func PrintDefaultTomlConfig() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddGRPCFlags add flags for grpc connection.
|
|
||||||
func AddGRPCFlags(fs *pflag.FlagSet) (*string, *time.Duration) {
|
|
||||||
endpoint := fs.String("endpoint", DefaultConfig().SocketPath, "cri-containerd endpoint.")
|
|
||||||
timeout := fs.Duration("timeout", connectionTimeout, "cri-containerd connection timeout.")
|
|
||||||
return endpoint, timeout
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultConfig returns default configurations of cri-containerd.
|
// DefaultConfig returns default configurations of cri-containerd.
|
||||||
func DefaultConfig() Config {
|
func DefaultConfig() Config {
|
||||||
return Config{
|
return Config{
|
||||||
|
84
cmd/ctrcri/ctrcri.go
Normal file
84
cmd/ctrcri/ctrcri.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2018 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 (
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
|
"github.com/containerd/cri-containerd/cmd/cri-containerd/options"
|
||||||
|
"github.com/containerd/cri-containerd/pkg/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Add \u200B to avoid the space trimming.
|
||||||
|
desc = "\u200B" + ` __ _
|
||||||
|
_____/ /________________(_)
|
||||||
|
/ ___/ __/ ___/ ___/ ___/ /
|
||||||
|
/ /__/ /_/ / / /__/ / / /
|
||||||
|
\___/\__/_/ \___/_/ /_/
|
||||||
|
|
||||||
|
containerd CRI plugin CLI
|
||||||
|
`
|
||||||
|
command = "ctrcri"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cmd = &cobra.Command{
|
||||||
|
Use: command,
|
||||||
|
Short: "A CLI for containerd CRI plugin.",
|
||||||
|
Long: desc,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// address is the address for containerd's GRPC server.
|
||||||
|
address string
|
||||||
|
// timeout is the timeout for containerd grpc connection.
|
||||||
|
timeout time.Duration
|
||||||
|
// defaultTimeout is the default timeout for containerd grpc connection.
|
||||||
|
defaultTimeout = 10 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
|
func addGlobalFlags(fs *pflag.FlagSet) {
|
||||||
|
// TODO(random-liu): Change default to containerd/defaults.DefaultAddress after cri plugin
|
||||||
|
// become default.
|
||||||
|
fs.StringVar(&address, "address", options.DefaultConfig().SocketPath, "address for containerd's GRPC server.")
|
||||||
|
fs.DurationVar(&timeout, "timeout", defaultTimeout, "timeout for containerd grpc connection.")
|
||||||
|
}
|
||||||
|
|
||||||
|
func versionCommand() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Print " + command + " version information.",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
version.PrintVersion()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
addGlobalFlags(cmd.PersistentFlags())
|
||||||
|
|
||||||
|
cmd.AddCommand(versionCommand())
|
||||||
|
cmd.AddCommand(loadImageCommand())
|
||||||
|
if err := cmd.Execute(); err != nil {
|
||||||
|
// Error should have been reported.
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,6 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/containerd/cri-containerd/cmd/cri-containerd/options"
|
|
||||||
api "github.com/containerd/cri-containerd/pkg/api/v1"
|
api "github.com/containerd/cri-containerd/pkg/api/v1"
|
||||||
"github.com/containerd/cri-containerd/pkg/client"
|
"github.com/containerd/cri-containerd/pkg/client"
|
||||||
)
|
)
|
||||||
@ -41,21 +40,20 @@ var (
|
|||||||
TAR - The path to a tar archive containing a container image.
|
TAR - The path to a tar archive containing a container image.
|
||||||
|
|
||||||
Requirement:
|
Requirement:
|
||||||
Containerd and cri-containerd daemons (grpc servers) must already be up and
|
Containerd and its cri plugin must already be up and running before the load
|
||||||
running before the load command is used.
|
command is used.
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
Running as a client, cri-containerd implements the load command by sending the
|
Running as a client, ` + command + ` implements the load command by sending the
|
||||||
load request to the already running cri-containerd daemon/server, which in
|
load request to the already running containerd daemon/server, which in
|
||||||
turn loads the image into containerd's image storage via the already running
|
turn loads the image into containerd's image storage.`)
|
||||||
containerd daemon.`)
|
|
||||||
|
|
||||||
loadExample = dedent(`
|
loadExample = dedent(`
|
||||||
- use docker to pull the latest busybox image and save it as a tar archive:
|
- use docker to pull the latest busybox image and save it as a tar archive:
|
||||||
$ docker pull busybox:latest
|
$ docker pull busybox:latest
|
||||||
$ docker save busybox:latest -o busybox.tar
|
$ docker save busybox:latest -o busybox.tar
|
||||||
- use cri-containerd to load the image into containerd's image storage:
|
- use ` + command + ` to load the image into containerd's image storage:
|
||||||
$ cri-containerd load busybox.tar`)
|
$ ` + command + ` load busybox.tar`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadImageCommand() *cobra.Command {
|
func loadImageCommand() *cobra.Command {
|
||||||
@ -67,9 +65,8 @@ func loadImageCommand() *cobra.Command {
|
|||||||
Example: loadExample,
|
Example: loadExample,
|
||||||
}
|
}
|
||||||
c.SetUsageTemplate(strings.Replace(c.UsageTemplate(), "Examples:", "Example:", 1))
|
c.SetUsageTemplate(strings.Replace(c.UsageTemplate(), "Examples:", "Example:", 1))
|
||||||
endpoint, timeout := options.AddGRPCFlags(c.Flags())
|
|
||||||
c.RunE = func(cmd *cobra.Command, args []string) error {
|
c.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
cl, err := client.NewCRIContainerdClient(*endpoint, *timeout)
|
cl, err := client.NewCRIContainerdClient(address, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create grpc client: %v", err)
|
return fmt.Errorf("failed to create grpc client: %v", err)
|
||||||
}
|
}
|
@ -7,6 +7,7 @@ These steps have been verified on Ubuntu 16.04. For other OS distributions, the
|
|||||||
## Release Tarball
|
## Release Tarball
|
||||||
For each release, we'll publish a release tarball. The release tarball contains all required binaries and files for `cri-containerd`.
|
For each release, we'll publish a release tarball. The release tarball contains all required binaries and files for `cri-containerd`.
|
||||||
### Content
|
### Content
|
||||||
|
<!-- TODO(random-liu): Update the release tarball information -->
|
||||||
As shown below, the release tarball contains:
|
As shown below, the release tarball contains:
|
||||||
1) `cri-containerd`: cri-containerd binary.
|
1) `cri-containerd`: cri-containerd binary.
|
||||||
2) `containerd`, `containerd-shim`, `containerd-stress`, `containerd-release`, `ctr`: binaries for containerd.
|
2) `containerd`, `containerd-shim`, `containerd-stress`, `containerd-release`, `ctr`: binaries for containerd.
|
||||||
|
Loading…
Reference in New Issue
Block a user