Skip to content

Commit

Permalink
Merge pull request #9648 from Icinga/frozen-namespace-config-validation
Browse files Browse the repository at this point in the history
Fix config sync after freezing namespaces
  • Loading branch information
Al2Klimov committed Feb 1, 2023
2 parents 0bd972f + fd1aa73 commit 4e021e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
9 changes: 7 additions & 2 deletions icinga-app/icinga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,13 @@ static int Main()
std::unique_ptr<SetExpression> setExpr{new SetExpression(std::move(expr), OpSetLiteral, MakeLiteral(value))};
setExpr->SetOverrideFrozen();

ScriptFrame frame(true);
setExpr->Evaluate(frame);
try {
ScriptFrame frame(true);
setExpr->Evaluate(frame);
} catch (const ScriptError& e) {
Log(LogCritical, "icinga-app") << "cannot set '" << key << "': " << e.what();
return EXIT_FAILURE;
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions lib/base/scriptframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace icinga;

boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFrames;

static Namespace::Ptr l_SystemNS, l_StatsNS, l_InternalNS;
static Namespace::Ptr l_SystemNS, l_StatsNS;

/* Ensure that this gets called with highest priority
* and wins against other static initializers in lib/icinga, etc.
Expand All @@ -36,14 +36,12 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
l_StatsNS = new Namespace(true);
globalNS->Set("StatsFunctions", l_StatsNS, true);

l_InternalNS = new Namespace(true);
globalNS->Set("Internal", l_InternalNS, true);
globalNS->Set("Internal", new Namespace(true), true);
}, InitializePriority::CreateNamespaces);

INITIALIZE_ONCE_WITH_PRIORITY([]() {
l_SystemNS->Freeze();
l_StatsNS->Freeze();
l_InternalNS->Freeze();
}, InitializePriority::FreezeNamespaces);

ScriptFrame::ScriptFrame(bool allocLocals)
Expand Down
9 changes: 6 additions & 3 deletions lib/cli/daemonutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
VERIFY(systemNS);

Namespace::Ptr internalNS = ScriptGlobal::Get("Internal");
VERIFY(internalNS);

if (!objectsFile.IsEmpty())
ConfigCompilerContext::GetInstance()->OpenObjectsFile(objectsFile);

Expand All @@ -134,7 +137,7 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
success = true;

/* Only load zone directory if we're not in staging validation. */
if (!systemNS->Contains("ZonesStageVarDir")) {
if (!internalNS->Contains("ZonesStageVarDir")) {
String zonesEtcDir = Configuration::ZonesDir;
if (!zonesEtcDir.IsEmpty() && Utility::PathExists(zonesEtcDir)) {
std::set<String> zoneEtcDirs;
Expand Down Expand Up @@ -177,8 +180,8 @@ bool DaemonUtility::ValidateConfigFiles(const std::vector<std::string>& configs,
String zonesVarDir = Configuration::DataDir + "/api/zones";

/* Cluster config sync stage validation needs this. */
if (systemNS->Contains("ZonesStageVarDir")) {
zonesVarDir = systemNS->Get("ZonesStageVarDir");
if (internalNS->Contains("ZonesStageVarDir")) {
zonesVarDir = internalNS->Get("ZonesStageVarDir");

Log(LogNotice, "DaemonUtility")
<< "Overriding zones var directory with '" << zonesVarDir << "' for cluster config sync staging.";
Expand Down
4 changes: 2 additions & 2 deletions lib/remote/apilistener-filesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void ApiListener::HandleConfigUpdate(const MessageOrigin::Ptr& origin, const Dic
}

/**
* Spawns a new validation process with 'System.ZonesStageVarDir' set to override the config validation zone dirs with
* Spawns a new validation process with 'Internal.ZonesStageVarDir' set to override the config validation zone dirs with
* our current stage. Then waits for the validation result and if it was successful, the configuration is copied from
* stage to production and a restart is triggered. On validation failure, there is no restart and this is logged.
*
Expand Down Expand Up @@ -584,7 +584,7 @@ void ApiListener::TryActivateZonesStage(const std::vector<String>& relativePaths

// Set the ZonesStageDir. This creates our own local chroot without any additional automated zone includes.
args->Add("--define");
args->Add("System.ZonesStageVarDir=" + GetApiZonesStageDir());
args->Add("Internal.ZonesStageVarDir=" + GetApiZonesStageDir());

Process::Ptr process = new Process(Process::PrepareCommand(args));
process->SetTimeout(Application::GetReloadTimeout());
Expand Down

0 comments on commit 4e021e0

Please sign in to comment.