Skip to content

Commit

Permalink
operator: implement Default for manifests
Browse files Browse the repository at this point in the history
**Summary**

Implementing `Default` makes the structs much nicer to use since most
fields will be left empty or to their default value.
  • Loading branch information
fracek committed Jul 11, 2023
1 parent c8d41f6 commit 7f00306
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions operator/src/sink/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand All @@ -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<serde_json::Map<String, serde_json::Value>>,
Expand All @@ -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`.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}

Expand Down
3 changes: 2 additions & 1 deletion operator/src/sink/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
2 changes: 1 addition & 1 deletion operator/src/sink/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7f00306

Please sign in to comment.