From 7e67d96b9bbe71ca2bdf5ec901d40ad2cfacf603 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Thu, 15 Mar 2018 23:22:00 +0000 Subject: [PATCH] Replace `ctrcri` with `ctr cri`. Signed-off-by: Lantao Liu --- Makefile | 37 ++++---- cluster/gce/env | 2 +- .../version_test.go => cmd/ctr/main.go | 24 ++--- cmd/ctrcri/ctrcri.go | 82 ----------------- cmd/ctrcri/load.go | 88 ------------------- docs/crictl.md | 2 +- hack/release.sh | 5 +- pkg/version/version.go | 43 --------- 8 files changed, 35 insertions(+), 248 deletions(-) rename pkg/version/version_test.go => cmd/ctr/main.go (61%) delete mode 100644 cmd/ctrcri/ctrcri.go delete mode 100644 cmd/ctrcri/load.go delete mode 100644 pkg/version/version.go diff --git a/Makefile b/Makefile index 7b8c93a47..6bb59ea96 100644 --- a/Makefile +++ b/Makefile @@ -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 " @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 \ diff --git a/cluster/gce/env b/cluster/gce/env index 231d1c914..203f714c2 100644 --- a/cluster/gce/env +++ b/cluster/gce/env @@ -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,containerd-configure-sh=${GCE_DIR}/configure.sh,version=${version_file}" export KUBE_CONTAINER_RUNTIME="remote" export KUBE_CONTAINER_RUNTIME_ENDPOINT="/run/containerd/containerd.sock" -export KUBE_LOAD_IMAGE_COMMAND="/home/containerd/usr/local/bin/ctrcri load" +export KUBE_LOAD_IMAGE_COMMAND="/home/containerd/usr/local/bin/ctr cri load" export NETWORK_POLICY_PROVIDER="calico" export NON_MASQUERADE_CIDR="0.0.0.0/0" export KUBE_KUBELET_EXTRA_ARGS="--runtime-cgroups=/runtime" diff --git a/pkg/version/version_test.go b/cmd/ctr/main.go similarity index 61% rename from pkg/version/version_test.go rename to cmd/ctr/main.go index a494a8841..e001e4300 100644 --- a/pkg/version/version_test.go +++ b/cmd/ctr/main.go @@ -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) + } } diff --git a/cmd/ctrcri/ctrcri.go b/cmd/ctrcri/ctrcri.go deleted file mode 100644 index f9e4a1d7c..000000000 --- a/cmd/ctrcri/ctrcri.go +++ /dev/null @@ -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) - } -} diff --git a/cmd/ctrcri/load.go b/cmd/ctrcri/load.go deleted file mode 100644 index 372f240eb..000000000 --- a/cmd/ctrcri/load.go +++ /dev/null @@ -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 -} diff --git a/docs/crictl.md b/docs/crictl.md index 488d409ac..0db5d9177 100644 --- a/docs/crictl.md +++ b/docs/crictl.md @@ -54,7 +54,7 @@ $ docker save k8s.gcr.io/pause-amd64:3.1 -o pause.tar ``` Then load the container image into the container runtime: ```console -$ sudo ctrcri load pause.tar +$ sudo ctr cri load pause.tar Loaded image: k8s.gcr.io/pause-amd64:3.1 ``` List images and inspect the pause image: diff --git a/hack/release.sh b/hack/release.sh index bf14945c7..7976febae 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -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. diff --git a/pkg/version/version.go b/pkg/version/version.go deleted file mode 100644 index ca95133d1..000000000 --- a/pkg/version/version.go +++ /dev/null @@ -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) -}