This is an automated email from the ASF dual-hosted git repository. qianzhang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit a3e8fd89b1a34cf479c454e9991712cd2999affe Author: Qian Zhang <zhq527...@gmail.com> AuthorDate: Thu Jul 16 22:13:18 2020 +0800 Implemented the framework and `create` method of `volume/csi` isolator. Review: https://reviews.apache.org/r/72690 --- src/CMakeLists.txt | 2 + src/Makefile.am | 4 + .../mesos/isolators/volume/csi/isolator.cpp | 114 +++++++++++++++++++++ .../mesos/isolators/volume/csi/isolator.hpp | 86 ++++++++++++++++ .../mesos/isolators/volume/csi/paths.cpp | 47 +++++++++ .../mesos/isolators/volume/csi/paths.hpp | 57 +++++++++++ 6 files changed, 310 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c60d98a..f3abdbf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -196,6 +196,7 @@ if (NOT WIN32) slave/containerizer/mesos/isolators/posix/disk.cpp slave/containerizer/mesos/isolators/posix/rlimits.cpp slave/containerizer/mesos/isolators/volume/sandbox_path.cpp + slave/containerizer/mesos/isolators/volume/csi/paths.cpp slave/containerizer/mesos/provisioner/appc/cache.cpp slave/containerizer/mesos/provisioner/appc/fetcher.cpp slave/containerizer/mesos/provisioner/appc/paths.cpp @@ -336,6 +337,7 @@ set(LINUX_SRC slave/containerizer/mesos/isolators/volume/image.cpp slave/containerizer/mesos/isolators/volume/secret.cpp slave/containerizer/mesos/isolators/volume/utils.cpp + slave/containerizer/mesos/isolators/volume/csi/isolator.cpp slave/containerizer/mesos/provisioner/backends/aufs.cpp slave/containerizer/mesos/provisioner/backends/bind.cpp slave/containerizer/mesos/provisioner/backends/overlay.cpp) diff --git a/src/Makefile.am b/src/Makefile.am index 49dab4b..70e844d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1251,6 +1251,8 @@ libmesos_no_3rdparty_la_SOURCES += \ slave/containerizer/mesos/isolators/posix/rlimits.hpp \ slave/containerizer/mesos/isolators/volume/sandbox_path.cpp \ slave/containerizer/mesos/isolators/volume/sandbox_path.hpp \ + slave/containerizer/mesos/isolators/volume/csi/paths.cpp \ + slave/containerizer/mesos/isolators/volume/csi/paths.hpp \ slave/containerizer/mesos/isolators/windows/cpu.hpp \ slave/containerizer/mesos/isolators/windows/mem.hpp \ slave/containerizer/mesos/launch.cpp \ @@ -1454,6 +1456,8 @@ MESOS_LINUX_FILES = \ slave/containerizer/mesos/isolators/volume/secret.hpp \ slave/containerizer/mesos/isolators/volume/utils.cpp \ slave/containerizer/mesos/isolators/volume/utils.hpp \ + slave/containerizer/mesos/isolators/volume/csi/isolator.cpp \ + slave/containerizer/mesos/isolators/volume/csi/isolator.hpp \ slave/containerizer/mesos/provisioner/backends/aufs.cpp \ slave/containerizer/mesos/provisioner/backends/aufs.hpp \ slave/containerizer/mesos/provisioner/backends/bind.cpp \ diff --git a/src/slave/containerizer/mesos/isolators/volume/csi/isolator.cpp b/src/slave/containerizer/mesos/isolators/volume/csi/isolator.cpp new file mode 100644 index 0000000..7ec3a4e --- /dev/null +++ b/src/slave/containerizer/mesos/isolators/volume/csi/isolator.cpp @@ -0,0 +1,114 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#include <string> +#include <vector> + +#include <process/future.hpp> +#include <process/owned.hpp> + +#include <stout/os.hpp> + +#include <stout/os/realpath.hpp> + +#include "slave/containerizer/mesos/isolators/volume/csi/isolator.hpp" +#include "slave/containerizer/mesos/isolators/volume/csi/paths.hpp" + +using std::string; +using std::vector; + +using process::Future; +using process::Owned; + +using mesos::slave::ContainerConfig; +using mesos::slave::ContainerLaunchInfo; +using mesos::slave::ContainerState; +using mesos::slave::Isolator; + +namespace mesos { +namespace internal { +namespace slave { + +Try<Isolator*> VolumeCSIIsolatorProcess::create( + const Flags& flags, + CSIServer* csiServer) +{ + if (!strings::contains(flags.isolation, "filesystem/linux")) { + return Error("'filesystem/linux' isolator must be used"); + } + + if (csiServer == nullptr) { + return Error("No CSI server is provided"); + } + + const string csiRootDir = path::join(flags.runtime_dir, csi::paths::CSI_DIR); + + // Create the CSI volume information root directory if it does not exist. + Try<Nothing> mkdir = os::mkdir(csiRootDir); + if (mkdir.isError()) { + return Error( + "Failed to create CSI volume information root directory at '" + + csiRootDir + "': " + mkdir.error()); + } + + Result<string> rootDir = os::realpath(csiRootDir); + if (!rootDir.isSome()) { + return Error( + "Failed to determine canonical path of CSI volume information root" + " directory '" + csiRootDir + "': " + + (rootDir.isError() ? rootDir.error() : "No such file or directory")); + } + + Owned<MesosIsolatorProcess> process(new VolumeCSIIsolatorProcess( + flags, + csiServer, + rootDir.get())); + + return new MesosIsolator(process); +} + + +bool VolumeCSIIsolatorProcess::supportsNesting() +{ + return true; +} + + +Future<Nothing> VolumeCSIIsolatorProcess::recover( + const vector<ContainerState>& states, + const hashset<ContainerID>& orphans) +{ + return Nothing(); +} + + +Future<Option<ContainerLaunchInfo>> VolumeCSIIsolatorProcess::prepare( + const ContainerID& containerId, + const ContainerConfig& containerConfig) +{ + return None(); +} + + +Future<Nothing> VolumeCSIIsolatorProcess::cleanup( + const ContainerID& containerId) +{ + return Nothing(); +} + +} // namespace slave { +} // namespace internal { +} // namespace mesos { diff --git a/src/slave/containerizer/mesos/isolators/volume/csi/isolator.hpp b/src/slave/containerizer/mesos/isolators/volume/csi/isolator.hpp new file mode 100644 index 0000000..f943766 --- /dev/null +++ b/src/slave/containerizer/mesos/isolators/volume/csi/isolator.hpp @@ -0,0 +1,86 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#ifndef __VOLUME_CSI_ISOLATOR_HPP__ +#define __VOLUME_CSI_ISOLATOR_HPP__ + +#include <string> +#include <vector> + +#include <mesos/mesos.hpp> + +#include <process/future.hpp> +#include <process/id.hpp> +#include <process/process.hpp> + +#include <stout/hashset.hpp> +#include <stout/nothing.hpp> +#include <stout/option.hpp> +#include <stout/try.hpp> + +#include "slave/csi_server.hpp" +#include "slave/flags.hpp" + +#include "slave/containerizer/mesos/isolator.hpp" + +namespace mesos { +namespace internal { +namespace slave { + +class VolumeCSIIsolatorProcess : public MesosIsolatorProcess +{ +public: + static Try<mesos::slave::Isolator*> create( + const Flags& flags, + CSIServer* csiServer); + + ~VolumeCSIIsolatorProcess() override {}; + + bool supportsNesting() override; + + process::Future<Nothing> recover( + const std::vector<mesos::slave::ContainerState>& states, + const hashset<ContainerID>& orphans) override; + + process::Future<Option<mesos::slave::ContainerLaunchInfo>> prepare( + const ContainerID& containerId, + const mesos::slave::ContainerConfig& containerConfig) override; + + process::Future<Nothing> cleanup( + const ContainerID& containerId) override; + +private: + VolumeCSIIsolatorProcess( + const Flags& _flags, + CSIServer* _csiServer, + const std::string& _rootDir) + : ProcessBase(process::ID::generate("volume-csi-isolator")), + flags(_flags), + csiServer(_csiServer), + rootDir(_rootDir) {} + + const Flags flags; + CSIServer* csiServer; + + // CSI volume information root directory. + const std::string rootDir; +}; + +} // namespace slave { +} // namespace internal { +} // namespace mesos { + +#endif // __VOLUME_CSI_ISOLATOR_HPP__ diff --git a/src/slave/containerizer/mesos/isolators/volume/csi/paths.cpp b/src/slave/containerizer/mesos/isolators/volume/csi/paths.cpp new file mode 100644 index 0000000..4fdbc29 --- /dev/null +++ b/src/slave/containerizer/mesos/isolators/volume/csi/paths.cpp @@ -0,0 +1,47 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#include <mesos/type_utils.hpp> + +#include <stout/path.hpp> +#include <stout/stringify.hpp> + +#include "slave/containerizer/mesos/isolators/volume/csi/paths.hpp" + +using std::string; + +namespace mesos { +namespace internal { +namespace slave { +namespace csi { +namespace paths { + +string getContainerDir(const string& rootDir, const ContainerID& containerId) +{ + return path::join(rootDir, stringify(containerId)); +} + + +string getVolumesPath(const string& rootDir, const ContainerID& containerId) +{ + return path::join(getContainerDir(rootDir, containerId), "volumes"); +} + +} // namespace paths { +} // namespace csi { +} // namespace slave { +} // namespace internal { +} // namespace mesos { diff --git a/src/slave/containerizer/mesos/isolators/volume/csi/paths.hpp b/src/slave/containerizer/mesos/isolators/volume/csi/paths.hpp new file mode 100644 index 0000000..5b4a4ee --- /dev/null +++ b/src/slave/containerizer/mesos/isolators/volume/csi/paths.hpp @@ -0,0 +1,57 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#ifndef __VOLUME_CSI_ISOLATOR_PATHS_HPP__ +#define __VOLUME_CSI_ISOLATOR_PATHS_HPP__ + +#include <string> + +#include <mesos/mesos.hpp> + +namespace mesos { +namespace internal { +namespace slave { +namespace csi { +namespace paths { + +// The root directory where we keep the information of CSI volumes that each +// container uses. The layout is as follows: +// /<runtime_dir>/isolators/volume/csi/ +// |-- <ID of Container1>/ +// | |-- volumes +// |-- <ID of Container2>/ +// | |-- volumes +// |-- <ID of Container3>/ +// |-- ... +constexpr char CSI_DIR[] = "isolators/volume/csi"; + + +std::string getContainerDir( + const std::string& rootDir, + const ContainerID& containerId); + + +std::string getVolumesPath( + const std::string& rootDir, + const ContainerID& containerId); + +} // namespace paths { +} // namespace csi { +} // namespace slave { +} // namespace internal { +} // namespace mesos { + +#endif // __VOLUME_CSI_ISOLATOR_PATHS_HPP__