Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ProcessContainers] Have default container provider #1769

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/com/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ namespace RPC {

ContainerConfig()
: Core::JSON::Container()
, ContainerType(ProcessContainers::IContainer::LXC)
, ContainerType(ProcessContainers::IContainer::DEFAULT)
#ifdef __DEBUG__
, ContainerPath()
#endif
Expand Down
67 changes: 54 additions & 13 deletions Source/extensions/processcontainers/ContainerAdministrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,50 @@ namespace ProcessContainers {
container.Add(value.Data(), &specific);
container.FromString(configuration);

if ((specific.IsSet() == false) && (_producers.size() == 1)) {
// Looks like the configuration for this provider is not specified, however there is only one container
// system available, so let's forward the entire config (perhaps it's a legacy config file).
specific = configuration;
}

TRACE(Trace::Information, (_T("Initializing container runtime system '%s'..."), value.Data()));

// Pass the configuration to the runtime
const uint32_t initResult = runtime.second->Initialize(specific);
const uint32_t initResult = runtime.second->Initialize(specific.Value());

if (initResult != Core::ERROR_NONE) {
TRACE(Trace::Error, (_T("Initialization failure")));
result = Core::ERROR_GENERAL;
}
}

if (_producers.empty() == true) {
SYSLOG(Logging::Error, (_T("No container runtime systems are available!")));
}
else if (_producers.size() == 1) {
// Since there is only one provider available, make it the default one
_default = _producers.cbegin()->first;
}
else {
Core::JSON::EnumType<IContainer::containertype> defaultProducer;
Core::JSON::Container config;
config.Add(_T("default"), &defaultProducer);
config.FromString(configuration);

if (defaultProducer.IsSet() == true) {
_default = defaultProducer.Value();
ASSERT(_default != IContainer::DEFAULT);
ASSERT(_producers.find(_default) != _producers.end());

const Core::EnumerateType<IContainer::containertype> value(_default);
DEBUG_VARIABLE(value);
TRACE(Trace::Information, (_T("Default container runtime is '%s'"), value.Data()));
}
else {
TRACE(Trace::Information, (_T("Default container runtime is not set")));
}
}

_adminLock.Unlock();

return (result);
Expand All @@ -86,27 +119,35 @@ namespace ProcessContainers {

_adminLock.Lock();

auto it = _producers.find(type);
const IContainer::containertype containerType = (type == IContainer::DEFAULT? _default : type);

if (containerType != IContainer::DEFAULT) {

const Core::EnumerateType<IContainer::containertype> value(type);
DEBUG_VARIABLE(value);
auto it = _producers.find(containerType);

ASSERT(value.IsSet() == true);
const Core::EnumerateType<IContainer::containertype> value(containerType);
DEBUG_VARIABLE(value);

if (it != _producers.end()) {
ASSERT(value.IsSet() == true);

if (it != _producers.end()) {

auto& runtime = (*it).second;
ASSERT(runtime != nullptr);
auto& runtime = (*it).second;
ASSERT(runtime != nullptr);

container = runtime->Container(id, searchPaths, logPath, configuration);
container = runtime->Container(id, searchPaths, logPath, configuration);

if (container.IsValid() == true) {
TRACE(Trace::Information, (_T("Container '%s' created successfully (runtime system '%s')"),
container->Id().c_str(), value.Data()));
if (container.IsValid() == true) {
TRACE(Trace::Information, (_T("Container '%s' created successfully (runtime system '%s')"),
container->Id().c_str(), value.Data()));
}
}
else {
TRACE(Trace::Error, (_T("Container runtime system '%s' is not enabled!"), value.Data()));
}
}
else {
TRACE(Trace::Error, (_T("Container runtime system '%s' is not enabled!"), value.Data()));
TRACE(Trace::Error, (_T("Container runtime system not specified for '%s'"), id.c_str()));
}

_adminLock.Unlock();
Expand Down
4 changes: 4 additions & 0 deletions Source/extensions/processcontainers/ContainerAdministrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace ProcessContainers {

ContainerAdministrator()
: _adminLock()
, _producers()
, _containers()
, _default(IContainer::DEFAULT)
{
}

Expand Down Expand Up @@ -107,6 +110,7 @@ namespace ProcessContainers {
mutable Core::CriticalSection _adminLock;
std::map<IContainer::containertype, IContainerProducer*> _producers;
Core::ProxyListType<IContainer> _containers;
IContainer::containertype _default;
};

} // namespace ProcessContainers
Expand Down
1 change: 1 addition & 0 deletions Source/extensions/processcontainers/IProcessContainers.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace ProcessContainers {
struct IContainer {

enum containertype : uint8_t {
DEFAULT,
LXC,
RUNC,
CRUN,
Expand Down
Loading