diff --git a/operator/src/controller.rs b/operator/src/controller.rs index c9698e5..e5f4420 100644 --- a/operator/src/controller.rs +++ b/operator/src/controller.rs @@ -1,5 +1,6 @@ use futures::StreamExt; use kube::{ + api::ListParams, runtime::{controller::Action, watcher::Config as WatcherConfig, Controller}, Api, Client, CustomResource, ResourceExt, }; @@ -76,18 +77,25 @@ fn error_policy(crd: Arc, err: &Error, ctx: Arc) -> Action } #[instrument("controller run", skip_all)] -pub async fn run(state: Arc) -> Result<(), Error> { +pub async fn run(state: Arc) { info!("listening crds running"); - let client = Client::try_default().await?; + let client = Client::try_default() + .await + .expect("failed to create kube client"); + let crds = Api::::all(client.clone()); + if let Err(e) = crds.list(&ListParams::default().limit(1)).await { + error!("CRD is not queryable; {e:?}. Is the CRD installed?"); + std::process::exit(1); + } + let ctx = Context::new(client, state.metrics.clone()); Controller::new(crds, WatcherConfig::default().any_semantic()) .shutdown_on_signal() .run(reconcile, error_policy, Arc::new(ctx)) + .filter_map(|x| async move { std::result::Result::ok(x) }) .for_each(|_| futures::future::ready(())) .await; - - Ok(()) } diff --git a/operator/src/main.rs b/operator/src/main.rs index 621b6c2..05a7c13 100644 --- a/operator/src/main.rs +++ b/operator/src/main.rs @@ -30,7 +30,7 @@ async fn main() -> io::Result<()> { let state = Arc::new(State::default()); - let controller = tokio::spawn(controller::run(state.clone())); + let controller = controller::run(state.clone()); let addr = std::env::var("ADDR").unwrap_or("0.0.0.0:8080".into()); @@ -44,12 +44,7 @@ async fn main() -> io::Result<()> { .bind(&addr)?; info!({ addr }, "metrics server running"); - let signal = tokio::spawn(async { - tokio::signal::ctrl_c().await.expect("Fail to exit"); - std::process::exit(0); - }); - - tokio::join!(server.run(), controller, signal).0?; + tokio::join!(server.run(), controller,).0?; Ok(()) } diff --git a/operator/yaml/crd.yaml b/operator/yaml/crd.yaml new file mode 100644 index 0000000..294afc3 --- /dev/null +++ b/operator/yaml/crd.yaml @@ -0,0 +1,67 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: ogmiosports.demeter.run +spec: + group: demeter.run + names: + categories: [] + kind: OgmiosPort + plural: ogmiosports + shortNames: [] + singular: ogmiosport + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.network + name: Network + type: string + - jsonPath: .spec.version + name: Version + type: number + - jsonPath: .status.endpointUrl + name: Endpoint URL + type: string + - jsonPath: .status.authToken + name: Auth Token + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: Auto-generated derived type for OgmiosPortSpec via `CustomResource` + properties: + spec: + properties: + network: + enum: + - mainnet + - preprod + - preview + - sanchonet + type: string + version: + format: uint8 + minimum: 0.0 + type: integer + required: + - network + - version + type: object + status: + nullable: true + properties: + authToken: + nullable: true + type: string + endpointUrl: + nullable: true + type: string + type: object + required: + - spec + title: OgmiosPort + type: object + served: true + storage: true + subresources: + status: {} diff --git a/operator/yaml/port.yaml b/operator/yaml/port.yaml new file mode 100644 index 0000000..84916bd --- /dev/null +++ b/operator/yaml/port.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: prj-mainnet-test +--- +apiVersion: demeter.run/v1alpha1 +kind: OgmiosPort +metadata: + name: mainnet-user + namespace: prj-mainnet-test +spec: + network: "mainnet" + version: 1 +