Skip to content

Commit b485354

Browse files
committed
restruture on host folder and names
1 parent 5a71a04 commit b485354

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+826
-703
lines changed

.goreleaser.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,31 +84,23 @@ nfpms:
8484
file_info:
8585
mode: 0700
8686
- src: build/package/config.yaml
87-
dst: /etc/newrelic-agent-control/config.yaml
87+
dst: /etc/newrelic-agent-control/local-data/agent-control/local_config.yaml
8888
type: config
8989
file_info:
9090
mode: 0600
9191
- src: build/package/newrelic-agent-control.service
9292
dst: /lib/systemd/system/newrelic-agent-control.service
9393
- src: build/package/newrelic-agent-control.conf
94-
dst: /etc/newrelic-agent-control/newrelic-agent-control.conf
94+
dst: /etc/newrelic-agent-control/systemd-env.conf
9595
type: config|noreplace
9696
file_info:
9797
mode: 0600
98-
- dst: /etc/newrelic-agent-control/fleet/agents.d
99-
type: dir
100-
file_info:
101-
mode: 0700
10298
- src: LICENSE.md
10399
dst: /usr/share/doc/newrelic/newrelic-agent-control/LICENSE.md
104100
- dst: /var/lib/newrelic-agent-control
105101
type: dir
106102
file_info:
107103
mode: 0700
108-
- dst: /var/lib/newrelic-agent-control/fleet/agents.d
109-
type: dir
110-
file_info:
111-
mode: 0700
112104
- dst: /var/lib/newrelic-agent-control/auto-generated
113105
type: dir
114106
file_info:

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace = os.getenv('NAMESPACE','default')
1212
sa_chart_values_file = os.getenv('SA_CHART_VALUES_FILE','local/agent-control-tilt.yml')
1313
cluster = os.getenv('CLUSTER', "")
1414
# Branch of the helm-charts repo to use.
15-
feature_branch = os.getenv('FEATURE_BRANCH', "master")
15+
feature_branch = os.getenv('FEATURE_BRANCH', "change-config-volume-path-for-agent-control")
1616

1717
# Remote updates are disabled by default in order to avoid accidental downgrades.
1818
enable_ac_remote_update = os.getenv('ENABLE_AC_REMOTE_UPDATE', "false")

agent-control/src/agent_control/defaults.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::agent_type::agent_type_id::AgentTypeID;
2+
use crate::k8s::store::StoreKey;
23
use crate::opamp::remote_config::signature::SIGNATURE_CUSTOM_CAPABILITY;
34
use crate::sub_agent::identity::AgentIdentity;
45
use opamp_client::capabilities;
@@ -47,12 +48,24 @@ cfg_if::cfg_if! {
4748
}
4849
}
4950

50-
pub const SUB_AGENT_DIR: &str = "fleet/agents.d";
51-
pub const AGENT_CONTROL_CONFIG_FILENAME: &str = "config.yaml";
51+
/// - **On-host**: Used as the directory name (e.g., `.../local-data/`).
52+
/// - **k8s**: Used as a ConfigMap prefix, followed by a hyphen (e.g., `local-data-agentid`).
53+
pub const FOLDER_NAME_LOCAL_DATA: &str = "local-data";
54+
55+
/// - **On-host**: Used as the directory name (e.g., `.../fleet-data/`).
56+
/// - **k8s**: Used as a ConfigMap prefix, followed by a hyphen (e.g., `fleet-data-agentid`).
57+
pub const FOLDER_NAME_FLEET_DATA: &str = "fleet-data";
58+
59+
/// - **On-host**: Used as the base filename, combined with ".yaml" (e.g., `local_config.yaml`).
60+
/// - **k8s**: Used as the data key within the local ConfigMap.
61+
pub const STORE_KEY_LOCAL_DATA_CONFIG: &StoreKey = "local_config";
62+
63+
/// - **On-host**: Used as the base filename, combined with ".yaml" (e.g., `remote_config.yaml`).
64+
/// - **k8s**: Used as the data key within the OpAMP/fleet ConfigMap.
65+
pub const STORE_KEY_OPAMP_DATA_CONFIG: &StoreKey = "remote_config";
66+
pub const STORE_KEY_INSTANCE_ID: &StoreKey = "instance_id";
5267
pub const DYNAMIC_AGENT_TYPE_DIR: &str = "dynamic-agent-types";
53-
pub const IDENTIFIERS_FILENAME: &str = "identifiers.yaml";
54-
pub const VALUES_DIR: &str = "values";
55-
pub const VALUES_FILENAME: &str = "values.yaml";
68+
pub const INSTANCE_ID_FILENAME: &str = "instance_id.yaml";
5669
pub const GENERATED_FOLDER_NAME: &str = "auto-generated";
5770
pub const AGENT_CONTROL_LOG_FILENAME: &str = "newrelic-agent-control.log";
5871
pub const STDOUT_LOG_PREFIX: &str = "stdout.log";

