feat: add visible pod discovery tools
This commit is contained in:
@@ -123,6 +123,35 @@ impl PodMetadataStore for FsStore {
|
||||
Ok(Some(serde_json::from_str(&content)?))
|
||||
}
|
||||
|
||||
fn list_names(&self) -> Result<Vec<String>, StoreError> {
|
||||
let dir = self.pods_dir();
|
||||
let mut names = Vec::new();
|
||||
if !dir.exists() {
|
||||
return Ok(names);
|
||||
}
|
||||
for entry in fs::read_dir(dir)? {
|
||||
let entry = entry?;
|
||||
if !entry.file_type()?.is_dir() {
|
||||
continue;
|
||||
}
|
||||
if !entry.path().join("metadata.json").exists() {
|
||||
continue;
|
||||
}
|
||||
let Some(name) = entry.file_name().to_str().map(ToOwned::to_owned) else {
|
||||
continue;
|
||||
};
|
||||
if validate_pod_name(&name).is_ok() {
|
||||
names.push(name);
|
||||
}
|
||||
}
|
||||
names.sort();
|
||||
Ok(names)
|
||||
}
|
||||
|
||||
fn root_dir(&self) -> Option<PathBuf> {
|
||||
Some(self.root.clone())
|
||||
}
|
||||
|
||||
fn delete_by_name(&self, pod_name: &str) -> Result<(), StoreError> {
|
||||
let path = self.pod_metadata_path(pod_name)?;
|
||||
match fs::remove_file(&path) {
|
||||
|
||||
@@ -92,6 +92,16 @@ pub trait PodMetadataStore: Send + Sync {
|
||||
/// Read metadata by Pod name. Returns `None` when no metadata exists.
|
||||
fn read_by_name(&self, pod_name: &str) -> Result<Option<PodMetadata>, StoreError>;
|
||||
|
||||
/// List persisted Pod metadata keys. Implementations return names only;
|
||||
/// callers can then read each item independently so a corrupt metadata
|
||||
/// file does not make the whole discovery result fail.
|
||||
fn list_names(&self) -> Result<Vec<String>, StoreError>;
|
||||
|
||||
/// Return the metadata root directory when this backend is path-backed.
|
||||
fn root_dir(&self) -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Delete metadata by Pod name. Missing metadata is a successful no-op.
|
||||
fn delete_by_name(&self, pod_name: &str) -> Result<(), StoreError>;
|
||||
}
|
||||
|
||||
@@ -250,6 +250,7 @@ fn pod_metadata_minimal_crud() {
|
||||
|
||||
let pending = PodMetadata::new(pod_name, Some(PodActiveSegmentRef::pending_segment(sid)));
|
||||
store.write(&pending).unwrap();
|
||||
assert_eq!(store.list_names().unwrap(), vec![pod_name.to_string()]);
|
||||
assert_eq!(store.read_by_name(pod_name).unwrap(), Some(pending.clone()));
|
||||
assert!(
|
||||
dir.path()
|
||||
|
||||
Reference in New Issue
Block a user