Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate end to end testing #20

Merged
merged 11 commits into from
Jul 5, 2024
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,33 @@ jobs:

- name: Run Unit Tests
run: cargo test --lib

integration:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
cluster_name: "k8scluster"

- name: Build RPC
run: docker build -t rpc:1.0 -f docker/dockerfile.rpc .

- name: Load Docker Image
run: kind load docker-image rpc:1.0 --name k8scluster

- name: Build Daemon
run: docker build -t daemon:1.0 -f docker/dockerfile.daemon .

- name: Load Docker Image
run: kind load docker-image daemon:1.0 --name k8scluster

- name: Apply main manifest
run: kubectl apply -f test/manifest.yaml

- name: Validate
run: ./test/expect

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
dev.db*
rpc.toml
daemon.toml
grpcurl*
2 changes: 1 addition & 1 deletion src/bin/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() -> Result<()> {

futures::future::try_join(
fabric::drivers::grpc::server(&config.addr, &config.db_path, &config.brokers),
fabric::drivers::event::subscribe(&config.brokers),
fabric::drivers::event::subscribe(&config.db_path, &config.brokers),
)
.await?;

Expand Down
4 changes: 2 additions & 2 deletions src/drivers/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::{
driven::cache::{project::SqliteProjectCache, SqliteCache},
};

pub async fn subscribe(brokers: &str) -> Result<()> {
let sqlite_cache = Arc::new(SqliteCache::new(Path::new("dev.db")).await?);
pub async fn subscribe(db_path: &str, brokers: &str) -> Result<()> {
let sqlite_cache = Arc::new(SqliteCache::new(Path::new(db_path)).await?);
sqlite_cache.migrate().await?;

let project_cache = Arc::new(SqliteProjectCache::new(sqlite_cache));
Expand Down
41 changes: 0 additions & 41 deletions test/child.yaml

This file was deleted.

36 changes: 36 additions & 0 deletions test/expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
wget https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_x86_64.tar.gz
tar -zxvf ./grpcurl_1.9.1_linux_x86_64.tar.gz grpcurl

echo "Waiting for kafka to be ready..."

while true; do
pod_status=$(kubectl get pods -n demeter-kafka -o 'jsonpath={.items[*].status.conditions[?(@.type=="Ready")].status}' | grep True)

if [[ -n "$pod_status" ]]; then
break
else
echo "Kafka is not ready yet, waiting..."
sleep 5
fi
done

NODE_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
NAMESPACE=$(./grpcurl -plaintext -d '{"name": "New Namespace"}' "$NODE_IP":30950 demeter.ops.v1alpha.ProjectService.CreateProject | jq -r '.namespace')
ATTEMPT=1
MAX_ATTEMPT=120

echo "Checking executation"
while [ $ATTEMPT -lt $MAX_ATTEMPT ]; do
if kubectl get namespace "$NAMESPACE" &> /dev/null; then
echo "Namespace $NAMESPACE exists."
break
else
echo "Namespace $NAMESPACE not found. Retrying..."
sleep 2
let ATTEMPT=ATTEMPT+1
fi
done

if [ $ATTEMPT -eq $MAX_ATTEMPT ]; then
echo "Error: Namespace $NAMESPACE not found after $MAX_ATTEMPT attempts."
fi
6 changes: 0 additions & 6 deletions test/main.yaml

This file was deleted.

208 changes: 208 additions & 0 deletions test/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# Kafka
apiVersion: v1
kind: Namespace
metadata:
name: demeter-kafka
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redpanda
namespace: demeter-kafka
labels:
app: redpanda
spec:
selector:
matchLabels:
app: redpanda
template:
metadata:
labels:
app: redpanda
spec:
containers:
- name: redpanda
image: docker.redpanda.com/redpandadata/redpanda:latest
args:
- redpanda
- start
- --kafka-addr internal://localhost:9092,external://0.0.0.0:19092
- --advertise-kafka-addr internal://localhost:9092,external://redpanda.demeter-kafka.svc.cluster.local:19092
- --pandaproxy-addr internal://localhost:8082,external://0.0.0.0:18082
- --advertise-pandaproxy-addr internal://localhost:8082,external://redpanda.demeter-kafka.svc.cluster.local:18082
- --schema-registry-addr internal://localhost:8081,external://0.0.0.0:18081
- --rpc-addr localhost:33145
- --advertise-rpc-addr localhost:33145
- --mode dev-container
- --smp 1
- --default-log-level=debug

ports:
- containerPort: 19092
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", " rpk topic create events"]
---
apiVersion: v1
kind: Service
metadata:
name: redpanda
namespace: demeter-kafka
labels:
app: redpanda
spec:
selector:
app: redpanda
type: ClusterIP
ports:
- name: redpanda
port: 19092
targetPort: 19092
protocol: TCP
---
# Daemon
apiVersion: v1
kind: Namespace
metadata:
name: demeter-daemon
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kube-rs
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kube-rs
namespace: demeter-daemon
automountServiceAccountToken: true
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kube-rs-binding
namespace: demeter-daemon
subjects:
- kind: ServiceAccount
namespace: demeter-daemon
name: kube-rs
- kind: Group
name: system:serviceaccounts
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: kube-rs
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
data:
daemon.toml: |
brokers="redpanda.demeter-kafka.svc.cluster.local:19092"
kind: ConfigMap
metadata:
name: daemon-config
namespace: demeter-daemon
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: daemon
namespace: demeter-daemon
labels:
app: daemon
spec:
selector:
matchLabels:
app: daemon
template:
metadata:
labels:
app: daemon
spec:
containers:
- name: daemon
image: daemon:1.0
env:
- name: DAEMON_CONFIG
value: "/fabric/daemon.toml"
volumeMounts:
- name: daemon-vol
mountPath: /fabric
volumes:
- name: daemon-vol
configMap:
name: daemon-config
---

# RPC
apiVersion: v1
kind: Namespace
metadata:
name: demeter-rpc
---
apiVersion: v1
data:
rpc.toml: |
addr="0.0.0.0:80"
db_path="test.db"
brokers="redpanda.demeter-kafka.svc.cluster.local:19092"
kind: ConfigMap
metadata:
name: rpc-config
namespace: demeter-rpc
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: rpc
namespace: demeter-rpc
labels:
app: rpc
spec:
selector:
matchLabels:
app: rpc
template:
metadata:
labels:
app: rpc
spec:
containers:
- name: rpc
image: rpc:1.0
ports:
- containerPort: 80
env:
- name: RPC_CONFIG
value: "/fabric/rpc.toml"
volumeMounts:
- name: rpc-vol
mountPath: /fabric
volumes:
- name: rpc-vol
configMap:
name: rpc-config
---
apiVersion: v1
kind: Service
metadata:
name: rpc
namespace: demeter-rpc
labels:
app: rpc
spec:
selector:
app: rpc
type: NodePort
ports:
- name: rpc
port: 80
targetPort: 80
nodePort: 30950
protocol: TCP
12 changes: 12 additions & 0 deletions test/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

kind create cluster --name k8scluster

docker build -t rpc:1.0 -f docker/dockerfile.rpc .
kind load docker-image rpc:1.0 --name k8scluster

docker build -t daemon:1.0 -f docker/dockerfile.daemon .
kind load docker-image daemon:1.0 --name k8scluster

kubectl apply -f ./test/manifest.yaml
./test/expect
Loading