feat: add reconciliation loop

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2026-01-06 22:06:54 +01:00
parent 2d59c7fd69
commit f73b8c7796
13 changed files with 790 additions and 221 deletions

View File

@@ -1,7 +1,6 @@
use async_trait::async_trait;
use nocontrol::{
manifests::{Manifest, ManifestMetadata, ManifestState},
Operator, Specification,
Operator, OperatorState, Specification,
manifests::{Action, Manifest, ManifestMetadata, ManifestState},
};
use serde::{Deserialize, Serialize};
use tracing_test::traced_test;
@@ -9,8 +8,7 @@ use tracing_test::traced_test;
#[tokio::test]
#[traced_test]
async fn test_can_run_reconciler() -> anyhow::Result<()> {
let operator = MyOperator {};
let operator = OperatorState::new(MyOperator {});
let mut control_plane = nocontrol::ControlPlane::new(operator);
control_plane.with_deadline(std::time::Duration::from_secs(3));
@@ -51,19 +49,13 @@ async fn test_can_run_reconciler() -> anyhow::Result<()> {
#[derive(Clone)]
pub struct MyOperator {}
#[async_trait]
impl Operator for MyOperator {
type Specifications = Specifications;
async fn reconcile(
&self,
desired_manifest: &mut ManifestState<Specifications>,
) -> anyhow::Result<()> {
let now = jiff::Timestamp::now();
desired_manifest.status.status = nocontrol::manifests::ManifestStatusState::Started;
desired_manifest.updated = now;
) -> anyhow::Result<Action> {
match &desired_manifest.manifest.spec {
Specifications::Deployment(spec) => {
tracing::info!(
@@ -73,10 +65,8 @@ impl Operator for MyOperator {
)
}
}
desired_manifest.status.status = nocontrol::manifests::ManifestStatusState::Running;
desired_manifest.updated = now;
Ok(())
Ok(Action::Requeue(std::time::Duration::from_secs(1)))
}
}