GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(agent): fence locality before route and CNI startup · arencloud/unf@01aba67

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Cargo.lock
  • bins/unf-agent
    • Cargo.toml
    • src
      • cni_server.rs
      • locality_runtime.rs
      • main.rs
  • crates/unf-locality/examples
    • kernel_observed_bank.rs
    • support
      • runtime_owner.rs
  • docs
    • adr
      • 0425-agent-locality-startup-and-journal-binding.md
    • development
      • phase9-attested-encryption-fabric-plan.md
      • phase9-required-locality-plan.md
    • project-status.md
  • ebpf/unf-ebpf-tc/src
    • main.rs
  • hack
    • verify-locality-incarnation-gate.sh
  • images
    • KernelLocalityTestContainerfile
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Cargo.lock‎

Copy file name to clipboardExpand all lines: Cargo.lock
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎bins/unf-agent/Cargo.toml‎

Copy file name to clipboardExpand all lines: bins/unf-agent/Cargo.toml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ unf-egress = { path = "../../crates/unf-egress" }
3030
unf-gobgp = { path = "../../crates/unf-gobgp" }
3131
unf-ipam = { path = "../../crates/unf-ipam" }
3232
unf-link = { path = "../../crates/unf-link" }
33+
unf-locality = { path = "../../crates/unf-locality" }
3334
unf-loadbalancer = { path = "../../crates/unf-loadbalancer" }
3435
unf-route = { path = "../../crates/unf-route" }
3536
unf-runtime = { path = "../../crates/unf-runtime" }
Collapse file

‎bins/unf-agent/src/cni_server.rs‎

Copy file name to clipboardExpand all lines: bins/unf-agent/src/cni_server.rs
+121-2Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,47 @@ impl CniTransactionServer {
4141
///
4242
/// Returns an error when the paths are unsafe, durable state is invalid, or
4343
/// the socket cannot be bound with owner-only permissions.
44+
#[cfg(test)]
4445
pub fn bind(
4546
socket_path: PathBuf,
4647
state_path: &Path,
4748
provider: NodeBlockProvider,
4849
readiness_lease_path: PathBuf,
4950
readiness_heartbeat: Duration,
51+
) -> Result<Self> {
52+
Self::bind_with_initializer(
53+
socket_path,
54+
state_path,
55+
provider,
56+
readiness_lease_path,
57+
readiness_heartbeat,
58+
|_| Ok(()),
59+
)
60+
}
61+
62+
/// Initialize retirement while exclusively owning startup and before any
63+
/// socket/readiness publication. Existing live sockets reject first, before
64+
/// schema migration. An unhooked schema-5 journal must never report Ready.
65+
pub(super) fn bind_with_initializer(
66+
socket_path: PathBuf,
67+
state_path: &Path,
68+
provider: NodeBlockProvider,
69+
readiness_lease_path: PathBuf,
70+
readiness_heartbeat: Duration,
71+
initialize: impl FnOnce(&mut AttachmentJournal) -> Result<()>,
5072
) -> Result<Self> {
5173
validate_socket_path(&socket_path)?;
5274
validate_readiness_lease_path(&readiness_lease_path)?;
5375
if readiness_heartbeat.is_zero() {
5476
bail!("CNI readiness heartbeat must be greater than zero");
5577
}
56-
let journal = AttachmentJournal::open(state_path, provider)
57-
.with_context(|| format!("open CNI attachment journal {}", state_path.display()))?;
5878
prepare_socket_path(&socket_path)?;
79+
let mut journal = AttachmentJournal::open(state_path, provider)
80+
.with_context(|| format!("open CNI attachment journal {}", state_path.display()))?;
81+
initialize(&mut journal)?;
82+
if journal.retirement_required() && journal.cut().is_none() {
83+
bail!("CNI retirement-required journal has no live startup gate");
84+
}
5985
let listener = UnixListener::bind(&socket_path)
6086
.with_context(|| format!("bind CNI transaction socket {}", socket_path.display()))?;
6187
fs::set_permissions(&socket_path, fs::Permissions::from_mode(0o600))
@@ -371,6 +397,99 @@ mod tests {
371397
)
372398
}
373399

400+
struct NoopRetirement;
401+
impl unf_cni_state::AttachmentRetirement for NoopRetirement {
402+
fn retire(&self, _: &[u8; 32]) -> io::Result<()> {
403+
Ok(())
404+
}
405+
}
406+
407+
#[tokio::test]
408+
async fn required_journal_without_initializer_never_binds_or_reports_ready() {
409+
let directory = tempfile::tempdir().unwrap();
410+
let journal_path = directory.path().join("attachments.json");
411+
let socket = directory.path().join("cni.sock");
412+
let lease = directory.path().join("readiness");
413+
let mut journal = AttachmentJournal::open(&journal_path, provider()).unwrap();
414+
journal
415+
.install_required_retirement(Box::new(NoopRetirement))
416+
.unwrap();
417+
drop(journal);
418+
let before = fs::read(&journal_path).unwrap();
419+
assert!(
420+
CniTransactionServer::bind(
421+
socket.clone(),
422+
&journal_path,
423+
provider(),
424+
lease.clone(),
425+
Duration::from_secs(1)
426+
)
427+
.is_err()
428+
);
429+
assert!(!socket.exists() && !lease.exists());
430+
assert_eq!(fs::read(&journal_path).unwrap(), before);
431+
}
432+
433+
#[tokio::test]
434+
async fn initializer_precedes_socket_and_readiness_but_not_live_owner_check() {
435+
let directory = tempfile::tempdir().unwrap();
436+
let journal_path = directory.path().join("attachments.json");
437+
let socket = directory.path().join("cni.sock");
438+
let lease = directory.path().join("readiness");
439+
let server = CniTransactionServer::bind_with_initializer(
440+
socket.clone(),
441+
&journal_path,
442+
provider(),
443+
lease.clone(),
444+
Duration::from_secs(1),
445+
|journal| {
446+
assert!(!socket.exists() && !lease.exists());
447+
journal.install_required_retirement(Box::new(NoopRetirement))?;
448+
Ok(())
449+
},
450+
)
451+
.unwrap();
452+
assert!(server.journal.lock().await.cut().is_some());
453+
let before = fs::read(&journal_path).unwrap();
454+
let mut called = false;
455+
assert!(
456+
CniTransactionServer::bind_with_initializer(
457+
socket.clone(),
458+
&journal_path,
459+
provider(),
460+
lease.clone(),
461+
Duration::from_secs(1),
462+
|_| {
463+
called = true;
464+
Ok(())
465+
}
466+
)
467+
.is_err()
468+
);
469+
assert!(!called && !lease.exists());
470+
assert_eq!(fs::read(&journal_path).unwrap(), before);
471+
drop(server);
472+
}
473+
474+
#[tokio::test]
475+
async fn failed_initializer_stops_before_socket_and_readiness() {
476+
let directory = tempfile::tempdir().unwrap();
477+
let socket = directory.path().join("cni.sock");
478+
let lease = directory.path().join("readiness");
479+
assert!(
480+
CniTransactionServer::bind_with_initializer(
481+
socket.clone(),
482+
&directory.path().join("attachments.json"),
483+
provider(),
484+
lease.clone(),
485+
Duration::from_secs(1),
486+
|_| bail!("injected gate failure")
487+
)
488+
.is_err()
489+
);
490+
assert!(!socket.exists() && !lease.exists());
491+
}
492+
374493
fn request(operation: TransactionOperation) -> Vec<u8> {
375494
serde_json::to_vec(&TransactionRequest::new(
376495
CNI_TRANSACTION_SCHEMA_VERSION,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.