/ operator / src / crd.rs
crd.rs
  1  use k8s_openapi::{
  2      api::core::v1::{EnvVar, EnvVarSource, Volume, VolumeMount},
  3      apimachinery::pkg::apis::meta::v1::{Condition, Time},
  4  };
  5  use kube::CustomResource;
  6  use schemars::JsonSchema;
  7  use serde::{Deserialize, Serialize};
  8  
  9  pub type HeaderValueSource = EnvVarSource;
 10  
 11  /// Run an indexer.
 12  #[derive(CustomResource, Deserialize, Serialize, Clone, Debug, JsonSchema)]
 13  #[kube(
 14      kind = "Indexer",
 15      group = "apibara.com",
 16      version = "v1alpha2",
 17      namespaced,
 18      printcolumn = r#"{"name": "Age", "type": "date", "jsonPath": ".metadata.creationTimestamp" }"#,
 19      printcolumn = r#"{"name": "Status", "type": "string", "jsonPath": ".status.phase" }"#,
 20      printcolumn = r#"{"name": "Instance", "type": "string", "jsonPath": ".status.instanceName" }"#,
 21      printcolumn = r#"{"name": "Restarts", "type": "number", "jsonPath": ".status.restartCount" }"#
 22  )]
 23  #[kube(status = "IndexerStatus", shortname = "indexer")]
 24  #[serde(rename_all = "camelCase")]
 25  pub struct IndexerSpec {
 26      /// Indexer source code.
 27      pub source: IndexerSource,
 28      /// Sink to run.
 29      pub sink: Sink,
 30      /// List of volumes that can be mounted by containers belonging to the indexer.
 31      pub volumes: Option<Vec<IndexerVolume>>,
 32      /// List of environment variables to set in the indexer container.
 33      pub env: Option<Vec<EnvVar>>,
 34  }
 35  
 36  #[derive(Deserialize, Serialize, Clone, Debug, JsonSchema, PartialEq)]
 37  #[serde(rename_all = "camelCase")]
 38  pub enum IndexerSource {
 39      /// Clone the indexer repository from GitHub.
 40      GitHub(GitHubSource),
 41      /// Use source code from a mounted volume.
 42      Volume(VolumeSource),
 43  }
 44  
 45  #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema, PartialEq)]
 46  #[serde(rename_all = "camelCase")]
 47  pub struct GitHubSource {
 48      /// GitHub repository owner, e.g. `my-org`.
 49      pub owner: String,
 50      /// GitHub repository name, e.g. `my-indexer`.
 51      pub repo: String,
 52      /// Git revision, e.g. `main` or `a746ab`.
 53      pub revision: String,
 54      /// Run the indexer from the specified subpath of the repository, e.g. `/packages/indexer`.
 55      pub subpath: Option<String>,
 56      /// Environment variable containing the GitHub access token.
 57      pub access_token_env_var: Option<String>,
 58      /// Additional flags to pass to `git clone`.
 59      pub git_clone_flags: Option<String>,
 60      /// Additional flags to pass to `git clean`.
 61      pub git_clean_flags: Option<String>,
 62  }
 63  
 64  #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema, PartialEq)]
 65  #[serde(rename_all = "camelCase")]
 66  pub struct VolumeSource {
 67      /// Path to the indexer source code, e.g. `/myvolume`.
 68      ///
 69      /// Use this option with the `volumes` field to mount a volume containing the indexer source
 70      /// code.
 71      pub path: String,
 72  }
 73  
 74  #[derive(Deserialize, Serialize, Clone, Debug, JsonSchema, PartialEq)]
 75  #[serde(rename_all = "camelCase")]
 76  pub struct Sink {
 77      /// Container image with the sink.
 78      #[serde(flatten)]
 79      pub sink: SinkType,
 80      /// Path to the script to run.
 81      pub script: String,
 82      /// Arguments passed to the sink.
 83      pub args: Option<Vec<String>>,
 84  }
 85  
 86  #[derive(Deserialize, Serialize, Clone, Debug, JsonSchema, PartialEq)]
 87  #[serde(rename_all = "camelCase", untagged)]
 88  pub enum SinkType {
 89      Type { r#type: String },
 90      Image { image: String },
 91  }
 92  
 93  #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema, PartialEq)]
 94  #[serde(rename_all = "camelCase")]
 95  pub struct IndexerVolume {
 96      /// Volume to mount.
 97      pub volume: Volume,
 98      /// Volume mount specification.
 99      pub volume_mount: VolumeMount,
100  }
101  
102  /// Most recent status of the indexer.
103  #[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema, PartialEq)]
104  #[serde(rename_all = "camelCase")]
105  pub struct IndexerStatus {
106      /// Conditions of the indexer.
107      pub conditions: Option<Vec<Condition>>,
108      /// The name of the container running the indexer.
109      pub instance_name: Option<String>,
110      /// Service name exposing the indexer's status.
111      pub status_service_name: Option<String>,
112      /// Current phase of the indexer.
113      pub phase: Option<String>,
114      /// Number of times the indexer container has restarted.
115      pub restart_count: Option<i32>,
116      /// Creation timestamp of the indexer's pod.
117      pub pod_created: Option<Time>,
118  }