-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
**Summary** Add the handler to reconcile webhook sinks by creating a pod with all the command line flags (from environment) configured. **Test Plan** Use the manifests in `operator/examples` to test that the webhook resources are created.
- Loading branch information
Showing
21 changed files
with
758 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Apibara Operator Examples | ||
|
||
This folder contains example manifests that you can use to test your Apibara | ||
Operator installation. | ||
|
||
|
||
### Getting Started | ||
|
||
If you're deploying integrations that use data from the hosted streams, you | ||
must configure your API Key in `apikey.yaml`. | ||
|
||
Change the value of the `production` key to your key, then deploy it with: | ||
|
||
```sh | ||
kubectl apply -f apikey.yaml | ||
``` | ||
|
||
|
||
### Content Structure | ||
|
||
- `config.yaml`: contains a `ConfigMap` with a filter and transform for the | ||
AVNU exchange on Starknet Goerli. | ||
- `webhook.yaml`: deploys a webhook integration that streams AVNU data to [/dev/null as a Service](https://devnull-as-a-service.com/code/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
namespace: default | ||
name: apibara-api-key | ||
stringData: | ||
production: dna_XXX | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
namespace: default | ||
name: avnu-swaps | ||
data: | ||
# AVNU exchange swap events, on Starknet Goerli testnet. | ||
filter.json: | | ||
{ | ||
"header": { "weak": true }, | ||
"events": [ | ||
{ | ||
"fromAddress": "0x06d8cd321dcbbf54512eab67c8a6849faf920077a3996f40bb4761adc4f021d2", | ||
"keys": ["0xe316f0d9d2a3affa97de1d99bb2aac0538e2666d0d8545545ead241ef0ccab"] | ||
} | ||
] | ||
} | ||
transform.js: | | ||
// Return the batch as is | ||
export default function transform(batch) { | ||
return batch; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: apibara.com/v1alpha1 | ||
kind: SinkWebhook | ||
metadata: | ||
namespace: default | ||
name: webhook-example | ||
spec: | ||
targetUrl: https://devnull-as-a-service.com/dev/null | ||
headers: | ||
- name: x-my-header | ||
value: "test value" | ||
stream: | ||
filter: | ||
configMapKeyRef: | ||
key: filter.json | ||
name: avnu-swaps | ||
streamUrl: https://goerli.starknet.a5a.ch | ||
authToken: | ||
valueFrom: | ||
secretKeyRef: | ||
name: apibara-api-key | ||
key: production | ||
network: starknet | ||
finality: accepted | ||
startingBlock: 781300 | ||
inheritedMetadata: | ||
annotations: | ||
"sidecar.opentelemetry.io/inject": true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct Configuration { | ||
pub webhook: SinkWebhookConfiguration, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct SinkWebhookConfiguration { | ||
/// The image name to use for the webhook container. | ||
pub image: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::fmt::Debug; | ||
|
||
use futures::{Future, Stream, StreamExt}; | ||
use kube::{ | ||
core::Resource, | ||
runtime::{ | ||
controller::{Action, Error as ControllerError}, | ||
reflector::ObjectRef, | ||
watcher::Error as WatcherError, | ||
}, | ||
Client, | ||
}; | ||
use tracing::{info, warn}; | ||
|
||
use crate::{ | ||
configuration::Configuration, | ||
reconcile::{Context, Error}, | ||
sink::webhook, | ||
}; | ||
|
||
pub type ReconcileItem<K> = Result<(ObjectRef<K>, Action), ControllerError<Error, WatcherError>>; | ||
|
||
pub async fn start(client: Client, configuration: Configuration) -> Result<(), Error> { | ||
info!("controller started"); | ||
|
||
let ctx = Context { | ||
client, | ||
configuration, | ||
}; | ||
let webhook_controller = webhook::start_controller(ctx.clone()).await?; | ||
|
||
run_controller_to_end(webhook_controller).await; | ||
|
||
info!("controller terminated"); | ||
Ok(()) | ||
} | ||
|
||
fn run_controller_to_end<K>( | ||
controller_stream: impl Stream<Item = ReconcileItem<K>>, | ||
) -> impl Future<Output = ()> | ||
where | ||
K: Resource + Debug, | ||
<K as Resource>::DynamicType: Debug, | ||
{ | ||
controller_stream.for_each(|res| async move { | ||
match res { | ||
Ok((obj, action)) => info!(obj = ?obj, action = ?action, "reconcile success"), | ||
Err(err) => warn!(err = ?err, "reconcile failed"), | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
pub mod configuration; | ||
pub mod controller; | ||
pub mod reconcile; | ||
pub mod sink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use kube::{ | ||
runtime::{ | ||
controller::{Action, Error as ControllerError}, | ||
reflector::ObjectRef, | ||
watcher::Error as WatcherError, | ||
}, | ||
Client, | ||
}; | ||
|
||
use crate::configuration::Configuration; | ||
|
||
#[derive(Clone)] | ||
pub struct Context { | ||
/// Kube client. | ||
pub client: Client, | ||
/// Operator configuration. | ||
pub configuration: Configuration, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error("CRD not installed: {0}")] | ||
CrdNotInstalled(String), | ||
#[error("Finalizer error: {0}")] | ||
Finalizer(#[source] Box<kube::runtime::finalizer::Error<Error>>), | ||
#[error("Kube error: {0}")] | ||
Kube(#[from] kube::Error), | ||
} | ||
|
||
pub type ReconcileItem<K> = Result<(ObjectRef<K>, Action), ControllerError<Error, WatcherError>>; |
Oops, something went wrong.