agent-control/src/agent_control/run/on_host.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::agent_control::config_repository::store::AgentControlConfigStore;
44
use crate::agent_control::config_validator::RegistryDynamicConfigValidator;
55
use crate::agent_control::defaults::{
66
AGENT_CONTROL_VERSION, FLEET_ID_ATTRIBUTE_KEY, HOST_ID_ATTRIBUTE_KEY, HOST_NAME_ATTRIBUTE_KEY,
7-
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY, SUB_AGENT_DIR,
7+
OPAMP_AGENT_VERSION_ATTRIBUTE_KEY,
88
};
99
use crate::agent_control::http_server::runner::Runner;
1010
use crate::agent_control::resource_cleaner::no_op::NoOpResourceCleaner;
@@ -100,7 +100,6 @@ impl AgentControlRunner {
100100
LocalFile,
101101
DirectoryManagerFs,
102102
self.base_paths.remote_dir.clone(),
103-
self.base_paths.remote_dir.join(SUB_AGENT_DIR),
104103
);
105104
let instance_id_getter =
106105
InstanceIDWithIdentifiersGetter::new(instance_id_storer, identifiers);
@@ -154,8 +153,7 @@ impl AgentControlRunner {
154153
&self.base_paths.remote_dir,
155154
));
156155

157-
let supervisor_builder =
158-
SupervisortBuilderOnHost::new(self.base_paths.log_dir.join(SUB_AGENT_DIR));
156+
let supervisor_builder = SupervisortBuilderOnHost::new(self.base_paths.log_dir);
159157

