Replace ctrcri with ctr cri.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2018-03-15 23:22:00 +00:00
parent 62d1f13217
commit 7e67d96b9b
8 changed files with 35 additions and 248 deletions

View File

@ -20,16 +20,15 @@ PROJECT := github.com/containerd/cri
BINDIR := ${DESTDIR}/usr/local/bin
BUILD_DIR := _output
# VERSION is derived from the current tag for HEAD plus amends. Version is used
# to set/overide the CRIContainerdVersion variable in the verison package for
# cri plugin.
# to set/overide the containerd version in vendor/github.com/containerd/containerd/version.
VERSION := $(shell git describe --tags --dirty --always)
# strip the first char of the tag if it's a `v`
VERSION := $(VERSION:v%=%)
TARBALL_PREFIX := cri-containerd
TARBALL := $(TARBALL_PREFIX)-$(VERSION).$(GOOS)-$(GOARCH).tar.gz
BUILD_TAGS := seccomp apparmor
GO_LDFLAGS := -X $(PROJECT)/pkg/version.CRIContainerdVersion=$(VERSION) \
-X $(PROJECT)/vendor/github.com/containerd/containerd/version.Version=$(VERSION)-TEST
# Add `-TEST` suffix to indicate that all binaries built from this repo are for test.
GO_LDFLAGS := -X $(PROJECT)/vendor/github.com/containerd/containerd/version.Version=$(VERSION)-TEST
SOURCES := $(shell find cmd/ pkg/ vendor/ -name '*.go')
PLUGIN_SOURCES := $(shell ls *.go)
INTEGRATION_SOURCES := $(shell find integration/ -name '*.go')
@ -42,10 +41,10 @@ help:
@echo "Usage: make <target>"
@echo
@echo " * 'install' - Install binaries to system locations"
@echo " * 'binaries' - Build containerd and ctrcri"
@echo " * 'static-binaries - Build static containerd and ctrcri"
@echo " * 'ctrcri' - Build ctrcri"
@echo " * 'install-ctrcri' - Install ctrcri"
@echo " * 'binaries' - Build containerd and ctr"
@echo " * 'static-binaries - Build static containerd and ctr"
@echo " * 'ctr' - Build ctr"
@echo " * 'install-ctr' - Install ctr"
@echo " * 'containerd' - Build a customized containerd with CRI plugin for testing"
@echo " * 'install-containerd' - Install customized containerd to system location"
@echo " * 'release' - Build release tarball"
@ -92,12 +91,12 @@ sync-vendor:
update-vendor: sync-vendor sort-vendor
$(BUILD_DIR)/ctrcri: $(SOURCES)
$(BUILD_DIR)/ctr: $(SOURCES)
$(GO) build -o $@ \
-tags '$(BUILD_TAGS)' \
-ldflags '$(GO_LDFLAGS)' \
-gcflags '$(GO_GCFLAGS)' \
$(PROJECT)/cmd/ctrcri
$(PROJECT)/cmd/ctr
$(BUILD_DIR)/containerd: $(SOURCES) $(PLUGIN_SOURCES)
$(GO) build -o $@ \
@ -127,26 +126,26 @@ test-e2e-node: binaries
clean:
rm -rf $(BUILD_DIR)/*
binaries: $(BUILD_DIR)/containerd $(BUILD_DIR)/ctrcri
binaries: $(BUILD_DIR)/containerd $(BUILD_DIR)/ctr
static-binaries: GO_LDFLAGS += -extldflags "-fno-PIC -static"
static-binaries: $(BUILD_DIR)/containerd $(BUILD_DIR)/ctrcri
static-binaries: $(BUILD_DIR)/containerd $(BUILD_DIR)/ctr
ctrcri: $(BUILD_DIR)/ctrcri
ctr: $(BUILD_DIR)/ctr
install-ctrcri: ctrcri
install -D -m 755 $(BUILD_DIR)/ctrcri $(BINDIR)/ctrcri
install-ctr: ctr
install -D -m 755 $(BUILD_DIR)/ctr $(BINDIR)/ctr
containerd: $(BUILD_DIR)/containerd
install-containerd: containerd
install -D -m 755 $(BUILD_DIR)/containerd $(BINDIR)/containerd
install: install-ctrcri install-containerd
install: install-ctr install-containerd
uninstall:
rm -f $(BINDIR)/containerd
rm -f $(BINDIR)/ctrcri
rm -f $(BINDIR)/ctr
$(BUILD_DIR)/$(TARBALL): static-binaries vendor.conf
@BUILD_DIR=$(BUILD_DIR) TARBALL=$(TARBALL) ./hack/release.sh
@ -188,8 +187,8 @@ install.tools: .install.gitvalidation .install.gometalinter
.PHONY: \
binaries \
static-binaries \
ctrcri \
install-ctrcri \
ctr \
install-ctr \
containerd \
install-containerd \
release \

View File

@ -1,5 +1,5 @@
/*
Copyright 2017 The Kubernetes Authors.
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.
@ -14,18 +14,22 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package version
package main
import (
"testing"
"fmt"
"os"
"github.com/stretchr/testify/assert"
"github.com/containerd/containerd/cmd/ctr/command"
cricli "github.com/containerd/cri/cli"
)
func TestValidateSemver(t *testing.T) {
err := validateSemver("UNKNOWN")
assert := assert.New(t)
assert.NotNil(err)
err = validateSemver("0.0.0-1-gdf6a1cc-dirty")
assert.Nil(err)
func main() {
app := command.App()
app.Commands = append(app.Commands, cricli.Command)
if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "ctr: %s\n", err)
os.Exit(1)
}
}

View File

@ -1,82 +0,0 @@
/*
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/containerd/containerd/defaults"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/containerd/cri/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) {
fs.StringVar(&address, "address", defaults.DefaultAddress, "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)
}
}

View File

@ -1,88 +0,0 @@
/*
Copyright 2017 The Kubernetes 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"
"path/filepath"
"strings"
dedentutil "github.com/renstrom/dedent"
"github.com/spf13/cobra"
"golang.org/x/net/context"
api "github.com/containerd/cri/pkg/api/v1"
"github.com/containerd/cri/pkg/client"
)
func dedent(s string) string {
return strings.TrimLeft(dedentutil.Dedent(s), "\n")
}
var (
loadLong = dedent(`
Help for "load TAR" command
TAR - The path to a tar archive containing a container image.
Requirement:
Containerd and its cri plugin must already be up and running before the load
command is used.
Description:
Running as a client, ` + command + ` implements the load command by sending the
load request to the already running containerd daemon/server, which in
turn loads the image into containerd's image storage.`)
loadExample = dedent(`
- use docker to pull the latest busybox image and save it as a tar archive:
$ docker pull busybox:latest
$ docker save busybox:latest -o busybox.tar
- use ` + command + ` to load the image into containerd's image storage:
$ ` + command + ` load busybox.tar`)
)
func loadImageCommand() *cobra.Command {
c := &cobra.Command{
Use: "load TAR",
Long: loadLong,
Short: "Load an image from a tar archive.",
Args: cobra.ExactArgs(1),
Example: loadExample,
}
c.SetUsageTemplate(strings.Replace(c.UsageTemplate(), "Examples:", "Example:", 1))
c.RunE = func(cmd *cobra.Command, args []string) error {
cl, err := client.NewCRIContainerdClient(address, timeout)
if err != nil {
return fmt.Errorf("failed to create grpc client: %v", err)
}
path, err := filepath.Abs(args[0])
if err != nil {
return fmt.Errorf("failed to get absolute path: %v", err)
}
res, err := cl.LoadImage(context.Background(), &api.LoadImageRequest{FilePath: path})
if err != nil {
return fmt.Errorf("failed to load image: %v", err)
}
images := res.GetImages()
for _, image := range images {
fmt.Println("Loaded image:", image)
}
return nil
}
return c
}

View File

@ -40,11 +40,8 @@ rm -rf ${destdir}
# Install dependencies into release stage.
NOSUDO=true INSTALL_CNI=${INCLUDE_CNI} DESTDIR=${destdir} ./hack/install-deps.sh
# Install ctrcri into release stage.
make install-ctrcri -e DESTDIR=${destdir}
if ${CUSTOM_CONTAINERD}; then
make install-containerd -e DESTDIR=${destdir}
make install -e DESTDIR=${destdir}
fi
# Install systemd units into release stage.

View File

@ -1,43 +0,0 @@
/*
Copyright 2017 The Kubernetes 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 version
import (
"fmt"
"github.com/blang/semver"
)
// CRIContainerdVersion is the version of the cri plugin.
var CRIContainerdVersion = "UNKNOWN"
func validateSemver(sv string) error {
_, err := semver.Parse(sv)
if err != nil {
return fmt.Errorf("couldn't parse version %q: %v", sv, err)
}
return nil
}
// PrintVersion outputs the release version of containerd/cri
func PrintVersion() {
err := validateSemver(CRIContainerdVersion)
if err != nil {
fmt.Println(err)
}
fmt.Println(CRIContainerdVersion)
}