@@ -3,23 +3,12 @@ use super::Error;
33use super :: client:: SyncK8sClient ;
44use super :: labels:: Labels ;
55use crate :: agent_control:: agent_id:: AgentID ;
6+ use crate :: agent_control:: defaults:: { FOLDER_NAME_FLEET_DATA , FOLDER_NAME_LOCAL_DATA } ;
67use 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.
1710pub 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.
2514pub 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) ]
120109pub 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 )
0 commit comments