160158
let signature_validator = Arc::new(self.signature_validator);
161159
let remote_config_validators = vec![

agent-control/src/bin/main_config_migrate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() -> Result<(), Box<dyn Error>> {
2626
let config_migrator = ConfigMigrator::new(
2727
ConfigConverter::default(),
2828
AgentConfigGetter::new(sa_local_config_loader),
29-
ValuesPersisterFile::new(cli.local_sub_agent_data_dir()),
29+
ValuesPersisterFile::new(cli.local_data_dir()),
3030
);
3131

3232
let legacy_config_renamer = LegacyConfigRenamer::default();

agent-control/src/config_migrate/cli.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
agent_control::defaults::{
3-
AGENT_CONTROL_DATA_DIR, AGENT_CONTROL_LOCAL_DATA_DIR, AGENT_CONTROL_LOG_DIR, SUB_AGENT_DIR,
3+
AGENT_CONTROL_DATA_DIR, AGENT_CONTROL_LOCAL_DATA_DIR, AGENT_CONTROL_LOG_DIR,
44
},
55
config_migrate::migration::defaults::NEWRELIC_INFRA_AGENT_TYPE_CONFIG_MAPPING,
66
};
@@ -38,10 +38,6 @@ impl Cli {
3838
self.local_dir.to_path_buf()
3939
}
4040

41-
pub fn local_sub_agent_data_dir(&self) -> PathBuf {
42-
self.local_dir.join(SUB_AGENT_DIR)
43-
}
44-
4541
pub fn remote_data_dir(&self) -> PathBuf {
4642
self.remote_dir.to_path_buf()
4743
}

agent-control/src/config_migrate/migration/persister/values_persister_file.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::agent_control::agent_id::AgentID;
2-
use crate::agent_control::defaults::{VALUES_DIR, VALUES_FILENAME};
2+
use crate::agent_control::defaults::STORE_KEY_OPAMP_DATA_CONFIG;
3+
use crate::opamp::instance_id::on_host::storer::build_config_name;
34
use fs::LocalFile;
45
use fs::directory_manager::{DirectoryManagementError, DirectoryManager, DirectoryManagerFs};
56
use fs::writer_file::{FileWriter, WriteError};
@@ -51,11 +52,7 @@ where
5152
if !path.exists() {
5253
self.create_directory(&path)?;
5354
}
54-
path.push(VALUES_DIR);
55-
if !path.exists() {
56-
self.create_directory(&path)?;
57-
}
58-
path.push(VALUES_FILENAME);
55+
path.push(build_config_name(STORE_KEY_OPAMP_DATA_CONFIG));
5956

6057
debug!("writing to file {:?}", path.as_path());
6158

agent-control/src/k8s/store.rs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,12 @@ use super::Error;
33
use super::client::SyncK8sClient;
44
use super::labels::Labels;
55
use crate::agent_control::agent_id::AgentID;
6+
use crate::agent_control::defaults::{FOLDER_NAME_FLEET_DATA, FOLDER_NAME_LOCAL_DATA};
67
use std::sync::{Arc, RwLock};
78

8-
/// The prefixes for the ConfigMap name.
9-
/// The cm having CM_NAME_LOCAL_DATA_PREFIX stores all the config that are "local",
10-
/// the SA treats those CM as read-only.
11-
pub const CM_NAME_LOCAL_DATA_PREFIX: &str = "local-data-";
12-
/// The cm having CM_NAME_OPAMP_DATA_PREFIX as prefix stores all the data related with opamp:
13-
/// Instance IDs, hashes, and remote configs. The Sa reads and writes those CMs.
14-
pub const CM_NAME_OPAMP_DATA_PREFIX: &str = "fleet-data-";
15-
169
/// The key used to identify the data in the Store.
1710
pub type StoreKey = str;
1811

19-
pub const STORE_KEY_LOCAL_DATA_CONFIG: &StoreKey = "local_config";
20-
pub const STORE_KEY_OPAMP_DATA_CONFIG: &StoreKey = "remote_config";
21-
pub const STORE_KEY_INSTANCE_ID: &StoreKey = "instance_id";
22-
2312
/// Represents a Kubernetes persistent store of Agents data such as instance id and configs.
2413
/// The store is implemented using one ConfigMap per Agent with all the data.
2514
pub struct K8sStore {
@@ -44,7 +33,7 @@ impl K8sStore {
4433
where
4534
T: serde::de::DeserializeOwned,
4635
{
47-
self.get(agent_id, CM_NAME_OPAMP_DATA_PREFIX, key)
36+
self.get(agent_id, FOLDER_NAME_FLEET_DATA, key)
4837
}
4938

5039
/// get_local_data is used to get data from CMs storing local configurations. I.e. all the CMs
@@ -53,7 +42,7 @@ impl K8sStore {
5342
where
5443
T: serde::de::DeserializeOwned,
5544
{
56-
self.get(agent_id, CM_NAME_LOCAL_DATA_PREFIX, key)
45+
self.get(agent_id, FOLDER_NAME_LOCAL_DATA, key)
5746
}
5847

5948
/// Retrieves data from an Agent store.
@@ -91,7 +80,7 @@ impl K8sStore {
9180
let _write_guard = self.rw_lock.write().unwrap();
9281

9382
let data_as_string = serde_yaml::to_string(data)?;
94-
let configmap_name = K8sStore::build_cm_name(agent_id, CM_NAME_OPAMP_DATA_PREFIX);
83+
let configmap_name = K8sStore::build_cm_name(agent_id, FOLDER_NAME_FLEET_DATA);
9584
self.k8s_client.set_configmap_key(
9685
&configmap_name,
9786
self.namespace.as_str(),
@@ -106,21 +95,21 @@ impl K8sStore {
10695
#[allow(clippy::readonly_write_lock)]
10796
let _write_guard = self.rw_lock.write().unwrap();
10897

109-
let configmap_name = K8sStore::build_cm_name(agent_id, CM_NAME_OPAMP_DATA_PREFIX);
98+
let configmap_name = K8sStore::build_cm_name(agent_id, FOLDER_NAME_FLEET_DATA);
11099
self.k8s_client
111100
.delete_configmap_key(&configmap_name, self.namespace.as_str(), key)
112101
}
113102

114103
pub fn build_cm_name(agent_id: &AgentID, prefix: &str) -> String {
115-
format!("{prefix}{agent_id}")
104+
format!("{prefix}-{agent_id}")
116105
}
117106
}
118107

119108
#[cfg(test)]
120109
pub mod tests {
121-
use super::{CM_NAME_LOCAL_DATA_PREFIX, CM_NAME_OPAMP_DATA_PREFIX};
122110
use super::{K8sStore, StoreKey};
123111
use crate::agent_control::agent_id::AgentID;
112+
use crate::agent_control::defaults::{FOLDER_NAME_FLEET_DATA, FOLDER_NAME_LOCAL_DATA};
124113
use crate::k8s::client::MockSyncK8sClient;
125114
use crate::k8s::error::K8sError;
126115
use crate::k8s::labels::Labels;
@@ -132,7 +121,7 @@ pub mod tests {
132121
const DATA_STORED: &str = "test: foo\n";
133122
pub const STORE_KEY_TEST: &StoreKey = "data_to_be_stored";
134123
const TEST_NAMESPACE: &str = "test-namespace";
135-
pub const PREFIX_TEST: &StoreKey = "prefix-";
124+
pub const PREFIX_TEST: &StoreKey = "prefix";
136125

137126
#[derive(Deserialize, Serialize, Default, Debug, PartialEq)]
138127
pub struct DataToBeStored {
@@ -150,10 +139,7 @@ pub mod tests {
150139
.expect_set_configmap_key()
151140
.once()
152141
.with(
153-
predicate::eq(K8sStore::build_cm_name(
154-
&agent_id,
155-
CM_NAME_OPAMP_DATA_PREFIX,
156-
)),
142+
predicate::eq(K8sStore::build_cm_name(&agent_id, FOLDER_NAME_FLEET_DATA)),
157143
predicate::eq(TEST_NAMESPACE),
158144
predicate::eq(Labels::new(&AgentID::try_from(AGENT_NAME).unwrap()).get()),
159145
predicate::eq(STORE_KEY_TEST),
@@ -164,10 +150,7 @@ pub mod tests {
164150
.expect_delete_configmap_key()
165151
.once()
166152
.with(
167-
predicate::eq(K8sStore::build_cm_name(
168-
&agent_id,
169-
CM_NAME_OPAMP_DATA_PREFIX,
170-
)),
153+
predicate::eq(K8sStore::build_cm_name(&agent_id, FOLDER_NAME_FLEET_DATA)),
171154
predicate::eq(TEST_NAMESPACE),
172155
predicate::eq(STORE_KEY_TEST),
173156
)
@@ -195,7 +178,7 @@ pub mod tests {
195178
k8s_client
196179
.expect_get_configmap_key()
197180
.with(
198-
predicate::eq(K8sStore::build_cm_name(agent_id, CM_NAME_OPAMP_DATA_PREFIX)),
181+
predicate::eq(K8sStore::build_cm_name(agent_id, FOLDER_NAME_FLEET_DATA)),
199182
predicate::eq(TEST_NAMESPACE),
200183
predicate::eq(STORE_KEY_TEST),
201184
)
@@ -209,7 +192,7 @@ pub mod tests {
209192
k8s_client
210193
.expect_get_configmap_key()
211194
.with(
212-
predicate::eq(K8sStore::build_cm_name(agent_id, CM_NAME_LOCAL_DATA_PREFIX)),
195+
predicate::eq(K8sStore::build_cm_name(agent_id, FOLDER_NAME_LOCAL_DATA)),
213196
predicate::eq(TEST_NAMESPACE),
214197
predicate::always(),
215198
)

agent-control/src/opamp/instance_id/k8s/storer.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
use crate::agent_control::agent_id::AgentID;
22

3-
use crate::k8s::{
4-
self,
5-
store::{K8sStore, STORE_KEY_INSTANCE_ID},
6-
};
3+
use super::getter::Identifiers;
4+
use crate::agent_control::defaults::STORE_KEY_INSTANCE_ID;
5+
use crate::k8s::{self, store::K8sStore};
76
use crate::opamp::instance_id::getter::DataStored;
87
use crate::opamp::instance_id::storer::InstanceIDStorer;
98
use std::sync::Arc;
109
use tracing::debug;
1110

12-
use super::getter::Identifiers;
13-
1411
pub struct Storer {
1512
k8s_store: Arc<K8sStore>,
1613
}

0 commit comments

Comments
 (0)