Skip to content

Commit

Permalink
add k8s example structure
Browse files Browse the repository at this point in the history
the internals haven't been implemented yet, but I want an interface to do TDD off of while developing
  • Loading branch information
DominicBurkart committed Sep 30, 2020
1 parent 0682c58 commit 83290a1
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
license = "Hippocratic-2.1"

[features]
distributed = ["chrono", "cached", "async-std", "turbolift_macros/distributed"]
distributed = ["chrono", "async-std", "turbolift_macros/distributed"]
service = ["serde_json"]
# todo we can optimize reqs for children with this load

Expand All @@ -17,6 +17,6 @@ turbolift_macros = { path = "./turbolift_macros" }
turbolift_internals = { path = "./turbolift_internals" }
async-std = { version = "1.6", optional = true }
chrono = { version = "0.4", optional = true }
cached = { version = "0.19", optional = true }
cached = { version = "0.19" }
actix-web = { version = "3" }
serde_json = { version = "1", optional = true }
5 changes: 5 additions & 0 deletions examples/kubernetes_example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ edition = "2018"
"distributed" = ["turbolift/distributed"]

[dependencies]
rand = "0.7"
async-std = "1"
lazy_static = "1"
futures = "0.3"
cute = "0.3"
turbolift = { path="../../" }
4 changes: 3 additions & 1 deletion examples/kubernetes_example/example_runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly test --features "distr

# run
RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly run
RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly run --features "distributed"
RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo +nightly run --features "distributed"

../../kind delete cluster
46 changes: 45 additions & 1 deletion examples/kubernetes_example/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
use std::sync::Mutex;

#[macro_use]
extern crate lazy_static;
#[macro_use(c)]
extern crate cute;
use futures::future::try_join_all;
use rand::{thread_rng, Rng};
use turbolift::kubernetes::K8s;
use turbolift::on;

lazy_static! {
static ref K8S: Mutex<K8s> = Mutex::new(K8s::new());
}

#[on(K8S)]
fn square(u: u64) -> u64 {
u * u
}

fn random_numbers() -> Vec<u64> {
let mut pseud = thread_rng();
c![pseud.gen_range(0, 1000), for _i in 1..10]
}

fn main() {
println!("Hello, world!");
let input = random_numbers();
let futures = c![square(*int), for int in &input];
let output = async_std::task::block_on(try_join_all(futures)).unwrap();
println!("input: {:?}\noutput: {:?}", input, output);
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let input = random_numbers();
let futures = c![square(*int), for int in &input];
let output = async_std::task::block_on(try_join_all(futures)).unwrap();
assert_eq!(
output,
input.into_iter().map(|x| x * x).collect::<Vec<u64>>()
);
}
}
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#[cfg(feature = "distributed")]
pub use async_std;
#[cfg(feature = "distributed")]
pub use cached;
#[cfg(feature = "distributed")]
pub use chrono;

pub use actix_web;
#[cfg(feature = "service")]
pub use serde_json;

pub use actix_web;
pub use cached;

pub use distributed_platform::{DistributionPlatform, DistributionResult};
pub use turbolift_internals::*;
pub use turbolift_macros::*;
7 changes: 7 additions & 0 deletions turbolift_internals/src/kubernetes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ use crate::distributed_platform::{
const K8S_NAMESPACE: &str = "turbolift";
type ImageTag = String;

#[derive(Default)]
pub struct K8s {
pods: Vec<Pod>,
}

impl K8s {
pub fn new() -> K8s {
K8s { pods: Vec::new() }
}
}

#[async_trait]
impl DistributionPlatform for K8s {
async fn declare(&mut self, function_name: &str, project_tar: &[u8]) -> DistributionResult<()> {
Expand Down

0 comments on commit 83290a1

Please sign in to comment.