Queries, k8s.
This commit is contained in:
parent
3250a5adc6
commit
0f20533eaa
|
|
@ -0,0 +1,10 @@
|
||||||
|
SCRIPTPATH=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||||
|
|
||||||
|
export ZENOH_CONFIG=$SCRIPTPATH/peer.yaml
|
||||||
|
# I know I'm hardcoding, but this is just for testing.
|
||||||
|
export PATH=$PATH:/home/jimmy/Develop/zenoh/zenoh/target/release
|
||||||
|
|
||||||
|
run_router() {
|
||||||
|
zenohd --config $SCRIPTPATH/router.yaml
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
FROM registry.fedoraproject.org/fedora:latest AS builder
|
||||||
|
# You must mount the source directory when building. I.E.:
|
||||||
|
# podman build --no-cache -v $PWD:/src -f k8s/Dockerfile -t zenoh-k3s-registry:5000/zenoh-exp .
|
||||||
|
# TODO: Cache the deps piece by making a custom base image. Mounting a volume does not
|
||||||
|
# play nice with caching.
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
RUN sudo dnf update -y && \
|
||||||
|
sudo dnf install -y git curl gcc-c++ openssl-devel
|
||||||
|
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.75.0
|
||||||
|
|
||||||
|
RUN cd /src && \
|
||||||
|
/bin/bash -c "source $HOME/.cargo/env && cargo build --release" && \
|
||||||
|
mkdir /app && \
|
||||||
|
find ./target/release -maxdepth 1 -type f -perm /a+x -not -name "*.so" -not -name "*.rlib" -exec cp {} /app \;
|
||||||
|
|
||||||
|
FROM registry.fedoraproject.org/fedora:latest
|
||||||
|
COPY --from=builder /app/* /usr/local/bin/.
|
||||||
|
RUN useradd -m -s /bin/bash -u 1000 zenoh
|
||||||
|
USER zenoh
|
||||||
|
ENTRYPOINT ["/bin/bash", "-c"]
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
FROM registry.fedoraproject.org/fedora:latest AS builder
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
RUN sudo dnf update -y && \
|
||||||
|
sudo dnf install -y git curl gcc-c++
|
||||||
|
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.75.0
|
||||||
|
|
||||||
|
# Clone and build
|
||||||
|
RUN git clone https://github.com/eclipse-zenoh/zenoh.git /zenoh-src && \
|
||||||
|
cd /zenoh-src && \
|
||||||
|
/bin/bash -c "source $HOME/.cargo/env && cargo build --release" && \
|
||||||
|
mkdir /zenoh && \
|
||||||
|
mv ./target/release/*.so /zenoh/. && \
|
||||||
|
mv ./target/release/zenohd /zenoh/.
|
||||||
|
|
||||||
|
FROM registry.fedoraproject.org/fedora:latest
|
||||||
|
COPY --from=builder /zenoh/zenohd /usr/local/bin/.
|
||||||
|
COPY --from=builder /zenoh/*.so /usr/local/lib/.
|
||||||
|
RUN useradd -m -s /bin/bash -u 1000 zenoh
|
||||||
|
USER zenoh
|
||||||
|
ENTRYPOINT ["zenohd"]
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
FROM docker.io/library/ubuntu:22.04
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
RUN echo "wireshark-common wireshark-common/install-setuid boolean true" | debconf-set-selections && \
|
||||||
|
apt update && \
|
||||||
|
apt install -y software-properties-common && \
|
||||||
|
add-apt-repository -y ppa:wireshark-dev/stable && \
|
||||||
|
apt install -y wireshark-dev tshark && \
|
||||||
|
apt install -y --allow-change-held-packages wireshark
|
||||||
|
RUN apt install -y git curl g++ libssl-dev
|
||||||
|
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.75.0
|
||||||
|
RUN useradd -m -s /bin/bash -u 1000 -G wireshark zenoh
|
||||||
|
|
||||||
|
# Clone and build
|
||||||
|
RUN git clone https://github.com/ZettaScaleLabs/zenoh-dissector.git /zenoh && \
|
||||||
|
cd /zenoh && \
|
||||||
|
git checkout dev/1.0.0 && \
|
||||||
|
/bin/bash -c "source $HOME/.cargo/env && cargo build --release"
|
||||||
|
|
||||||
|
# Install
|
||||||
|
USER zenoh
|
||||||
|
RUN mkdir -p ~/.local/lib/wireshark/plugins/4.4/epan && \
|
||||||
|
cp /zenoh/target/release/libzenoh_dissector.so ~/.local/lib/wireshark/plugins/4.4/epan/libzenoh_dissector.so
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
apiVersion: k3d.io/v1alpha4
|
||||||
|
kind: Simple
|
||||||
|
metadata:
|
||||||
|
name: zenoh
|
||||||
|
servers: 1
|
||||||
|
agents: 0
|
||||||
|
registries:
|
||||||
|
create:
|
||||||
|
name: zenoh-k3s-registry
|
||||||
|
host: "0.0.0.0"
|
||||||
|
hostPort: "5000"
|
||||||
|
ports:
|
||||||
|
- port: 7447:7447
|
||||||
|
- port: 80:8080
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: zenoh-conf
|
||||||
|
data:
|
||||||
|
peer.yaml: |
|
||||||
|
mode: peer
|
||||||
|
listen:
|
||||||
|
endpoints:
|
||||||
|
- "tcp/0.0.0.0:1223"
|
||||||
|
connect:
|
||||||
|
endpoints:
|
||||||
|
- "tcp/zenohd-zenoh-service.default.svc.cluster.local:7447"
|
||||||
|
scouting:
|
||||||
|
multicast:
|
||||||
|
enabled: false
|
||||||
|
gossip:
|
||||||
|
enabled: true
|
||||||
|
routing:
|
||||||
|
router:
|
||||||
|
peers_failover_brokering: true
|
||||||
|
peer:
|
||||||
|
mode: linkstate
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: zenoh-publisher-deployment
|
||||||
|
labels:
|
||||||
|
app: zenoh-publisher
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: zenoh-publisher
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: zenoh-publisher
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: publisher
|
||||||
|
image: zenoh-k3s-registry:5000/zenoh-exp:latest
|
||||||
|
args: ["pub"]
|
||||||
|
env:
|
||||||
|
- name: ZENOH_CONFIG
|
||||||
|
value: "/opt/zenoh/peer.yaml"
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /opt/zenoh
|
||||||
|
name: zenoh-conf
|
||||||
|
ports:
|
||||||
|
- containerPort: 1223
|
||||||
|
name: zenoh-port
|
||||||
|
volumes:
|
||||||
|
- name: zenoh-conf
|
||||||
|
configMap:
|
||||||
|
name: zenoh-conf
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
resources:
|
||||||
|
- configmap.yaml
|
||||||
|
- deployment.yaml
|
||||||
|
- service.yaml
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: zenoh-publisher-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: zenoh-publisher
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 1223
|
||||||
|
name: zenoh-port
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: zenohd-conf
|
||||||
|
data:
|
||||||
|
router.yaml: |
|
||||||
|
mode: router
|
||||||
|
listen:
|
||||||
|
endpoints:
|
||||||
|
- "tcp/0.0.0.0:7447"
|
||||||
|
scouting:
|
||||||
|
multicast:
|
||||||
|
enabled: false
|
||||||
|
gossip:
|
||||||
|
enabled: true
|
||||||
|
multihop: true
|
||||||
|
routing:
|
||||||
|
router:
|
||||||
|
peers_failover_brokering: true
|
||||||
|
peer:
|
||||||
|
mode: linkstate
|
||||||
|
plugins_loading:
|
||||||
|
enabled: true
|
||||||
|
plugins:
|
||||||
|
rest:
|
||||||
|
__required__: true
|
||||||
|
http_port: 8000
|
||||||
|
storage_manager:
|
||||||
|
storages:
|
||||||
|
primary_memory:
|
||||||
|
key_expr: "**"
|
||||||
|
volume: memory
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: zenohd-deployment
|
||||||
|
labels:
|
||||||
|
app: zenohd
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: zenohd
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: zenohd
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: zenohd
|
||||||
|
image: zenoh-k3s-registry:5000/zenoh-router:latest
|
||||||
|
args: ["-c", "/opt/zenohd/router.yaml"]
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /opt/zenohd
|
||||||
|
name: zenohd-conf
|
||||||
|
ports:
|
||||||
|
- containerPort: 8000
|
||||||
|
name: rest-port
|
||||||
|
- containerPort: 8001
|
||||||
|
name: websocket-port
|
||||||
|
- containerPort: 7447
|
||||||
|
name: zenoh-port
|
||||||
|
volumes:
|
||||||
|
- name: zenohd-conf
|
||||||
|
configMap:
|
||||||
|
name: zenohd-conf
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
resources:
|
||||||
|
- configmap.yaml
|
||||||
|
- deployment.yaml
|
||||||
|
- service.yaml
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: zenohd-zenoh-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: zenohd
|
||||||
|
type: LoadBalancer
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 7447
|
||||||
|
name: zenoh-port
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: zenohd-web-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: zenohd
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 8000
|
||||||
|
name: rest-port
|
||||||
|
- protocol: TCP
|
||||||
|
port: 8001
|
||||||
|
name: websocket-port
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
`sudo podman run --rm -it --net=host --privileged -v /tmp:/tmp localhost/zenoh-wireshark:latest bash`
|
||||||
|
`tshark -i loopback -w output.pcap`
|
||||||
|
`tshark -r output.pcap -V | more`
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
ZENOH_CONFIG=config/peer.yaml ./target/debug/pub
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
ZENOH_CONFIG=config/peer.yaml ./target/debug/sub_callback
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
ZENOH_CONFIG=config/peer.yaml ./target/debug/sub
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#[tokio::main]
|
||||||
|
|
||||||
|
async fn main() {
|
||||||
|
let config = zenoh::Config::from_env().unwrap();
|
||||||
|
let session = zenoh::open(config).await.unwrap();
|
||||||
|
|
||||||
|
let replies = session.get("name").await.unwrap();
|
||||||
|
while let Ok(reply) = replies.recv_async().await {
|
||||||
|
let result = reply.result().unwrap();
|
||||||
|
println!(
|
||||||
|
"Got: {:?}",
|
||||||
|
result.payload().deserialize::<String>().unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,28 +2,9 @@ use anyhow::anyhow;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
fn build_message1() -> Result<Vec<u8>> {
|
|
||||||
let mut message = zenoh_exp::Message::default();
|
|
||||||
message.sender = "pub".to_string();
|
|
||||||
message.message = "Hi sub!".to_string();
|
|
||||||
let mut buff: Vec<u8> = Vec::new();
|
|
||||||
let _ = ciborium::into_writer(&message, &mut buff)?;
|
|
||||||
|
|
||||||
return Ok(buff);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_message2() -> Result<Vec<u8>> {
|
|
||||||
let mut message = zenoh_exp::Message::default();
|
|
||||||
message.sender = "pub".to_string();
|
|
||||||
message.message = "yo sub!".to_string();
|
|
||||||
let mut buff: Vec<u8> = Vec::new();
|
|
||||||
let _ = ciborium::into_writer(&message, &mut buff)?;
|
|
||||||
|
|
||||||
return Ok(buff);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
zenoh::init_log_from_env_or("error");
|
||||||
let config = zenoh::Config::from_env().map_err(|e| anyhow!(e))?;
|
let config = zenoh::Config::from_env().map_err(|e| anyhow!(e))?;
|
||||||
let session = zenoh::open(config).await.map_err(|e| anyhow!(e))?;
|
let session = zenoh::open(config).await.map_err(|e| anyhow!(e))?;
|
||||||
let test_publisher = session
|
let test_publisher = session
|
||||||
|
|
@ -53,3 +34,23 @@ async fn main() -> Result<()> {
|
||||||
tokio::time::sleep(Duration::from_secs_f32(0.5)).await;
|
tokio::time::sleep(Duration::from_secs_f32(0.5)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_message1() -> Result<Vec<u8>> {
|
||||||
|
let mut message = zenoh_exp::Message::default();
|
||||||
|
message.sender = "pub".to_string();
|
||||||
|
message.message = "Hi sub!".to_string();
|
||||||
|
let mut buff: Vec<u8> = Vec::new();
|
||||||
|
let _ = ciborium::into_writer(&message, &mut buff)?;
|
||||||
|
|
||||||
|
return Ok(buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_message2() -> Result<Vec<u8>> {
|
||||||
|
let mut message = zenoh_exp::Message::default();
|
||||||
|
message.sender = "pub".to_string();
|
||||||
|
message.message = "yo sub!".to_string();
|
||||||
|
let mut buff: Vec<u8> = Vec::new();
|
||||||
|
let _ = ciborium::into_writer(&message, &mut buff)?;
|
||||||
|
|
||||||
|
return Ok(buff);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let config = zenoh::Config::from_env().unwrap();
|
||||||
|
let session = zenoh::open(config).await.unwrap();
|
||||||
|
|
||||||
|
let queryable = session
|
||||||
|
.declare_queryable("name")
|
||||||
|
.with(zenoh::handlers::RingChannel::new(1))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
while let Ok(query) = queryable.recv_async().await {
|
||||||
|
let reply = "hi!";
|
||||||
|
query.reply(query.key_expr().as_str(), reply).await.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
zenoh::init_log_from_env_or("error");
|
||||||
let config = zenoh::Config::from_env().map_err(|e| anyhow!(e))?;
|
let config = zenoh::Config::from_env().map_err(|e| anyhow!(e))?;
|
||||||
let session = zenoh::open(config).await.map_err(|e| anyhow!(e))?;
|
let session = zenoh::open(config).await.map_err(|e| anyhow!(e))?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue