From 9460f94c1056765a089a4dd08a63c27db4745898 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Wed, 28 Feb 2018 19:46:46 +0000 Subject: [PATCH] Update containerd/cri to 0c876040681ebe8a291fa2cebefdcc2796fa3fc8 Signed-off-by: Lantao Liu --- vendor.conf | 2 +- .../containerd/cri-containerd/cri.go | 114 ----------- .../{cri-containerd => cri}/LICENSE | 0 .../{cri-containerd => cri}/README.md | 0 vendor/github.com/containerd/cri/cli/cli.go | 78 ++++++++ vendor/github.com/containerd/cri/cri.go | 181 ++++++++++++++++++ .../pkg/annotations/annotations.go | 0 .../pkg/api/v1/api.pb.go | 0 .../pkg/api/v1/api.proto | 0 .../pkg/atomic/atomic_boolean.go | 0 .../containerd/cri/pkg/client/client.go | 47 +++++ .../pkg/config/config.go | 0 .../containerd/cri/pkg/constants/constants.go | 26 +++ .../pkg/containerd/importer/importer.go | 4 +- .../pkg/containerd/opts/container.go | 0 .../pkg/containerd/opts/task.go | 0 .../pkg/containerd/resolver/auth.go | 0 .../pkg/containerd/resolver/fetcher.go | 0 .../pkg/containerd/resolver/httpreadseeker.go | 0 .../pkg/containerd/resolver/resolver.go | 0 .../pkg/containerd/resolver/scope.go | 0 .../pkg/containerd/resolver/status.go | 0 .../pkg/containerd/util/util.go | 17 +- .../pkg/ioutil/read_closer.go | 0 .../pkg/ioutil/write_closer.go | 0 .../pkg/ioutil/writer_group.go | 0 .../{cri-containerd => cri}/pkg/log/log.go | 0 .../{cri-containerd => cri}/pkg/os/os.go | 0 .../pkg/registrar/registrar.go | 0 .../pkg/server/container_attach.go | 2 +- .../pkg/server/container_create.go | 17 +- .../pkg/server/container_exec.go | 0 .../pkg/server/container_execsync.go | 8 +- .../pkg/server/container_list.go | 2 +- .../pkg/server/container_log_reopen.go | 2 +- .../pkg/server/container_remove.go | 6 +- .../pkg/server/container_start.go | 8 +- .../pkg/server/container_stats.go | 0 .../pkg/server/container_stats_list.go | 2 +- .../pkg/server/container_status.go | 2 +- .../pkg/server/container_stop.go | 2 +- .../pkg/server/container_update_resources.go | 6 +- .../pkg/server/events.go | 30 +-- .../pkg/server/helpers.go | 6 +- .../pkg/server/image_list.go | 2 +- .../pkg/server/image_load.go | 6 +- .../pkg/server/image_pull.go | 10 +- .../pkg/server/image_remove.go | 2 +- .../pkg/server/image_status.go | 2 +- .../pkg/server/imagefs_info.go | 0 .../pkg/server/instrumented_service.go | 63 +++--- .../pkg/server/io/container_io.go | 4 +- .../pkg/server/io/exec_io.go | 2 +- .../pkg/server/io/helpers.go | 0 .../pkg/server/io/logger.go | 2 +- .../pkg/server/restart.go | 20 +- .../pkg/server/sandbox_list.go | 2 +- .../pkg/server/sandbox_portforward.go | 5 +- .../pkg/server/sandbox_remove.go | 6 +- .../pkg/server/sandbox_run.go | 18 +- .../pkg/server/sandbox_status.go | 2 +- .../pkg/server/sandbox_stop.go | 4 +- .../pkg/server/service.go | 40 ++-- .../pkg/server/snapshots.go | 8 +- .../pkg/server/status.go | 20 +- .../pkg/server/streaming.go | 7 +- .../pkg/server/update_runtime_config.go | 2 +- .../pkg/server/version.go | 18 +- .../pkg/store/container/container.go | 4 +- .../pkg/store/container/fake_status.go | 0 .../pkg/store/container/metadata.go | 0 .../pkg/store/container/status.go | 0 .../pkg/store/errors.go | 0 .../pkg/store/image/image.go | 2 +- .../pkg/store/sandbox/metadata.go | 0 .../pkg/store/sandbox/netns.go | 0 .../pkg/store/sandbox/sandbox.go | 2 +- .../pkg/store/sandbox/status.go | 2 +- .../pkg/store/snapshot/snapshot.go | 2 +- .../{cri-containerd => cri}/pkg/store/util.go | 0 .../pkg/util/deep_copy.go | 0 .../{cri-containerd => cri}/pkg/util/id.go | 0 .../{cri-containerd => cri}/pkg/util/image.go | 0 .../pkg/util/strings.go | 0 .../{cri-containerd => cri}/vendor.conf | 5 +- .../k8s.io/kubernetes/pkg/kubelet/util/doc.go | 18 ++ .../kubernetes/pkg/kubelet/util/util.go | 47 +++++ .../kubernetes/pkg/kubelet/util/util_unix.go | 79 ++++++++ .../pkg/kubelet/util/util_unsupported.go | 33 ++++ .../pkg/kubelet/util/util_windows.go | 57 ++++++ 90 files changed, 748 insertions(+), 310 deletions(-) delete mode 100644 vendor/github.com/containerd/cri-containerd/cri.go rename vendor/github.com/containerd/{cri-containerd => cri}/LICENSE (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/README.md (100%) create mode 100644 vendor/github.com/containerd/cri/cli/cli.go create mode 100644 vendor/github.com/containerd/cri/cri.go rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/annotations/annotations.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/api/v1/api.pb.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/api/v1/api.proto (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/atomic/atomic_boolean.go (100%) create mode 100644 vendor/github.com/containerd/cri/pkg/client/client.go rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/config/config.go (100%) create mode 100644 vendor/github.com/containerd/cri/pkg/constants/constants.go rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/importer/importer.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/opts/container.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/opts/task.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/resolver/auth.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/resolver/fetcher.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/resolver/httpreadseeker.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/resolver/resolver.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/resolver/scope.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/resolver/status.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/containerd/util/util.go (65%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/ioutil/read_closer.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/ioutil/write_closer.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/ioutil/writer_group.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/log/log.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/os/os.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/registrar/registrar.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_attach.go (97%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_create.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_exec.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_execsync.go (96%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_list.go (97%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_log_reopen.go (96%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_remove.go (96%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_start.go (95%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_stats.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_stats_list.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_status.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_stop.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/container_update_resources.go (96%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/events.go (89%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/helpers.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/image_list.go (96%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/image_load.go (92%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/image_pull.go (96%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/image_remove.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/image_status.go (97%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/imagefs_info.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/instrumented_service.go (89%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/io/container_io.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/io/exec_io.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/io/helpers.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/io/logger.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/restart.go (96%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/sandbox_list.go (97%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/sandbox_portforward.go (95%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/sandbox_remove.go (95%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/sandbox_run.go (97%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/sandbox_status.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/sandbox_stop.go (96%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/service.go (85%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/snapshots.go (91%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/status.go (74%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/streaming.go (92%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/update_runtime_config.go (93%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/server/version.go (77%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/container/container.go (97%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/container/fake_status.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/container/metadata.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/container/status.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/errors.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/image/image.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/sandbox/metadata.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/sandbox/netns.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/sandbox/sandbox.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/sandbox/status.go (98%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/snapshot/snapshot.go (97%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/store/util.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/util/deep_copy.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/util/id.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/util/image.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/pkg/util/strings.go (100%) rename vendor/github.com/containerd/{cri-containerd => cri}/vendor.conf (96%) create mode 100644 vendor/k8s.io/kubernetes/pkg/kubelet/util/doc.go create mode 100644 vendor/k8s.io/kubernetes/pkg/kubelet/util/util.go create mode 100644 vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unix.go create mode 100644 vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unsupported.go create mode 100644 vendor/k8s.io/kubernetes/pkg/kubelet/util/util_windows.go diff --git a/vendor.conf b/vendor.conf index 55165f278..ad0b9fe86 100644 --- a/vendor.conf +++ b/vendor.conf @@ -42,7 +42,7 @@ github.com/syndtr/gocapability db04d3cc01c8b54962a58ec7e491717d06cfcc16 github.com/gotestyourself/gotestyourself 44dbf532bbf5767611f6f2a61bded572e337010a github.com/google/go-cmp v0.1.0 # cri dependencies -github.com/containerd/cri-containerd dcc278739fb31c5369f927c69716275c084c3d53 https://github.com/Random-Liu/cri-containerd.git +github.com/containerd/cri 0c876040681ebe8a291fa2cebefdcc2796fa3fc8 github.com/blang/semver v3.1.0 github.com/containernetworking/cni v0.6.0 github.com/containernetworking/plugins v0.6.0 diff --git a/vendor/github.com/containerd/cri-containerd/cri.go b/vendor/github.com/containerd/cri-containerd/cri.go deleted file mode 100644 index 4da21e910..000000000 --- a/vendor/github.com/containerd/cri-containerd/cri.go +++ /dev/null @@ -1,114 +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 cri - -import ( - "flag" - "path/filepath" - - "github.com/containerd/containerd/log" - "github.com/containerd/containerd/platforms" - "github.com/containerd/containerd/plugin" - imagespec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - - criconfig "github.com/containerd/cri-containerd/pkg/config" - "github.com/containerd/cri-containerd/pkg/server" -) - -// criVersion is the CRI version supported by the CRI plugin. -const criVersion = "v1alpha2" - -// TODO(random-liu): Use github.com/pkg/errors for our errors. -// Register CRI service plugin -func init() { - config := criconfig.DefaultConfig() - plugin.Register(&plugin.Registration{ - Type: plugin.GRPCPlugin, - ID: "cri", - Config: &config, - Requires: []plugin.Type{ - plugin.RuntimePlugin, - plugin.SnapshotPlugin, - plugin.TaskMonitorPlugin, - plugin.DiffPlugin, - plugin.MetadataPlugin, - plugin.ContentPlugin, - plugin.GCPlugin, - }, - InitFn: initCRIService, - }) -} - -func initCRIService(ic *plugin.InitContext) (interface{}, error) { - ic.Meta.Platforms = []imagespec.Platform{platforms.DefaultSpec()} - ic.Meta.Exports = map[string]string{"CRIVersion": criVersion} - ctx := ic.Context - pluginConfig := ic.Config.(*criconfig.PluginConfig) - c := criconfig.Config{ - PluginConfig: *pluginConfig, - // This is a hack. We assume that containerd root directory - // is one level above plugin directory. - // TODO(random-liu): Expose containerd config to plugin. - ContainerdRootDir: filepath.Dir(ic.Root), - ContainerdEndpoint: ic.Address, - RootDir: ic.Root, - } - log.G(ctx).Infof("Start cri plugin with config %+v", c) - - if err := setGLogLevel(); err != nil { - return nil, errors.Wrap(err, "failed to set glog level") - } - - s, err := server.NewCRIContainerdService(c) - if err != nil { - return nil, errors.Wrap(err, "failed to create CRI service") - } - - // Use a goroutine to initialize cri service. The reason is that currently - // cri service requires containerd to be initialize. - go func() { - if err := s.Run(); err != nil { - log.G(ctx).WithError(err).Fatal("Failed to run CRI service") - } - // TODO(random-liu): Whether and how we can stop containerd. - }() - return s, nil -} - -// Set glog level. -func setGLogLevel() error { - l := logrus.GetLevel() - if err := flag.Set("logtostderr", "true"); err != nil { - return err - } - switch l { - case log.TraceLevel: - return flag.Set("v", "5") - case logrus.DebugLevel: - return flag.Set("v", "4") - case logrus.InfoLevel: - return flag.Set("v", "2") - // glog doesn't support following filters. Defaults to v=0. - case logrus.WarnLevel: - case logrus.ErrorLevel: - case logrus.FatalLevel: - case logrus.PanicLevel: - } - return nil -} diff --git a/vendor/github.com/containerd/cri-containerd/LICENSE b/vendor/github.com/containerd/cri/LICENSE similarity index 100% rename from vendor/github.com/containerd/cri-containerd/LICENSE rename to vendor/github.com/containerd/cri/LICENSE diff --git a/vendor/github.com/containerd/cri-containerd/README.md b/vendor/github.com/containerd/cri/README.md similarity index 100% rename from vendor/github.com/containerd/cri-containerd/README.md rename to vendor/github.com/containerd/cri/README.md diff --git a/vendor/github.com/containerd/cri/cli/cli.go b/vendor/github.com/containerd/cri/cli/cli.go new file mode 100644 index 000000000..3a98f61da --- /dev/null +++ b/vendor/github.com/containerd/cri/cli/cli.go @@ -0,0 +1,78 @@ +/* +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 cli + +import ( + gocontext "context" + "fmt" + "path/filepath" + + api "github.com/containerd/cri/pkg/api/v1" + "github.com/containerd/cri/pkg/client" + "github.com/pkg/errors" + "github.com/urfave/cli" +) + +// Command is the cli command for cri plugin. +var Command = cli.Command{ + Name: "cri", + Usage: "interact with cri plugin", + Subcommands: cli.Commands{ + loadCommand, + }, +} + +var loadCommand = cli.Command{ + Name: "load", + Usage: "load one or more images from tar archives.", + ArgsUsage: "[flags] TAR [TAR, ...]", + Description: "load one or more images from tar archives.", + Flags: []cli.Flag{}, + Action: func(context *cli.Context) error { + var ( + ctx = gocontext.Background() + address = context.GlobalString("address") + timeout = context.GlobalDuration("timeout") + cancel gocontext.CancelFunc + ) + cl, err := client.NewCRIContainerdClient(address, timeout) + if err != nil { + return fmt.Errorf("failed to create grpc client: %v", err) + } + if timeout > 0 { + ctx, cancel = gocontext.WithTimeout(gocontext.Background(), timeout) + } else { + ctx, cancel = gocontext.WithCancel(ctx) + } + defer cancel() + for _, path := range context.Args() { + absPath, err := filepath.Abs(path) + if err != nil { + return errors.Wrap(err, "failed to get absolute path") + } + res, err := cl.LoadImage(ctx, &api.LoadImageRequest{FilePath: absPath}) + if err != nil { + return errors.Wrap(err, "failed to load image") + } + images := res.GetImages() + for _, image := range images { + fmt.Println("Loaded image:", image) + } + } + return nil + }, +} diff --git a/vendor/github.com/containerd/cri/cri.go b/vendor/github.com/containerd/cri/cri.go new file mode 100644 index 000000000..e1dba68ea --- /dev/null +++ b/vendor/github.com/containerd/cri/cri.go @@ -0,0 +1,181 @@ +/* +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 cri + +import ( + "flag" + "path/filepath" + + "github.com/containerd/containerd" + "github.com/containerd/containerd/api/services/containers/v1" + "github.com/containerd/containerd/api/services/diff/v1" + "github.com/containerd/containerd/api/services/images/v1" + "github.com/containerd/containerd/api/services/leases/v1" + "github.com/containerd/containerd/api/services/namespaces/v1" + "github.com/containerd/containerd/api/services/tasks/v1" + "github.com/containerd/containerd/content" + "github.com/containerd/containerd/log" + "github.com/containerd/containerd/platforms" + "github.com/containerd/containerd/plugin" + "github.com/containerd/containerd/services" + "github.com/containerd/containerd/snapshots" + imagespec "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + + criconfig "github.com/containerd/cri/pkg/config" + "github.com/containerd/cri/pkg/constants" + "github.com/containerd/cri/pkg/server" +) + +// TODO(random-liu): Use github.com/pkg/errors for our errors. +// Register CRI service plugin +func init() { + config := criconfig.DefaultConfig() + plugin.Register(&plugin.Registration{ + Type: plugin.GRPCPlugin, + ID: "cri", + Config: &config, + Requires: []plugin.Type{ + plugin.ServicePlugin, + }, + InitFn: initCRIService, + }) +} + +func initCRIService(ic *plugin.InitContext) (interface{}, error) { + ic.Meta.Platforms = []imagespec.Platform{platforms.DefaultSpec()} + ic.Meta.Exports = map[string]string{"CRIVersion": constants.CRIVersion} + ctx := ic.Context + pluginConfig := ic.Config.(*criconfig.PluginConfig) + c := criconfig.Config{ + PluginConfig: *pluginConfig, + // This is a hack. We assume that containerd root directory + // is one level above plugin directory. + // TODO(random-liu): Expose containerd config to plugin. + ContainerdRootDir: filepath.Dir(ic.Root), + ContainerdEndpoint: ic.Address, + RootDir: ic.Root, + } + log.G(ctx).Infof("Start cri plugin with config %+v", c) + + if err := setGLogLevel(); err != nil { + return nil, errors.Wrap(err, "failed to set glog level") + } + + servicesOpts, err := getServicesOpts(ic) + if err != nil { + return nil, errors.Wrap(err, "failed to get services") + } + + log.G(ctx).Info("Connect containerd service") + client, err := containerd.New( + "", + containerd.WithDefaultNamespace(constants.K8sContainerdNamespace), + containerd.WithServices(servicesOpts...), + ) + if err != nil { + return nil, errors.Wrap(err, "failed to create containerd client") + } + + s, err := server.NewCRIContainerdService(c, client) + if err != nil { + return nil, errors.Wrap(err, "failed to create CRI service") + } + + go func() { + if err := s.Run(); err != nil { + log.G(ctx).WithError(err).Fatal("Failed to run CRI service") + } + // TODO(random-liu): Whether and how we can stop containerd. + }() + return s, nil +} + +// getServicesOpts get service options from plugin context. +func getServicesOpts(ic *plugin.InitContext) ([]containerd.ServicesOpt, error) { + plugins, err := ic.GetByType(plugin.ServicePlugin) + if err != nil { + return nil, errors.Wrap(err, "failed to get service plugin") + } + + opts := []containerd.ServicesOpt{ + containerd.WithEventService(ic.Events), + } + for s, fn := range map[string]func(interface{}) containerd.ServicesOpt{ + services.ContentService: func(s interface{}) containerd.ServicesOpt { + return containerd.WithContentStore(s.(content.Store)) + }, + services.ImagesService: func(s interface{}) containerd.ServicesOpt { + return containerd.WithImageService(s.(images.ImagesClient)) + }, + services.SnapshotsService: func(s interface{}) containerd.ServicesOpt { + return containerd.WithSnapshotters(s.(map[string]snapshots.Snapshotter)) + }, + services.ContainersService: func(s interface{}) containerd.ServicesOpt { + return containerd.WithContainerService(s.(containers.ContainersClient)) + }, + services.TasksService: func(s interface{}) containerd.ServicesOpt { + return containerd.WithTaskService(s.(tasks.TasksClient)) + }, + services.DiffService: func(s interface{}) containerd.ServicesOpt { + return containerd.WithDiffService(s.(diff.DiffClient)) + }, + services.NamespacesService: func(s interface{}) containerd.ServicesOpt { + return containerd.WithNamespaceService(s.(namespaces.NamespacesClient)) + }, + services.LeasesService: func(s interface{}) containerd.ServicesOpt { + return containerd.WithLeasesService(s.(leases.LeasesClient)) + }, + } { + p := plugins[s] + if p == nil { + return nil, errors.Errorf("service %q not found", s) + } + i, err := p.Instance() + if err != nil { + return nil, errors.Wrapf(err, "failed to get instance of service %q", s) + } + if i == nil { + return nil, errors.Errorf("instance of service %q not found", s) + } + opts = append(opts, fn(i)) + } + return opts, nil +} + +// Set glog level. +func setGLogLevel() error { + l := logrus.GetLevel() + if err := flag.Set("logtostderr", "true"); err != nil { + return err + } + switch l { + case log.TraceLevel: + return flag.Set("v", "5") + case logrus.DebugLevel: + return flag.Set("v", "4") + case logrus.InfoLevel: + return flag.Set("v", "2") + // glog doesn't support following filters. Defaults to v=0. + case logrus.WarnLevel: + case logrus.ErrorLevel: + case logrus.FatalLevel: + case logrus.PanicLevel: + } + return nil +} diff --git a/vendor/github.com/containerd/cri-containerd/pkg/annotations/annotations.go b/vendor/github.com/containerd/cri/pkg/annotations/annotations.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/annotations/annotations.go rename to vendor/github.com/containerd/cri/pkg/annotations/annotations.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/api/v1/api.pb.go b/vendor/github.com/containerd/cri/pkg/api/v1/api.pb.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/api/v1/api.pb.go rename to vendor/github.com/containerd/cri/pkg/api/v1/api.pb.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/api/v1/api.proto b/vendor/github.com/containerd/cri/pkg/api/v1/api.proto similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/api/v1/api.proto rename to vendor/github.com/containerd/cri/pkg/api/v1/api.proto diff --git a/vendor/github.com/containerd/cri-containerd/pkg/atomic/atomic_boolean.go b/vendor/github.com/containerd/cri/pkg/atomic/atomic_boolean.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/atomic/atomic_boolean.go rename to vendor/github.com/containerd/cri/pkg/atomic/atomic_boolean.go diff --git a/vendor/github.com/containerd/cri/pkg/client/client.go b/vendor/github.com/containerd/cri/pkg/client/client.go new file mode 100644 index 000000000..f38c726c0 --- /dev/null +++ b/vendor/github.com/containerd/cri/pkg/client/client.go @@ -0,0 +1,47 @@ +/* +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 client + +import ( + "fmt" + "time" + + "google.golang.org/grpc" + "k8s.io/kubernetes/pkg/kubelet/util" + + api "github.com/containerd/cri/pkg/api/v1" +) + +// NewCRIContainerdClient creates grpc client of cri-containerd +// TODO(random-liu): Wrap grpc functions. +func NewCRIContainerdClient(endpoint string, timeout time.Duration) (api.CRIContainerdServiceClient, error) { + addr, dialer, err := util.GetAddressAndDialer(endpoint) + if err != nil { + return nil, fmt.Errorf("failed to get dialer: %v", err) + } + conn, err := grpc.Dial(addr, + grpc.WithBlock(), + grpc.WithInsecure(), + // TODO(random-liu): WithTimeout is being deprecated, use context instead. + grpc.WithTimeout(timeout), + grpc.WithDialer(dialer), + ) + if err != nil { + return nil, fmt.Errorf("failed to dial: %v", err) + } + return api.NewCRIContainerdServiceClient(conn), nil +} diff --git a/vendor/github.com/containerd/cri-containerd/pkg/config/config.go b/vendor/github.com/containerd/cri/pkg/config/config.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/config/config.go rename to vendor/github.com/containerd/cri/pkg/config/config.go diff --git a/vendor/github.com/containerd/cri/pkg/constants/constants.go b/vendor/github.com/containerd/cri/pkg/constants/constants.go new file mode 100644 index 000000000..7b71b6f9a --- /dev/null +++ b/vendor/github.com/containerd/cri/pkg/constants/constants.go @@ -0,0 +1,26 @@ +/* +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 constants + +// TODO(random-liu): Merge annotations package into this package. + +const ( + // K8sContainerdNamespace is the namespace we use to connect containerd. + K8sContainerdNamespace = "k8s.io" + // CRIVersion is the CRI version supported by the CRI plugin. + CRIVersion = "v1alpha2" +) diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/importer/importer.go b/vendor/github.com/containerd/cri/pkg/containerd/importer/importer.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/importer/importer.go rename to vendor/github.com/containerd/cri/pkg/containerd/importer/importer.go index fd6d97288..b97b593c1 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/containerd/importer/importer.go +++ b/vendor/github.com/containerd/cri/pkg/containerd/importer/importer.go @@ -36,8 +36,8 @@ import ( ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" - ctrdutil "github.com/containerd/cri-containerd/pkg/containerd/util" - "github.com/containerd/cri-containerd/pkg/util" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + "github.com/containerd/cri/pkg/util" ) // This code reuses the docker import code from containerd/containerd#1602. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/opts/container.go b/vendor/github.com/containerd/cri/pkg/containerd/opts/container.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/opts/container.go rename to vendor/github.com/containerd/cri/pkg/containerd/opts/container.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/opts/task.go b/vendor/github.com/containerd/cri/pkg/containerd/opts/task.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/opts/task.go rename to vendor/github.com/containerd/cri/pkg/containerd/opts/task.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/auth.go b/vendor/github.com/containerd/cri/pkg/containerd/resolver/auth.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/auth.go rename to vendor/github.com/containerd/cri/pkg/containerd/resolver/auth.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/fetcher.go b/vendor/github.com/containerd/cri/pkg/containerd/resolver/fetcher.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/fetcher.go rename to vendor/github.com/containerd/cri/pkg/containerd/resolver/fetcher.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/httpreadseeker.go b/vendor/github.com/containerd/cri/pkg/containerd/resolver/httpreadseeker.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/httpreadseeker.go rename to vendor/github.com/containerd/cri/pkg/containerd/resolver/httpreadseeker.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/resolver.go b/vendor/github.com/containerd/cri/pkg/containerd/resolver/resolver.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/resolver.go rename to vendor/github.com/containerd/cri/pkg/containerd/resolver/resolver.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/scope.go b/vendor/github.com/containerd/cri/pkg/containerd/resolver/scope.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/scope.go rename to vendor/github.com/containerd/cri/pkg/containerd/resolver/scope.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/status.go b/vendor/github.com/containerd/cri/pkg/containerd/resolver/status.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/resolver/status.go rename to vendor/github.com/containerd/cri/pkg/containerd/resolver/status.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/containerd/util/util.go b/vendor/github.com/containerd/cri/pkg/containerd/util/util.go similarity index 65% rename from vendor/github.com/containerd/cri-containerd/pkg/containerd/util/util.go rename to vendor/github.com/containerd/cri/pkg/containerd/util/util.go index 70f5f2edf..7c50f2c65 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/containerd/util/util.go +++ b/vendor/github.com/containerd/cri/pkg/containerd/util/util.go @@ -19,7 +19,10 @@ package util import ( "time" + "github.com/containerd/containerd/namespaces" "golang.org/x/net/context" + + "github.com/containerd/cri/pkg/constants" ) // deferCleanupTimeout is the default timeout for containerd cleanup operations @@ -28,8 +31,16 @@ const deferCleanupTimeout = 1 * time.Minute // DeferContext returns a context for containerd cleanup operations in defer. // A default timeout is applied to avoid cleanup operation pending forever. -// TODO(random-liu): Add namespace after local services are used. -// (containerd/containerd#2183) func DeferContext() (context.Context, context.CancelFunc) { - return context.WithTimeout(context.Background(), deferCleanupTimeout) + return context.WithTimeout(NamespacedContext(), deferCleanupTimeout) +} + +// NamespacedContext returns a context with kubernetes namespace set. +func NamespacedContext() context.Context { + return WithNamespace(context.Background()) +} + +// WithNamespace adds kubernetes namespace to the context. +func WithNamespace(ctx context.Context) context.Context { + return namespaces.WithNamespace(ctx, constants.K8sContainerdNamespace) } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/ioutil/read_closer.go b/vendor/github.com/containerd/cri/pkg/ioutil/read_closer.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/ioutil/read_closer.go rename to vendor/github.com/containerd/cri/pkg/ioutil/read_closer.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/ioutil/write_closer.go b/vendor/github.com/containerd/cri/pkg/ioutil/write_closer.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/ioutil/write_closer.go rename to vendor/github.com/containerd/cri/pkg/ioutil/write_closer.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/ioutil/writer_group.go b/vendor/github.com/containerd/cri/pkg/ioutil/writer_group.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/ioutil/writer_group.go rename to vendor/github.com/containerd/cri/pkg/ioutil/writer_group.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/log/log.go b/vendor/github.com/containerd/cri/pkg/log/log.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/log/log.go rename to vendor/github.com/containerd/cri/pkg/log/log.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/os/os.go b/vendor/github.com/containerd/cri/pkg/os/os.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/os/os.go rename to vendor/github.com/containerd/cri/pkg/os/os.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/registrar/registrar.go b/vendor/github.com/containerd/cri/pkg/registrar/registrar.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/registrar/registrar.go rename to vendor/github.com/containerd/cri/pkg/registrar/registrar.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_attach.go b/vendor/github.com/containerd/cri/pkg/server/container_attach.go similarity index 97% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_attach.go rename to vendor/github.com/containerd/cri/pkg/server/container_attach.go index c823f0953..49cbf8f01 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_attach.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_attach.go @@ -26,7 +26,7 @@ import ( "k8s.io/client-go/tools/remotecommand" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - cio "github.com/containerd/cri-containerd/pkg/server/io" + cio "github.com/containerd/cri/pkg/server/io" ) // Attach prepares a streaming endpoint to attach to a running container, and returns the address. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_create.go b/vendor/github.com/containerd/cri/pkg/server/container_create.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_create.go rename to vendor/github.com/containerd/cri/pkg/server/container_create.go index 174188a84..266988fe1 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_create.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_create.go @@ -29,7 +29,6 @@ import ( "github.com/containerd/containerd/contrib/seccomp" "github.com/containerd/containerd/linux/runctypes" "github.com/containerd/containerd/mount" - "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/oci" "github.com/containerd/typeurl" "github.com/davecgh/go-spew/spew" @@ -45,12 +44,12 @@ import ( "golang.org/x/sys/unix" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - "github.com/containerd/cri-containerd/pkg/annotations" - customopts "github.com/containerd/cri-containerd/pkg/containerd/opts" - ctrdutil "github.com/containerd/cri-containerd/pkg/containerd/util" - cio "github.com/containerd/cri-containerd/pkg/server/io" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" - "github.com/containerd/cri-containerd/pkg/util" + "github.com/containerd/cri/pkg/annotations" + customopts "github.com/containerd/cri/pkg/containerd/opts" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + cio "github.com/containerd/cri/pkg/server/io" + containerstore "github.com/containerd/cri/pkg/store/container" + "github.com/containerd/cri/pkg/util" ) const ( @@ -70,7 +69,7 @@ const ( func init() { typeurl.Register(&containerstore.Metadata{}, - "github.com/containerd/cri-containerd/pkg/store/container", "Metadata") + "github.com/containerd/cri/pkg/store/container", "Metadata") } // CreateContainer creates a new container in the given PodSandbox. @@ -730,7 +729,7 @@ func setOCINamespaces(g *generate.Generator, namespaces *runtime.NamespaceOption // defaultRuntimeSpec returns a default runtime spec used in cri-containerd. func defaultRuntimeSpec(id string) (*runtimespec.Spec, error) { // GenerateSpec needs namespace. - ctx := namespaces.WithNamespace(context.Background(), k8sContainerdNamespace) + ctx := ctrdutil.NamespacedContext() spec, err := oci.GenerateSpec(ctx, nil, &containers.Container{ID: id}) if err != nil { return nil, err diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_exec.go b/vendor/github.com/containerd/cri/pkg/server/container_exec.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_exec.go rename to vendor/github.com/containerd/cri/pkg/server/container_exec.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_execsync.go b/vendor/github.com/containerd/cri/pkg/server/container_execsync.go similarity index 96% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_execsync.go rename to vendor/github.com/containerd/cri/pkg/server/container_execsync.go index 6893a52b5..e2f6c7592 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_execsync.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_execsync.go @@ -31,10 +31,10 @@ import ( "k8s.io/client-go/tools/remotecommand" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - ctrdutil "github.com/containerd/cri-containerd/pkg/containerd/util" - cioutil "github.com/containerd/cri-containerd/pkg/ioutil" - cio "github.com/containerd/cri-containerd/pkg/server/io" - "github.com/containerd/cri-containerd/pkg/util" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + cioutil "github.com/containerd/cri/pkg/ioutil" + cio "github.com/containerd/cri/pkg/server/io" + "github.com/containerd/cri/pkg/util" ) // ExecSync executes a command in the container, and returns the stdout output. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_list.go b/vendor/github.com/containerd/cri/pkg/server/container_list.go similarity index 97% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_list.go rename to vendor/github.com/containerd/cri/pkg/server/container_list.go index b8e1c0c46..01bd4fa1a 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_list.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_list.go @@ -21,7 +21,7 @@ import ( runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" + containerstore "github.com/containerd/cri/pkg/store/container" ) // ListContainers lists all containers matching the filter. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_log_reopen.go b/vendor/github.com/containerd/cri/pkg/server/container_log_reopen.go similarity index 96% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_log_reopen.go rename to vendor/github.com/containerd/cri/pkg/server/container_log_reopen.go index b233e65d4..5961ca20d 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_log_reopen.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_log_reopen.go @@ -23,7 +23,7 @@ import ( runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" ) -// ReopenContainerLog asks cri-containerd to reopen the stdout/stderr log file for the container. +// ReopenContainerLog asks the cri plugin to reopen the stdout/stderr log file for the container. // This is often called after the log file has been rotated. func (c *criContainerdService) ReopenContainerLog(ctx context.Context, r *runtime.ReopenContainerLogRequest) (*runtime.ReopenContainerLogResponse, error) { container, err := c.containerStore.Get(r.GetContainerId()) diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_remove.go b/vendor/github.com/containerd/cri/pkg/server/container_remove.go similarity index 96% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_remove.go rename to vendor/github.com/containerd/cri/pkg/server/container_remove.go index 6179bf658..16e29b8aa 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_remove.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_remove.go @@ -26,9 +26,9 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - "github.com/containerd/cri-containerd/pkg/log" - "github.com/containerd/cri-containerd/pkg/store" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" + "github.com/containerd/cri/pkg/log" + "github.com/containerd/cri/pkg/store" + containerstore "github.com/containerd/cri/pkg/store/container" ) // RemoveContainer removes the container. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_start.go b/vendor/github.com/containerd/cri/pkg/server/container_start.go similarity index 95% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_start.go rename to vendor/github.com/containerd/cri/pkg/server/container_start.go index b8acb789a..e605b800c 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_start.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_start.go @@ -28,10 +28,10 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - ctrdutil "github.com/containerd/cri-containerd/pkg/containerd/util" - cio "github.com/containerd/cri-containerd/pkg/server/io" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + cio "github.com/containerd/cri/pkg/server/io" + containerstore "github.com/containerd/cri/pkg/store/container" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" ) // StartContainer starts the container. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_stats.go b/vendor/github.com/containerd/cri/pkg/server/container_stats.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_stats.go rename to vendor/github.com/containerd/cri/pkg/server/container_stats.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_stats_list.go b/vendor/github.com/containerd/cri/pkg/server/container_stats_list.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_stats_list.go rename to vendor/github.com/containerd/cri/pkg/server/container_stats_list.go index 5ced5af1c..40a0a4d4b 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_stats_list.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_stats_list.go @@ -26,7 +26,7 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" + containerstore "github.com/containerd/cri/pkg/store/container" ) // ListContainerStats returns stats of all running containers. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_status.go b/vendor/github.com/containerd/cri/pkg/server/container_status.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_status.go rename to vendor/github.com/containerd/cri/pkg/server/container_status.go index 02a41ae1d..5edbdefc1 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_status.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_status.go @@ -25,7 +25,7 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" + containerstore "github.com/containerd/cri/pkg/store/container" ) // ContainerStatus inspects the container and returns the status. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_stop.go b/vendor/github.com/containerd/cri/pkg/server/container_stop.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_stop.go rename to vendor/github.com/containerd/cri/pkg/server/container_stop.go index bf892190a..47607a702 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_stop.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_stop.go @@ -28,7 +28,7 @@ import ( "golang.org/x/sys/unix" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" + containerstore "github.com/containerd/cri/pkg/store/container" ) // killContainerTimeout is the timeout that we wait for the container to diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/container_update_resources.go b/vendor/github.com/containerd/cri/pkg/server/container_update_resources.go similarity index 96% rename from vendor/github.com/containerd/cri-containerd/pkg/server/container_update_resources.go rename to vendor/github.com/containerd/cri/pkg/server/container_update_resources.go index 1b2841629..5f499ff25 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/container_update_resources.go +++ b/vendor/github.com/containerd/cri/pkg/server/container_update_resources.go @@ -29,9 +29,9 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - ctrdutil "github.com/containerd/cri-containerd/pkg/containerd/util" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" - "github.com/containerd/cri-containerd/pkg/util" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + containerstore "github.com/containerd/cri/pkg/store/container" + "github.com/containerd/cri/pkg/util" ) // UpdateContainerResources updates ContainerConfig of the container. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/events.go b/vendor/github.com/containerd/cri/pkg/server/events.go similarity index 89% rename from vendor/github.com/containerd/cri-containerd/pkg/server/events.go rename to vendor/github.com/containerd/cri/pkg/server/events.go index 893032033..58f0bfab5 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/events.go +++ b/vendor/github.com/containerd/cri/pkg/server/events.go @@ -19,7 +19,6 @@ package server import ( "errors" - "github.com/containerd/containerd" eventtypes "github.com/containerd/containerd/api/events" containerdio "github.com/containerd/containerd/cio" "github.com/containerd/containerd/errdefs" @@ -28,9 +27,10 @@ import ( "github.com/sirupsen/logrus" "golang.org/x/net/context" - "github.com/containerd/cri-containerd/pkg/store" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + "github.com/containerd/cri/pkg/store" + containerstore "github.com/containerd/cri/pkg/store/container" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" ) // eventMonitor monitors containerd event and updates internal state correspondingly. @@ -48,6 +48,7 @@ type eventMonitor struct { // Create new event monitor. New event monitor will start subscribing containerd event. All events // happen after it should be monitored. func newEventMonitor(c *containerstore.Store, s *sandboxstore.Store) *eventMonitor { + // event subscribe doesn't need namespace. ctx, cancel := context.WithCancel(context.Background()) return &eventMonitor{ containerStore: c, @@ -58,12 +59,12 @@ func newEventMonitor(c *containerstore.Store, s *sandboxstore.Store) *eventMonit } // subscribe starts to subscribe containerd events. -func (em *eventMonitor) subscribe(client *containerd.Client) { +func (em *eventMonitor) subscribe(subscriber events.Subscriber) { filters := []string{ `topic=="/tasks/exit"`, `topic=="/tasks/oom"`, } - em.ch, em.errCh = client.Subscribe(em.ctx, filters...) + em.ch, em.errCh = subscriber.Subscribe(em.ctx, filters...) } // start starts the event monitor which monitors and handles all container events. It returns @@ -98,6 +99,7 @@ func (em *eventMonitor) stop() { // handleEvent handles a containerd event. func (em *eventMonitor) handleEvent(evt *events.Envelope) { + ctx := ctrdutil.NamespacedContext() any, err := typeurl.UnmarshalAny(evt.Event) if err != nil { logrus.WithError(err).Errorf("Failed to convert event envelope %+v", evt) @@ -113,7 +115,7 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) { logrus.Infof("TaskExit event %+v", e) cntr, err := em.containerStore.Get(e.ContainerID) if err == nil { - handleContainerExit(e, cntr) + handleContainerExit(ctx, e, cntr) return } else if err != store.ErrNotExist { logrus.WithError(err).Errorf("Failed to get container %q", e.ContainerID) @@ -122,7 +124,7 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) { // Use GetAll to include sandbox in unknown state. sb, err := em.sandboxStore.GetAll(e.ContainerID) if err == nil { - handleSandboxExit(e, sb) + handleSandboxExit(ctx, e, sb) return } else if err != store.ErrNotExist { logrus.WithError(err).Errorf("Failed to get sandbox %q", e.ContainerID) @@ -151,13 +153,13 @@ func (em *eventMonitor) handleEvent(evt *events.Envelope) { } // handleContainerExit handles TaskExit event for container. -func handleContainerExit(e *eventtypes.TaskExit, cntr containerstore.Container) { +func handleContainerExit(ctx context.Context, e *eventtypes.TaskExit, cntr containerstore.Container) { if e.Pid != cntr.Status.Get().Pid { // Non-init process died, ignore the event. return } // Attach container IO so that `Delete` could cleanup the stream properly. - task, err := cntr.Container.Task(context.Background(), + task, err := cntr.Container.Task(ctx, func(*containerdio.FIFOSet) (containerdio.IO, error) { return cntr.IO, nil }, @@ -169,7 +171,7 @@ func handleContainerExit(e *eventtypes.TaskExit, cntr containerstore.Container) } } else { // TODO(random-liu): [P1] This may block the loop, we may want to spawn a worker - if _, err = task.Delete(context.Background()); err != nil { + if _, err = task.Delete(ctx); err != nil { // TODO(random-liu): [P0] Enqueue the event and retry. if !errdefs.IsNotFound(err) { logrus.WithError(err).Errorf("failed to stop container %q", e.ContainerID) @@ -199,13 +201,13 @@ func handleContainerExit(e *eventtypes.TaskExit, cntr containerstore.Container) } // handleSandboxExit handles TaskExit event for sandbox. -func handleSandboxExit(e *eventtypes.TaskExit, sb sandboxstore.Sandbox) { +func handleSandboxExit(ctx context.Context, e *eventtypes.TaskExit, sb sandboxstore.Sandbox) { if e.Pid != sb.Status.Get().Pid { // Non-init process died, ignore the event. return } // No stream attached to sandbox container. - task, err := sb.Container.Task(context.Background(), nil) + task, err := sb.Container.Task(ctx, nil) if err != nil { if !errdefs.IsNotFound(err) { logrus.WithError(err).Errorf("failed to load task for sandbox %q", e.ContainerID) @@ -213,7 +215,7 @@ func handleSandboxExit(e *eventtypes.TaskExit, sb sandboxstore.Sandbox) { } } else { // TODO(random-liu): [P1] This may block the loop, we may want to spawn a worker - if _, err = task.Delete(context.Background()); err != nil { + if _, err = task.Delete(ctx); err != nil { // TODO(random-liu): [P0] Enqueue the event and retry. if !errdefs.IsNotFound(err) { logrus.WithError(err).Errorf("failed to stop sandbox %q", e.ContainerID) diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/helpers.go b/vendor/github.com/containerd/cri/pkg/server/helpers.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/helpers.go rename to vendor/github.com/containerd/cri/pkg/server/helpers.go index a7956a28e..5a30c8d9d 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/helpers.go +++ b/vendor/github.com/containerd/cri/pkg/server/helpers.go @@ -39,9 +39,9 @@ import ( runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" "k8s.io/kubernetes/pkg/util/sysctl" - "github.com/containerd/cri-containerd/pkg/store" - imagestore "github.com/containerd/cri-containerd/pkg/store/image" - "github.com/containerd/cri-containerd/pkg/util" + "github.com/containerd/cri/pkg/store" + imagestore "github.com/containerd/cri/pkg/store/image" + "github.com/containerd/cri/pkg/util" ) const ( diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/image_list.go b/vendor/github.com/containerd/cri/pkg/server/image_list.go similarity index 96% rename from vendor/github.com/containerd/cri-containerd/pkg/server/image_list.go rename to vendor/github.com/containerd/cri/pkg/server/image_list.go index 6e19e341e..e770bfe28 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/image_list.go +++ b/vendor/github.com/containerd/cri/pkg/server/image_list.go @@ -20,7 +20,7 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - imagestore "github.com/containerd/cri-containerd/pkg/store/image" + imagestore "github.com/containerd/cri/pkg/store/image" ) // ListImages lists existing images. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/image_load.go b/vendor/github.com/containerd/cri/pkg/server/image_load.go similarity index 92% rename from vendor/github.com/containerd/cri-containerd/pkg/server/image_load.go rename to vendor/github.com/containerd/cri/pkg/server/image_load.go index 27ada0db1..b19b2291a 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/image_load.go +++ b/vendor/github.com/containerd/cri/pkg/server/image_load.go @@ -24,9 +24,9 @@ import ( "github.com/sirupsen/logrus" - api "github.com/containerd/cri-containerd/pkg/api/v1" - "github.com/containerd/cri-containerd/pkg/containerd/importer" - imagestore "github.com/containerd/cri-containerd/pkg/store/image" + api "github.com/containerd/cri/pkg/api/v1" + "github.com/containerd/cri/pkg/containerd/importer" + imagestore "github.com/containerd/cri/pkg/store/image" ) // LoadImage loads a image into containerd. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/image_pull.go b/vendor/github.com/containerd/cri/pkg/server/image_pull.go similarity index 96% rename from vendor/github.com/containerd/cri-containerd/pkg/server/image_pull.go rename to vendor/github.com/containerd/cri/pkg/server/image_pull.go index 02bcfb902..fc1e48836 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/image_pull.go +++ b/vendor/github.com/containerd/cri/pkg/server/image_pull.go @@ -30,9 +30,9 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - containerdresolver "github.com/containerd/cri-containerd/pkg/containerd/resolver" - imagestore "github.com/containerd/cri-containerd/pkg/store/image" - "github.com/containerd/cri-containerd/pkg/util" + containerdresolver "github.com/containerd/cri/pkg/containerd/resolver" + imagestore "github.com/containerd/cri/pkg/store/image" + "github.com/containerd/cri/pkg/util" ) // For image management: @@ -66,9 +66,9 @@ import ( // an error occurrs during the pulling, should we remove the entry from metadata // store? Or should we leave it there until next startup (resource leakage)? // -// 3) CRI-containerd only exposes "READY" (successfully pulled and unpacked) images +// 3) The cri plugin only exposes "READY" (successfully pulled and unpacked) images // to the user, which are maintained in the in-memory metadata index. However, it's -// still possible that someone else removes the content or snapshot by-pass cri-containerd, +// still possible that someone else removes the content or snapshot by-pass the cri plugin, // how do we detect that and update the in-memory metadata correspondingly? Always // check whether corresponding snapshot is ready when reporting image status? // diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/image_remove.go b/vendor/github.com/containerd/cri/pkg/server/image_remove.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/image_remove.go rename to vendor/github.com/containerd/cri/pkg/server/image_remove.go index d0f7db548..66a3693d8 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/image_remove.go +++ b/vendor/github.com/containerd/cri/pkg/server/image_remove.go @@ -56,7 +56,7 @@ func (c *criContainerdService) RemoveImage(ctx context.Context, r *runtime.Remov // We can only get image id by reading Config from content. // If the config is missing, we will fail to get image id, // So we won't be able to remove the image forever, - // and cri-containerd always report the image is ok. + // and the cri plugin always reports the image is ok. // But we also don't check it by manifest, // It's possible that two manifest digests have the same image ID in theory. // In theory it's possible that an image is compressed with different algorithms, diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/image_status.go b/vendor/github.com/containerd/cri/pkg/server/image_status.go similarity index 97% rename from vendor/github.com/containerd/cri-containerd/pkg/server/image_status.go rename to vendor/github.com/containerd/cri/pkg/server/image_status.go index d2f78158f..758b3779c 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/image_status.go +++ b/vendor/github.com/containerd/cri/pkg/server/image_status.go @@ -24,7 +24,7 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - imagestore "github.com/containerd/cri-containerd/pkg/store/image" + imagestore "github.com/containerd/cri/pkg/store/image" imagespec "github.com/opencontainers/image-spec/specs-go/v1" ) diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/imagefs_info.go b/vendor/github.com/containerd/cri/pkg/server/imagefs_info.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/server/imagefs_info.go rename to vendor/github.com/containerd/cri/pkg/server/imagefs_info.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/instrumented_service.go b/vendor/github.com/containerd/cri/pkg/server/instrumented_service.go similarity index 89% rename from vendor/github.com/containerd/cri-containerd/pkg/server/instrumented_service.go rename to vendor/github.com/containerd/cri/pkg/server/instrumented_service.go index 37f57221d..f3adc6433 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/instrumented_service.go +++ b/vendor/github.com/containerd/cri/pkg/server/instrumented_service.go @@ -23,11 +23,12 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - api "github.com/containerd/cri-containerd/pkg/api/v1" - "github.com/containerd/cri-containerd/pkg/log" + api "github.com/containerd/cri/pkg/api/v1" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + "github.com/containerd/cri/pkg/log" ) -// instrumentedService wraps service and logs each operation. +// instrumentedService wraps service with containerd namespace and logs. type instrumentedService struct { c *criContainerdService } @@ -59,7 +60,7 @@ func (in *instrumentedService) RunPodSandbox(ctx context.Context, r *runtime.Run logrus.Infof("RunPodSandbox for %+v returns sandbox id %q", r.GetConfig().GetMetadata(), res.GetPodSandboxId()) } }() - return in.c.RunPodSandbox(ctx, r) + return in.c.RunPodSandbox(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ListPodSandbox(ctx context.Context, r *runtime.ListPodSandboxRequest) (res *runtime.ListPodSandboxResponse, err error) { @@ -74,7 +75,7 @@ func (in *instrumentedService) ListPodSandbox(ctx context.Context, r *runtime.Li log.Tracef("ListPodSandbox returns pod sandboxes %+v", res.GetItems()) } }() - return in.c.ListPodSandbox(ctx, r) + return in.c.ListPodSandbox(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) PodSandboxStatus(ctx context.Context, r *runtime.PodSandboxStatusRequest) (res *runtime.PodSandboxStatusResponse, err error) { @@ -89,7 +90,7 @@ func (in *instrumentedService) PodSandboxStatus(ctx context.Context, r *runtime. log.Tracef("PodSandboxStatus for %q returns status %+v", r.GetPodSandboxId(), res.GetStatus()) } }() - return in.c.PodSandboxStatus(ctx, r) + return in.c.PodSandboxStatus(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandboxRequest) (_ *runtime.StopPodSandboxResponse, err error) { @@ -104,7 +105,7 @@ func (in *instrumentedService) StopPodSandbox(ctx context.Context, r *runtime.St logrus.Infof("StopPodSandbox for %q returns successfully", r.GetPodSandboxId()) } }() - return in.c.StopPodSandbox(ctx, r) + return in.c.StopPodSandbox(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodSandboxRequest) (_ *runtime.RemovePodSandboxResponse, err error) { @@ -119,7 +120,7 @@ func (in *instrumentedService) RemovePodSandbox(ctx context.Context, r *runtime. logrus.Infof("RemovePodSandbox %q returns successfully", r.GetPodSandboxId()) } }() - return in.c.RemovePodSandbox(ctx, r) + return in.c.RemovePodSandbox(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) PortForward(ctx context.Context, r *runtime.PortForwardRequest) (res *runtime.PortForwardResponse, err error) { @@ -134,7 +135,7 @@ func (in *instrumentedService) PortForward(ctx context.Context, r *runtime.PortF logrus.Infof("Portforward for %q returns URL %q", r.GetPodSandboxId(), res.GetUrl()) } }() - return in.c.PortForward(ctx, r) + return in.c.PortForward(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) CreateContainer(ctx context.Context, r *runtime.CreateContainerRequest) (res *runtime.CreateContainerResponse, err error) { @@ -152,7 +153,7 @@ func (in *instrumentedService) CreateContainer(ctx context.Context, r *runtime.C r.GetPodSandboxId(), r.GetConfig().GetMetadata(), res.GetContainerId()) } }() - return in.c.CreateContainer(ctx, r) + return in.c.CreateContainer(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) StartContainer(ctx context.Context, r *runtime.StartContainerRequest) (_ *runtime.StartContainerResponse, err error) { @@ -167,7 +168,7 @@ func (in *instrumentedService) StartContainer(ctx context.Context, r *runtime.St logrus.Infof("StartContainer for %q returns successfully", r.GetContainerId()) } }() - return in.c.StartContainer(ctx, r) + return in.c.StartContainer(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ListContainers(ctx context.Context, r *runtime.ListContainersRequest) (res *runtime.ListContainersResponse, err error) { @@ -183,7 +184,7 @@ func (in *instrumentedService) ListContainers(ctx context.Context, r *runtime.Li r.GetFilter(), res.GetContainers()) } }() - return in.c.ListContainers(ctx, r) + return in.c.ListContainers(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ContainerStatus(ctx context.Context, r *runtime.ContainerStatusRequest) (res *runtime.ContainerStatusResponse, err error) { @@ -198,7 +199,7 @@ func (in *instrumentedService) ContainerStatus(ctx context.Context, r *runtime.C log.Tracef("ContainerStatus for %q returns status %+v", r.GetContainerId(), res.GetStatus()) } }() - return in.c.ContainerStatus(ctx, r) + return in.c.ContainerStatus(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) StopContainer(ctx context.Context, r *runtime.StopContainerRequest) (res *runtime.StopContainerResponse, err error) { @@ -213,7 +214,7 @@ func (in *instrumentedService) StopContainer(ctx context.Context, r *runtime.Sto logrus.Infof("StopContainer for %q returns successfully", r.GetContainerId()) } }() - return in.c.StopContainer(ctx, r) + return in.c.StopContainer(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) RemoveContainer(ctx context.Context, r *runtime.RemoveContainerRequest) (res *runtime.RemoveContainerResponse, err error) { @@ -228,7 +229,7 @@ func (in *instrumentedService) RemoveContainer(ctx context.Context, r *runtime.R logrus.Infof("RemoveContainer for %q returns successfully", r.GetContainerId()) } }() - return in.c.RemoveContainer(ctx, r) + return in.c.RemoveContainer(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (res *runtime.ExecSyncResponse, err error) { @@ -245,7 +246,7 @@ func (in *instrumentedService) ExecSync(ctx context.Context, r *runtime.ExecSync res.GetStdout(), res.GetStderr()) } }() - return in.c.ExecSync(ctx, r) + return in.c.ExecSync(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) Exec(ctx context.Context, r *runtime.ExecRequest) (res *runtime.ExecResponse, err error) { @@ -261,7 +262,7 @@ func (in *instrumentedService) Exec(ctx context.Context, r *runtime.ExecRequest) logrus.Infof("Exec for %q returns URL %q", r.GetContainerId(), res.GetUrl()) } }() - return in.c.Exec(ctx, r) + return in.c.Exec(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) Attach(ctx context.Context, r *runtime.AttachRequest) (res *runtime.AttachResponse, err error) { @@ -276,7 +277,7 @@ func (in *instrumentedService) Attach(ctx context.Context, r *runtime.AttachRequ logrus.Infof("Attach for %q returns URL %q", r.GetContainerId(), res.Url) } }() - return in.c.Attach(ctx, r) + return in.c.Attach(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (res *runtime.UpdateContainerResourcesResponse, err error) { @@ -291,7 +292,7 @@ func (in *instrumentedService) UpdateContainerResources(ctx context.Context, r * logrus.Infof("UpdateContainerResources for %q returns successfully", r.GetContainerId()) } }() - return in.c.UpdateContainerResources(ctx, r) + return in.c.UpdateContainerResources(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) PullImage(ctx context.Context, r *runtime.PullImageRequest) (res *runtime.PullImageResponse, err error) { @@ -307,7 +308,7 @@ func (in *instrumentedService) PullImage(ctx context.Context, r *runtime.PullIma r.GetImage().GetImage(), res.GetImageRef()) } }() - return in.c.PullImage(ctx, r) + return in.c.PullImage(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ListImages(ctx context.Context, r *runtime.ListImagesRequest) (res *runtime.ListImagesResponse, err error) { @@ -323,7 +324,7 @@ func (in *instrumentedService) ListImages(ctx context.Context, r *runtime.ListIm r.GetFilter(), res.GetImages()) } }() - return in.c.ListImages(ctx, r) + return in.c.ListImages(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ImageStatus(ctx context.Context, r *runtime.ImageStatusRequest) (res *runtime.ImageStatusResponse, err error) { @@ -339,7 +340,7 @@ func (in *instrumentedService) ImageStatus(ctx context.Context, r *runtime.Image r.GetImage().GetImage(), res.GetImage()) } }() - return in.c.ImageStatus(ctx, r) + return in.c.ImageStatus(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) RemoveImage(ctx context.Context, r *runtime.RemoveImageRequest) (_ *runtime.RemoveImageResponse, err error) { @@ -354,7 +355,7 @@ func (in *instrumentedService) RemoveImage(ctx context.Context, r *runtime.Remov logrus.Infof("RemoveImage %q returns successfully", r.GetImage().GetImage()) } }() - return in.c.RemoveImage(ctx, r) + return in.c.RemoveImage(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ImageFsInfo(ctx context.Context, r *runtime.ImageFsInfoRequest) (res *runtime.ImageFsInfoResponse, err error) { @@ -369,7 +370,7 @@ func (in *instrumentedService) ImageFsInfo(ctx context.Context, r *runtime.Image logrus.Debugf("ImageFsInfo returns filesystem info %+v", res.ImageFilesystems) } }() - return in.c.ImageFsInfo(ctx, r) + return in.c.ImageFsInfo(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ContainerStats(ctx context.Context, r *runtime.ContainerStatsRequest) (res *runtime.ContainerStatsResponse, err error) { @@ -384,7 +385,7 @@ func (in *instrumentedService) ContainerStats(ctx context.Context, r *runtime.Co logrus.Debugf("ContainerStats for %q returns stats %+v", r.GetContainerId(), res.GetStats()) } }() - return in.c.ContainerStats(ctx, r) + return in.c.ContainerStats(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ListContainerStats(ctx context.Context, r *runtime.ListContainerStatsRequest) (res *runtime.ListContainerStatsResponse, err error) { @@ -399,7 +400,7 @@ func (in *instrumentedService) ListContainerStats(ctx context.Context, r *runtim log.Tracef("ListContainerStats returns stats %+v", res.GetStats()) } }() - return in.c.ListContainerStats(ctx, r) + return in.c.ListContainerStats(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) Status(ctx context.Context, r *runtime.StatusRequest) (res *runtime.StatusResponse, err error) { @@ -414,7 +415,7 @@ func (in *instrumentedService) Status(ctx context.Context, r *runtime.StatusRequ log.Tracef("Status returns status %+v", res.GetStatus()) } }() - return in.c.Status(ctx, r) + return in.c.Status(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) Version(ctx context.Context, r *runtime.VersionRequest) (res *runtime.VersionResponse, err error) { @@ -429,7 +430,7 @@ func (in *instrumentedService) Version(ctx context.Context, r *runtime.VersionRe log.Tracef("Version returns %+v", res) } }() - return in.c.Version(ctx, r) + return in.c.Version(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (res *runtime.UpdateRuntimeConfigResponse, err error) { @@ -444,7 +445,7 @@ func (in *instrumentedService) UpdateRuntimeConfig(ctx context.Context, r *runti logrus.Debug("UpdateRuntimeConfig returns returns successfully") } }() - return in.c.UpdateRuntimeConfig(ctx, r) + return in.c.UpdateRuntimeConfig(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) LoadImage(ctx context.Context, r *api.LoadImageRequest) (res *api.LoadImageResponse, err error) { @@ -459,7 +460,7 @@ func (in *instrumentedService) LoadImage(ctx context.Context, r *api.LoadImageRe logrus.Debugf("LoadImage returns images %+v", res.GetImages()) } }() - return in.c.LoadImage(ctx, r) + return in.c.LoadImage(ctrdutil.WithNamespace(ctx), r) } func (in *instrumentedService) ReopenContainerLog(ctx context.Context, r *runtime.ReopenContainerLogRequest) (res *runtime.ReopenContainerLogResponse, err error) { @@ -474,5 +475,5 @@ func (in *instrumentedService) ReopenContainerLog(ctx context.Context, r *runtim logrus.Debugf("ReopenContainerLog for %q returns successfully", r.GetContainerId()) } }() - return in.c.ReopenContainerLog(ctx, r) + return in.c.ReopenContainerLog(ctrdutil.WithNamespace(ctx), r) } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/io/container_io.go b/vendor/github.com/containerd/cri/pkg/server/io/container_io.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/io/container_io.go rename to vendor/github.com/containerd/cri/pkg/server/io/container_io.go index 726071213..7edf627c6 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/io/container_io.go +++ b/vendor/github.com/containerd/cri/pkg/server/io/container_io.go @@ -25,8 +25,8 @@ import ( "github.com/containerd/containerd/cio" "github.com/sirupsen/logrus" - cioutil "github.com/containerd/cri-containerd/pkg/ioutil" - "github.com/containerd/cri-containerd/pkg/util" + cioutil "github.com/containerd/cri/pkg/ioutil" + "github.com/containerd/cri/pkg/util" ) // streamKey generates a key for the stream. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/io/exec_io.go b/vendor/github.com/containerd/cri/pkg/server/io/exec_io.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/io/exec_io.go rename to vendor/github.com/containerd/cri/pkg/server/io/exec_io.go index 2614ca4b3..3b2c36a90 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/io/exec_io.go +++ b/vendor/github.com/containerd/cri/pkg/server/io/exec_io.go @@ -23,7 +23,7 @@ import ( "github.com/containerd/containerd/cio" "github.com/sirupsen/logrus" - cioutil "github.com/containerd/cri-containerd/pkg/ioutil" + cioutil "github.com/containerd/cri/pkg/ioutil" ) // ExecIO holds the exec io. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/io/helpers.go b/vendor/github.com/containerd/cri/pkg/server/io/helpers.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/server/io/helpers.go rename to vendor/github.com/containerd/cri/pkg/server/io/helpers.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/io/logger.go b/vendor/github.com/containerd/cri/pkg/server/io/logger.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/io/logger.go rename to vendor/github.com/containerd/cri/pkg/server/io/logger.go index 6022f7294..b34cb008b 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/io/logger.go +++ b/vendor/github.com/containerd/cri/pkg/server/io/logger.go @@ -28,7 +28,7 @@ import ( "github.com/sirupsen/logrus" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - cioutil "github.com/containerd/cri-containerd/pkg/ioutil" + cioutil "github.com/containerd/cri/pkg/ioutil" ) const ( diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/restart.go b/vendor/github.com/containerd/cri/pkg/server/restart.go similarity index 96% rename from vendor/github.com/containerd/cri-containerd/pkg/server/restart.go rename to vendor/github.com/containerd/cri/pkg/server/restart.go index 158c4b178..433174142 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/restart.go +++ b/vendor/github.com/containerd/cri/pkg/server/restart.go @@ -35,14 +35,14 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - cio "github.com/containerd/cri-containerd/pkg/server/io" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" - imagestore "github.com/containerd/cri-containerd/pkg/store/image" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" + cio "github.com/containerd/cri/pkg/server/io" + containerstore "github.com/containerd/cri/pkg/store/container" + imagestore "github.com/containerd/cri/pkg/store/image" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" ) -// NOTE: The recovery logic has following assumption: when cri-containerd is down: -// 1) Files (e.g. root directory, netns) and checkpoint maintained by cri-containerd MUST NOT be +// NOTE: The recovery logic has following assumption: when the cri plugin is down: +// 1) Files (e.g. root directory, netns) and checkpoint maintained by the plugin MUST NOT be // touched. Or else, recovery logic for those containers/sandboxes may return error. // 2) Containerd containers may be deleted, but SHOULD NOT be added. Or else, recovery logic // for the newly added container/sandbox will return error, because there is no corresponding root @@ -194,7 +194,7 @@ func loadContainer(ctx context.Context, cntr containerd.Container, containerDir switch status.State() { case runtime.ContainerState_CONTAINER_CREATED: // NOTE: Another possibility is that we've tried to start the container, but - // cri-containerd got restarted just during that. In that case, we still + // containerd got restarted during that. In that case, we still // treat the container as `CREATED`. containerIO, err = cio.NewContainerIO(id, cio.WithNewFIFOs(containerDir, meta.Config.GetTty(), meta.Config.GetStdin()), @@ -215,7 +215,7 @@ func loadContainer(ctx context.Context, cntr containerd.Container, containerDir // Task status is found. Update container status based on the up-to-date task status. switch s.Status { case containerd.Created: - // Task has been created, but not started yet. This could only happen if cri-containerd + // Task has been created, but not started yet. This could only happen if containerd // gets restarted during container start. // Container must be in `CREATED` state. if _, err := t.Delete(ctx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) { @@ -226,13 +226,13 @@ func loadContainer(ctx context.Context, cntr containerd.Container, containerDir } case containerd.Running: // Task is running. Container must be in `RUNNING` state, based on our assuption that - // "task should not be started when cri-containerd is down". + // "task should not be started when containerd is down". switch status.State() { case runtime.ContainerState_CONTAINER_EXITED: return container, fmt.Errorf("unexpected container state for running task: %q", status.State()) case runtime.ContainerState_CONTAINER_RUNNING: default: - // This may happen if cri-containerd gets restarted after task is started, but + // This may happen if containerd gets restarted after task is started, but // before status is checkpointed. status.StartedAt = time.Now().UnixNano() status.Pid = t.Pid() diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_list.go b/vendor/github.com/containerd/cri/pkg/server/sandbox_list.go similarity index 97% rename from vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_list.go rename to vendor/github.com/containerd/cri/pkg/server/sandbox_list.go index 482b78b3e..f81888840 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_list.go +++ b/vendor/github.com/containerd/cri/pkg/server/sandbox_list.go @@ -20,7 +20,7 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" ) // ListPodSandbox returns a list of Sandbox. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_portforward.go b/vendor/github.com/containerd/cri/pkg/server/sandbox_portforward.go similarity index 95% rename from vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_portforward.go rename to vendor/github.com/containerd/cri/pkg/server/sandbox_portforward.go index 23ed9ecc0..a4ce03b2e 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_portforward.go +++ b/vendor/github.com/containerd/cri/pkg/server/sandbox_portforward.go @@ -28,7 +28,8 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" ) // PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address. @@ -53,7 +54,7 @@ func (c *criContainerdService) portForward(id string, port int32, stream io.Read if err != nil { return fmt.Errorf("failed to find sandbox %q in store: %v", id, err) } - t, err := s.Container.Task(context.Background(), nil) + t, err := s.Container.Task(ctrdutil.NamespacedContext(), nil) if err != nil { return fmt.Errorf("failed to get sandbox container task: %v", err) } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_remove.go b/vendor/github.com/containerd/cri/pkg/server/sandbox_remove.go similarity index 95% rename from vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_remove.go rename to vendor/github.com/containerd/cri/pkg/server/sandbox_remove.go index 73f914c98..fc630a7a4 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_remove.go +++ b/vendor/github.com/containerd/cri/pkg/server/sandbox_remove.go @@ -25,9 +25,9 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - "github.com/containerd/cri-containerd/pkg/log" - "github.com/containerd/cri-containerd/pkg/store" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" + "github.com/containerd/cri/pkg/log" + "github.com/containerd/cri/pkg/store" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" ) // RemovePodSandbox removes the sandbox. If there are running containers in the diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_run.go b/vendor/github.com/containerd/cri/pkg/server/sandbox_run.go similarity index 97% rename from vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_run.go rename to vendor/github.com/containerd/cri/pkg/server/sandbox_run.go index 7fe3af0d9..1f37a65b8 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_run.go +++ b/vendor/github.com/containerd/cri/pkg/server/sandbox_run.go @@ -35,17 +35,17 @@ import ( "golang.org/x/sys/unix" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - "github.com/containerd/cri-containerd/pkg/annotations" - customopts "github.com/containerd/cri-containerd/pkg/containerd/opts" - ctrdutil "github.com/containerd/cri-containerd/pkg/containerd/util" - "github.com/containerd/cri-containerd/pkg/log" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" - "github.com/containerd/cri-containerd/pkg/util" + "github.com/containerd/cri/pkg/annotations" + customopts "github.com/containerd/cri/pkg/containerd/opts" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + "github.com/containerd/cri/pkg/log" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" + "github.com/containerd/cri/pkg/util" ) func init() { typeurl.Register(&sandboxstore.Metadata{}, - "github.com/containerd/cri-containerd/pkg/store/sandbox", "Metadata") + "github.com/containerd/cri/pkg/store/sandbox", "Metadata") } // RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure @@ -140,7 +140,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run if err != nil { return nil, fmt.Errorf("failed to get network status for sandbox %q: %v", id, err) } - // Certain VM based solutions like clear containers (Issue containerd/cri-containerd#524) + // Certain VM based solutions like clear containers (Issue containerd/cri#524) // rely on the assumption that CRI shim will not be querying the network namespace to check the // network states such as IP. // In furture runtime implementation should avoid relying on CRI shim implementation details. @@ -258,7 +258,7 @@ func (c *criContainerdService) RunPodSandbox(ctx context.Context, r *runtime.Run // and before the end of this function. // * If `Update` succeeds, sandbox state will become READY in one transaction. // * If `Update` fails, sandbox will be removed from the store in the defer above. - // * If cri-containerd stops at any point before `Update` finishes, because sandbox + // * If containerd stops at any point before `Update` finishes, because sandbox // state is not checkpointed, it will be recovered from corresponding containerd task // status during restart: // * If the task is running, sandbox state will be READY, diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_status.go b/vendor/github.com/containerd/cri/pkg/server/sandbox_status.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_status.go rename to vendor/github.com/containerd/cri/pkg/server/sandbox_status.go index aba1b07e3..d726f1e21 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_status.go +++ b/vendor/github.com/containerd/cri/pkg/server/sandbox_status.go @@ -26,7 +26,7 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" ) // PodSandboxStatus returns the status of the PodSandbox. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_stop.go b/vendor/github.com/containerd/cri/pkg/server/sandbox_stop.go similarity index 96% rename from vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_stop.go rename to vendor/github.com/containerd/cri/pkg/server/sandbox_stop.go index fe169d0b6..0597ed844 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/sandbox_stop.go +++ b/vendor/github.com/containerd/cri/pkg/server/sandbox_stop.go @@ -28,7 +28,7 @@ import ( "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" ) // StopPodSandbox stops the sandbox. If there are any running containers in the @@ -75,7 +75,7 @@ func (c *criContainerdService) StopPodSandbox(ctx context.Context, r *runtime.St return nil, fmt.Errorf("failed to destroy network for sandbox %q: %v", id, teardownErr) } } - /*TODO:It is still possible that cri-containerd crashes after we teardown the network, but before we remove the network namespace. + /*TODO:It is still possible that containerd crashes after we teardown the network, but before we remove the network namespace. In that case, we'll not be able to remove the sandbox anymore. The chance is slim, but we should be aware of that. In the future, once TearDownPod is idempotent, this will be fixed.*/ diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/service.go b/vendor/github.com/containerd/cri/pkg/server/service.go similarity index 85% rename from vendor/github.com/containerd/cri-containerd/pkg/server/service.go rename to vendor/github.com/containerd/cri/pkg/server/service.go index f5930800e..ea1cb77a0 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/service.go +++ b/vendor/github.com/containerd/cri/pkg/server/service.go @@ -29,25 +29,22 @@ import ( runcseccomp "github.com/opencontainers/runc/libcontainer/seccomp" "github.com/opencontainers/selinux/go-selinux" "github.com/sirupsen/logrus" - "golang.org/x/net/context" "google.golang.org/grpc" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" "k8s.io/kubernetes/pkg/kubelet/server/streaming" - api "github.com/containerd/cri-containerd/pkg/api/v1" - "github.com/containerd/cri-containerd/pkg/atomic" - criconfig "github.com/containerd/cri-containerd/pkg/config" - osinterface "github.com/containerd/cri-containerd/pkg/os" - "github.com/containerd/cri-containerd/pkg/registrar" - containerstore "github.com/containerd/cri-containerd/pkg/store/container" - imagestore "github.com/containerd/cri-containerd/pkg/store/image" - sandboxstore "github.com/containerd/cri-containerd/pkg/store/sandbox" - snapshotstore "github.com/containerd/cri-containerd/pkg/store/snapshot" + api "github.com/containerd/cri/pkg/api/v1" + "github.com/containerd/cri/pkg/atomic" + criconfig "github.com/containerd/cri/pkg/config" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + osinterface "github.com/containerd/cri/pkg/os" + "github.com/containerd/cri/pkg/registrar" + containerstore "github.com/containerd/cri/pkg/store/container" + imagestore "github.com/containerd/cri/pkg/store/image" + sandboxstore "github.com/containerd/cri/pkg/store/sandbox" + snapshotstore "github.com/containerd/cri/pkg/store/snapshot" ) -// k8sContainerdNamespace is the namespace we use to connect containerd. -const k8sContainerdNamespace = "k8s.io" - // grpcServices are all the grpc services provided by cri containerd. type grpcServices interface { runtime.RuntimeServiceServer @@ -104,10 +101,11 @@ type criContainerdService struct { } // NewCRIContainerdService returns a new instance of CRIContainerdService -func NewCRIContainerdService(config criconfig.Config) (CRIContainerdService, error) { +func NewCRIContainerdService(config criconfig.Config, client *containerd.Client) (CRIContainerdService, error) { var err error c := &criContainerdService{ config: config, + client: client, apparmorEnabled: runcapparmor.IsEnabled(), seccompEnabled: runcseccomp.IsEnabled(), os: osinterface.RealOS{}, @@ -159,23 +157,11 @@ func (c *criContainerdService) Register(s *grpc.Server) error { // Run starts the cri-containerd service. func (c *criContainerdService) Run() error { - logrus.Info("Start cri-containerd service") - - // Connect containerd service here, to get rid of the containerd dependency - // in `NewCRIContainerdService`. This is required for plugin mode bootstrapping. - logrus.Info("Connect containerd service") - client, err := containerd.New(c.config.ContainerdEndpoint, containerd.WithDefaultNamespace(k8sContainerdNamespace)) - if err != nil { - return fmt.Errorf("failed to initialize containerd client with endpoint %q: %v", - c.config.ContainerdEndpoint, err) - } - c.client = client - logrus.Info("Start subscribing containerd event") c.eventMonitor.subscribe(c.client) logrus.Infof("Start recovering state") - if err := c.recover(context.Background()); err != nil { + if err := c.recover(ctrdutil.NamespacedContext()); err != nil { return fmt.Errorf("failed to recover state: %v", err) } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/snapshots.go b/vendor/github.com/containerd/cri/pkg/server/snapshots.go similarity index 91% rename from vendor/github.com/containerd/cri-containerd/pkg/server/snapshots.go rename to vendor/github.com/containerd/cri/pkg/server/snapshots.go index 846f1d75f..2861805f9 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/snapshots.go +++ b/vendor/github.com/containerd/cri/pkg/server/snapshots.go @@ -25,7 +25,8 @@ import ( snapshot "github.com/containerd/containerd/snapshots" "github.com/sirupsen/logrus" - snapshotstore "github.com/containerd/cri-containerd/pkg/store/snapshot" + ctrdutil "github.com/containerd/cri/pkg/containerd/util" + snapshotstore "github.com/containerd/cri/pkg/store/snapshot" ) // snapshotsSyncer syncs snapshot stats periodically. imagefs info and container stats @@ -68,13 +69,14 @@ func (s *snapshotsSyncer) start() { // sync updates all snapshots stats. func (s *snapshotsSyncer) sync() error { + ctx := ctrdutil.NamespacedContext() start := time.Now().UnixNano() var snapshots []snapshot.Info // Do not call `Usage` directly in collect function, because // `Usage` takes time, we don't want `Walk` to hold read lock // of snapshot metadata store for too long time. // TODO(random-liu): Set timeout for the following 2 contexts. - if err := s.snapshotter.Walk(context.Background(), func(ctx context.Context, info snapshot.Info) error { + if err := s.snapshotter.Walk(ctx, func(ctx context.Context, info snapshot.Info) error { snapshots = append(snapshots, info) return nil }); err != nil { @@ -96,7 +98,7 @@ func (s *snapshotsSyncer) sync() error { Kind: info.Kind, Timestamp: time.Now().UnixNano(), } - usage, err := s.snapshotter.Usage(context.Background(), info.Name) + usage, err := s.snapshotter.Usage(ctx, info.Name) if err != nil { if !errdefs.IsNotFound(err) { logrus.WithError(err).Errorf("Failed to get usage for snapshot %q", info.Name) diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/status.go b/vendor/github.com/containerd/cri/pkg/server/status.go similarity index 74% rename from vendor/github.com/containerd/cri-containerd/pkg/server/status.go rename to vendor/github.com/containerd/cri/pkg/server/status.go index 018c92b12..b52842a22 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/status.go +++ b/vendor/github.com/containerd/cri/pkg/server/status.go @@ -25,29 +25,17 @@ import ( runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" ) -const ( - // runtimeNotReadyReason is the reason reported when runtime is not ready. - runtimeNotReadyReason = "ContainerdNotReady" - // networkNotReadyReason is the reason reported when network is not ready. - networkNotReadyReason = "NetworkPluginNotReady" -) +// networkNotReadyReason is the reason reported when network is not ready. +const networkNotReadyReason = "NetworkPluginNotReady" // Status returns the status of the runtime. func (c *criContainerdService) Status(ctx context.Context, r *runtime.StatusRequest) (*runtime.StatusResponse, error) { + // As a containerd plugin, if CRI plugin is serving request, + // containerd must be ready. runtimeCondition := &runtime.RuntimeCondition{ Type: runtime.RuntimeReady, Status: true, } - serving, err := c.client.IsServing(ctx) - if err != nil || !serving { - runtimeCondition.Status = false - runtimeCondition.Reason = runtimeNotReadyReason - if err != nil { - runtimeCondition.Message = fmt.Sprintf("Containerd healthcheck returns error: %v", err) - } else { - runtimeCondition.Message = "Containerd grpc server is not serving" - } - } networkCondition := &runtime.RuntimeCondition{ Type: runtime.NetworkReady, Status: true, diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/streaming.go b/vendor/github.com/containerd/cri/pkg/server/streaming.go similarity index 92% rename from vendor/github.com/containerd/cri-containerd/pkg/server/streaming.go rename to vendor/github.com/containerd/cri/pkg/server/streaming.go index d089db848..4934798ac 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/streaming.go +++ b/vendor/github.com/containerd/cri/pkg/server/streaming.go @@ -22,12 +22,13 @@ import ( "math" "net" - "golang.org/x/net/context" k8snet "k8s.io/apimachinery/pkg/util/net" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/tools/remotecommand" "k8s.io/kubernetes/pkg/kubelet/server/streaming" "k8s.io/utils/exec" + + ctrdutil "github.com/containerd/cri/pkg/containerd/util" ) func newStreamServer(c *criContainerdService, addr, port string) (streaming.Server, error) { @@ -56,7 +57,7 @@ func newStreamRuntime(c *criContainerdService) streaming.Runtime { // returns non-zero exit code. func (s *streamRuntime) Exec(containerID string, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { - exitCode, err := s.c.execInContainer(context.Background(), containerID, execOptions{ + exitCode, err := s.c.execInContainer(ctrdutil.NamespacedContext(), containerID, execOptions{ cmd: cmd, stdin: stdin, stdout: stdout, @@ -78,7 +79,7 @@ func (s *streamRuntime) Exec(containerID string, cmd []string, stdin io.Reader, func (s *streamRuntime) Attach(containerID string, in io.Reader, out, err io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error { - return s.c.attachContainer(context.Background(), containerID, in, out, err, tty, resize) + return s.c.attachContainer(ctrdutil.NamespacedContext(), containerID, in, out, err, tty, resize) } func (s *streamRuntime) PortForward(podSandboxID string, port int32, stream io.ReadWriteCloser) error { diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/update_runtime_config.go b/vendor/github.com/containerd/cri/pkg/server/update_runtime_config.go similarity index 93% rename from vendor/github.com/containerd/cri-containerd/pkg/server/update_runtime_config.go rename to vendor/github.com/containerd/cri/pkg/server/update_runtime_config.go index 05002ac16..62a69dd37 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/update_runtime_config.go +++ b/vendor/github.com/containerd/cri/pkg/server/update_runtime_config.go @@ -23,7 +23,7 @@ import ( ) // UpdateRuntimeConfig updates the runtime config. Currently only handles podCIDR updates. -// TODO(random-liu): Figure out how to handle pod cidr in cri-containerd. +// TODO(random-liu): Figure out how to handle pod cidr in the cri plugin. func (c *criContainerdService) UpdateRuntimeConfig(ctx context.Context, r *runtime.UpdateRuntimeConfigRequest) (*runtime.UpdateRuntimeConfigResponse, error) { return &runtime.UpdateRuntimeConfigResponse{}, nil } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/server/version.go b/vendor/github.com/containerd/cri/pkg/server/version.go similarity index 77% rename from vendor/github.com/containerd/cri-containerd/pkg/server/version.go rename to vendor/github.com/containerd/cri/pkg/server/version.go index 365c522cc..acaad7863 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/server/version.go +++ b/vendor/github.com/containerd/cri/pkg/server/version.go @@ -17,10 +17,11 @@ limitations under the License. package server import ( - "fmt" - + "github.com/containerd/containerd/version" "golang.org/x/net/context" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" + + "github.com/containerd/cri/pkg/constants" ) const ( @@ -32,15 +33,10 @@ const ( // Version returns the runtime name, runtime version and runtime API version. func (c *criContainerdService) Version(ctx context.Context, r *runtime.VersionRequest) (*runtime.VersionResponse, error) { - resp, err := c.client.Version(ctx) - if err != nil { - return nil, fmt.Errorf("failed to get containerd version: %v", err) - } return &runtime.VersionResponse{ - Version: kubeAPIVersion, - RuntimeName: containerName, - RuntimeVersion: resp.Version, - // Containerd doesn't have an api version use version instead. - RuntimeApiVersion: resp.Version, + Version: kubeAPIVersion, + RuntimeName: containerName, + RuntimeVersion: version.Version, + RuntimeApiVersion: constants.CRIVersion, }, nil } diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/container/container.go b/vendor/github.com/containerd/cri/pkg/store/container/container.go similarity index 97% rename from vendor/github.com/containerd/cri-containerd/pkg/store/container/container.go rename to vendor/github.com/containerd/cri/pkg/store/container/container.go index 76cf41a7a..fb6cad133 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/store/container/container.go +++ b/vendor/github.com/containerd/cri/pkg/store/container/container.go @@ -23,8 +23,8 @@ import ( "github.com/docker/docker/pkg/truncindex" runtime "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2" - cio "github.com/containerd/cri-containerd/pkg/server/io" - "github.com/containerd/cri-containerd/pkg/store" + cio "github.com/containerd/cri/pkg/server/io" + "github.com/containerd/cri/pkg/store" ) // Container contains all resources associated with the container. All methods to diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/container/fake_status.go b/vendor/github.com/containerd/cri/pkg/store/container/fake_status.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/store/container/fake_status.go rename to vendor/github.com/containerd/cri/pkg/store/container/fake_status.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/container/metadata.go b/vendor/github.com/containerd/cri/pkg/store/container/metadata.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/store/container/metadata.go rename to vendor/github.com/containerd/cri/pkg/store/container/metadata.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/container/status.go b/vendor/github.com/containerd/cri/pkg/store/container/status.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/store/container/status.go rename to vendor/github.com/containerd/cri/pkg/store/container/status.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/errors.go b/vendor/github.com/containerd/cri/pkg/store/errors.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/store/errors.go rename to vendor/github.com/containerd/cri/pkg/store/errors.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/image/image.go b/vendor/github.com/containerd/cri/pkg/store/image/image.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/store/image/image.go rename to vendor/github.com/containerd/cri/pkg/store/image/image.go index 22fa2cb46..80a11c448 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/store/image/image.go +++ b/vendor/github.com/containerd/cri/pkg/store/image/image.go @@ -24,7 +24,7 @@ import ( godigest "github.com/opencontainers/go-digest" imagespec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/containerd/cri-containerd/pkg/store" + "github.com/containerd/cri/pkg/store" ) // Image contains all resources associated with the image. All fields diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/metadata.go b/vendor/github.com/containerd/cri/pkg/store/sandbox/metadata.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/metadata.go rename to vendor/github.com/containerd/cri/pkg/store/sandbox/metadata.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/netns.go b/vendor/github.com/containerd/cri/pkg/store/sandbox/netns.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/netns.go rename to vendor/github.com/containerd/cri/pkg/store/sandbox/netns.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/sandbox.go b/vendor/github.com/containerd/cri/pkg/store/sandbox/sandbox.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/sandbox.go rename to vendor/github.com/containerd/cri/pkg/store/sandbox/sandbox.go index f9c45ef08..4e4b6b8e2 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/sandbox.go +++ b/vendor/github.com/containerd/cri/pkg/store/sandbox/sandbox.go @@ -22,7 +22,7 @@ import ( "github.com/containerd/containerd" "github.com/docker/docker/pkg/truncindex" - "github.com/containerd/cri-containerd/pkg/store" + "github.com/containerd/cri/pkg/store" ) // Sandbox contains all resources associated with the sandbox. All methods to diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/status.go b/vendor/github.com/containerd/cri/pkg/store/sandbox/status.go similarity index 98% rename from vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/status.go rename to vendor/github.com/containerd/cri/pkg/store/sandbox/status.go index 20df9749a..6dedb8ae3 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/store/sandbox/status.go +++ b/vendor/github.com/containerd/cri/pkg/store/sandbox/status.go @@ -21,7 +21,7 @@ import ( "time" ) -// State is the sandbox state we use in cri-containerd. +// State is the sandbox state we use in containerd/cri. // It has unknown state defined. type State uint32 diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/snapshot/snapshot.go b/vendor/github.com/containerd/cri/pkg/store/snapshot/snapshot.go similarity index 97% rename from vendor/github.com/containerd/cri-containerd/pkg/store/snapshot/snapshot.go rename to vendor/github.com/containerd/cri/pkg/store/snapshot/snapshot.go index a1cd96f37..1a01570e7 100644 --- a/vendor/github.com/containerd/cri-containerd/pkg/store/snapshot/snapshot.go +++ b/vendor/github.com/containerd/cri/pkg/store/snapshot/snapshot.go @@ -21,7 +21,7 @@ import ( snapshot "github.com/containerd/containerd/snapshots" - "github.com/containerd/cri-containerd/pkg/store" + "github.com/containerd/cri/pkg/store" ) // Snapshot contains the information about the snapshot. diff --git a/vendor/github.com/containerd/cri-containerd/pkg/store/util.go b/vendor/github.com/containerd/cri/pkg/store/util.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/store/util.go rename to vendor/github.com/containerd/cri/pkg/store/util.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/util/deep_copy.go b/vendor/github.com/containerd/cri/pkg/util/deep_copy.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/util/deep_copy.go rename to vendor/github.com/containerd/cri/pkg/util/deep_copy.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/util/id.go b/vendor/github.com/containerd/cri/pkg/util/id.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/util/id.go rename to vendor/github.com/containerd/cri/pkg/util/id.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/util/image.go b/vendor/github.com/containerd/cri/pkg/util/image.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/util/image.go rename to vendor/github.com/containerd/cri/pkg/util/image.go diff --git a/vendor/github.com/containerd/cri-containerd/pkg/util/strings.go b/vendor/github.com/containerd/cri/pkg/util/strings.go similarity index 100% rename from vendor/github.com/containerd/cri-containerd/pkg/util/strings.go rename to vendor/github.com/containerd/cri/pkg/util/strings.go diff --git a/vendor/github.com/containerd/cri-containerd/vendor.conf b/vendor/github.com/containerd/cri/vendor.conf similarity index 96% rename from vendor/github.com/containerd/cri-containerd/vendor.conf rename to vendor/github.com/containerd/cri/vendor.conf index 71fe38da7..73d63e523 100644 --- a/vendor/github.com/containerd/cri-containerd/vendor.conf +++ b/vendor/github.com/containerd/cri/vendor.conf @@ -2,9 +2,9 @@ github.com/beorn7/perks 4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9 github.com/blang/semver v3.1.0 github.com/boltdb/bolt e9cf4fae01b5a8ff89d0ec6b32f0d9c9f79aefdd github.com/BurntSushi/toml a368813c5e648fee92e5f6c30e3944ff9d5e8895 -github.com/containerd/cgroups c0710c92e8b3a44681d1321dcfd1360fc5c6c089 +github.com/containerd/cgroups fe281dd265766145e943a034aa41086474ea6130 github.com/containerd/console 84eeaae905fa414d03e07bcd6c8d3f19e7cf180e -github.com/containerd/containerd 25c403415aa99d0f3a609043429f3d24c8b70c0c +github.com/containerd/containerd 3013762fc58941e33ba70e8f8d9256911f134124 github.com/containerd/continuity d8fb8589b0e8e85b8c8bbaa8840226d0dfeb7371 github.com/containerd/fifo fbfb6a11ec671efbe94ad1c12c2e98773f19e1e6 github.com/containerd/go-runc 4f6e87ae043f859a38255247b49c9abc262d002f @@ -14,7 +14,6 @@ github.com/containernetworking/plugins v0.6.0 github.com/coreos/go-systemd 48702e0da86bd25e76cfef347e2adeb434a0d0a6 github.com/cri-o/ocicni 9b451e26eb7c694d564991fbf44f77d0afb9b03c github.com/davecgh/go-spew v1.1.0 -github.com/dmcgowan/go-tar go1.10 github.com/docker/distribution b38e5838b7b2f2ad48e06ec4b500011976080621 github.com/docker/docker 86f080cff0914e9694068ed78d503701667c4c00 github.com/docker/go-events 9461782956ad83b30282bf90e31fa6a70c255ba9 diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/doc.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/doc.go new file mode 100644 index 000000000..ac0d4097b --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2015 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. +*/ + +// Utility functions. +package util // import "k8s.io/kubernetes/pkg/kubelet/util" diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/util.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/util.go new file mode 100644 index 000000000..eb7cf1427 --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/util.go @@ -0,0 +1,47 @@ +/* +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 util + +import ( + "fmt" + "net/url" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// FromApiserverCache modifies so that the GET request will +// be served from apiserver cache instead of from etcd. +func FromApiserverCache(opts *metav1.GetOptions) { + opts.ResourceVersion = "0" +} + +func parseEndpoint(endpoint string) (string, string, error) { + u, err := url.Parse(endpoint) + if err != nil { + return "", "", err + } + + if u.Scheme == "tcp" { + return "tcp", u.Host, nil + } else if u.Scheme == "unix" { + return "unix", u.Path, nil + } else if u.Scheme == "" { + return "", "", fmt.Errorf("Using %q as endpoint is deprecated, please consider using full url format", endpoint) + } else { + return u.Scheme, "", fmt.Errorf("protocol %q not supported", u.Scheme) + } +} diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unix.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unix.go new file mode 100644 index 000000000..0b8fea9c8 --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unix.go @@ -0,0 +1,79 @@ +// +build freebsd linux darwin + +/* +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 util + +import ( + "fmt" + "net" + "os" + "time" + + "github.com/golang/glog" + "golang.org/x/sys/unix" +) + +const ( + // unixProtocol is the network protocol of unix socket. + unixProtocol = "unix" +) + +func CreateListener(endpoint string) (net.Listener, error) { + protocol, addr, err := parseEndpointWithFallbackProtocol(endpoint, unixProtocol) + if err != nil { + return nil, err + } + if protocol != unixProtocol { + return nil, fmt.Errorf("only support unix socket endpoint") + } + + // Unlink to cleanup the previous socket file. + err = unix.Unlink(addr) + if err != nil && !os.IsNotExist(err) { + return nil, fmt.Errorf("failed to unlink socket file %q: %v", addr, err) + } + + return net.Listen(protocol, addr) +} + +func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) { + protocol, addr, err := parseEndpointWithFallbackProtocol(endpoint, unixProtocol) + if err != nil { + return "", nil, err + } + if protocol != unixProtocol { + return "", nil, fmt.Errorf("only support unix socket endpoint") + } + + return addr, dial, nil +} + +func dial(addr string, timeout time.Duration) (net.Conn, error) { + return net.DialTimeout(unixProtocol, addr, timeout) +} + +func parseEndpointWithFallbackProtocol(endpoint string, fallbackProtocol string) (protocol string, addr string, err error) { + if protocol, addr, err = parseEndpoint(endpoint); err != nil && protocol == "" { + fallbackEndpoint := fallbackProtocol + "://" + endpoint + protocol, addr, err = parseEndpoint(fallbackEndpoint) + if err == nil { + glog.Warningf("Using %q as endpoint is deprecated, please consider using full url format %q.", endpoint, fallbackEndpoint) + } + } + return +} diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unsupported.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unsupported.go new file mode 100644 index 000000000..5fd2e9c68 --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_unsupported.go @@ -0,0 +1,33 @@ +// +build !freebsd,!linux,!windows,!darwin + +/* +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 util + +import ( + "fmt" + "net" + "time" +) + +func CreateListener(endpoint string) (net.Listener, error) { + return nil, fmt.Errorf("CreateListener is unsupported in this build") +} + +func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) { + return "", nil, fmt.Errorf("GetAddressAndDialer is unsupported in this build") +} diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_windows.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_windows.go new file mode 100644 index 000000000..108f4eb91 --- /dev/null +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/util_windows.go @@ -0,0 +1,57 @@ +// +build windows + +/* +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 util + +import ( + "fmt" + "net" + "time" +) + +const ( + tcpProtocol = "tcp" +) + +func CreateListener(endpoint string) (net.Listener, error) { + protocol, addr, err := parseEndpoint(endpoint) + if err != nil { + return nil, err + } + if protocol != tcpProtocol { + return nil, fmt.Errorf("only support tcp endpoint") + } + + return net.Listen(protocol, addr) +} + +func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) { + protocol, addr, err := parseEndpoint(endpoint) + if err != nil { + return "", nil, err + } + if protocol != tcpProtocol { + return "", nil, fmt.Errorf("only support tcp endpoint") + } + + return addr, dial, nil +} + +func dial(addr string, timeout time.Duration) (net.Conn, error) { + return net.DialTimeout(tcpProtocol, addr, timeout) +}