| 2971 | |
| 2972 | |
| 2973 | void MesosContainerizerProcess::______destroy( |
| 2974 | const ContainerID& containerId, |
| 2975 | const Option<ContainerTermination>& _termination, |
| 2976 | const Future<bool>& destroy) |
| 2977 | { |
| 2978 | CHECK(containers_.contains(containerId)); |
| 2979 | |
| 2980 | const Owned<Container>& container = containers_.at(containerId); |
| 2981 | |
| 2982 | if (!destroy.isReady()) { |
| 2983 | container->termination.fail( |
| 2984 | "Failed to destroy the provisioned rootfs when destroying container: " + |
| 2985 | (destroy.isFailed() ? destroy.failure() : "discarded future")); |
| 2986 | |
| 2987 | ++metrics.container_destroy_errors; |
| 2988 | return; |
| 2989 | } |
| 2990 | |
| 2991 | ContainerTermination termination; |
| 2992 | |
| 2993 | if (_termination.isSome()) { |
| 2994 | termination = _termination.get(); |
| 2995 | } |
| 2996 | |
| 2997 | if (container->status.isSome() && |
| 2998 | container->status->isReady() && |
| 2999 | container->status->get().isSome()) { |
| 3000 | termination.set_status(container->status->get().get()); |
| 3001 | } |
| 3002 | |
| 3003 | // Now that we are done destroying the container we need to cleanup |
| 3004 | // its runtime directory. There are two cases to consider: |
| 3005 | // |
| 3006 | // (1) We are a nested container: |
| 3007 | // * In this case we should defer deletion of the runtime directory |
| 3008 | // until the top-level container is destroyed. Instead, we |
| 3009 | // checkpoint a file with the termination state indicating that |
| 3010 | // the container has already been destroyed. This allows |
| 3011 | // subsequent calls to `wait()` to succeed with the proper |
| 3012 | // termination state until the top-level container is destroyed. |
| 3013 | // It also prevents subsequent `destroy()` calls from attempting |
| 3014 | // to cleanup the container a second time. |
| 3015 | // * We also schedule the nested container's sandbox directory for |
| 3016 | // garbage collection, if this behavior is enabled. |
| 3017 | // |
| 3018 | // (2) We are a top-level container: |
| 3019 | // We should simply remove the runtime directory. Since we build |
| 3020 | // the runtime directories of nested containers hierarchically, |
| 3021 | // removing the top-level runtime directory will automatically |
| 3022 | // cleanup all nested container runtime directories as well. |
| 3023 | // |
| 3024 | // NOTE: The runtime directory will not exist for legacy containers, |
| 3025 | // so we need to make sure it actually exists before attempting to |
| 3026 | // remove it. |
| 3027 | const string runtimePath = |
| 3028 | containerizer::paths::getRuntimePath(flags.runtime_dir, containerId); |
| 3029 | |
| 3030 | if (containerId.has_parent()) { |
nothing calls this directly
no test coverage detected