From 7f00306001c1ff030ccc1babf49b880dbe6c7e0e Mon Sep 17 00:00:00 2001 From: Francesco Ceccon Date: Tue, 11 Jul 2023 20:41:11 +0200 Subject: [PATCH] operator: implement Default for manifests **Summary** Implementing `Default` makes the structs much nicer to use since most fields will be left empty or to their default value. --- operator/src/sink/common.rs | 13 +++++++------ operator/src/sink/mod.rs | 3 ++- operator/src/sink/webhook.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/operator/src/sink/common.rs b/operator/src/sink/common.rs index 211cdafa..94d8b8a8 100644 --- a/operator/src/sink/common.rs +++ b/operator/src/sink/common.rs @@ -12,7 +12,7 @@ pub type MetadataValueSource = EnvVarSource; pub type AuthTokenValueSource = EnvVarSource; /// Common configuration between all sinks. -#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] +#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct CommonSpec { pub stream: StreamSpec, @@ -23,7 +23,7 @@ pub struct CommonSpec { } /// Configure the image used to run the sink. -#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] +#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct ImageSpec { /// Name of the container image to run. @@ -39,7 +39,7 @@ pub struct ImageSpec { } /// Metadata that will be inherited by all resources created by the sink. -#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] +#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)] pub struct InheritedMetadataSpec { /// Annotations to add to the resources. pub annotations: Option>, @@ -61,7 +61,7 @@ pub struct PersistenceSpec { } /// DNA stream configuration. -#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] +#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct StreamSpec { /// URL of the stream. Must start with `http` or `https`. @@ -89,7 +89,7 @@ pub struct StreamSpec { } /// Use a filter to select which data to stream. -#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] +#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct FilterSource { /// Filter from ConfigMap. @@ -121,10 +121,11 @@ pub enum FinalitySpec { } /// Type of network. -#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)] +#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)] #[serde(rename_all = "lowercase")] pub enum NetworkTypeSpec { /// Starknet L2 and appchains. + #[default] Starknet, } diff --git a/operator/src/sink/mod.rs b/operator/src/sink/mod.rs index e6bd9285..a9836c24 100644 --- a/operator/src/sink/mod.rs +++ b/operator/src/sink/mod.rs @@ -3,4 +3,5 @@ pub mod webhook; #[cfg(feature = "operator")] pub mod webhook_controller; -pub use webhook::{SinkWebhook, SinkWebhookSpec, SinkWebhookStatus}; +pub use common::*; +pub use webhook::*; diff --git a/operator/src/sink/webhook.rs b/operator/src/sink/webhook.rs index ddcf6b1a..8d5dc836 100644 --- a/operator/src/sink/webhook.rs +++ b/operator/src/sink/webhook.rs @@ -8,7 +8,7 @@ use super::common::{CommonSpec, CommonStatus}; pub type HeaderValueSource = EnvVarSource; /// Run a sink that invokes a webhook for each batch of data. -#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)] +#[derive(CustomResource, Deserialize, Serialize, Clone, Debug, Default, JsonSchema)] #[kube( kind = "SinkWebhook", group = "apibara.com",