feat: add reconciliation loop
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -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)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user