feat(k8s): add Kubernetes Helm chart for emailks service

- Create Helm chart structure with Chart.yaml and values.yaml
- Add deployment template with container configuration and environment variables
- Implement service template for gRPC port exposure
- Add service account template with security configuration
- Include horizontal pod autoscaler template for scaling capabilities
- Add helper templates for naming and label management
- Configure SMTP settings as configurable parameters in values.yaml
- Set up resource limits and requests for container performance
- Implement liveness and readiness probes for health checks
- Add support for existing secrets and custom configurations
This commit is contained in:
zhenyi
2026-06-07 22:59:06 +08:00
parent d0852ad131
commit c4824ef261
17 changed files with 353 additions and 33 deletions
+30 -8
View File
@@ -7,6 +7,7 @@ use std::sync::{
Arc,
atomic::{AtomicUsize, Ordering},
};
use tokio::sync::Notify;
fn dummy_request() -> SendEmailRequest {
SendEmailRequest {
@@ -29,6 +30,8 @@ async fn enqueue_and_consume_success() {
let (queue, worker) = EmailQueue::unbounded();
let counter = Arc::new(AtomicUsize::new(0));
let c = counter.clone();
let notify = Arc::new(Notify::new());
let n = notify.clone();
let mut req = dummy_request();
req.to.push(EmailAddress {
@@ -41,14 +44,16 @@ async fn enqueue_and_consume_success() {
worker.spawn(move |_job| {
let c = c.clone();
let n = n.clone();
async move {
c.fetch_add(1, Ordering::SeqCst);
n.notify_one();
Ok::<(), EmailError>(())
}
});
// Wait for async consumption
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
// Wait for async consumption with proper signalling
notify.notified().await;
assert_eq!(counter.load(Ordering::SeqCst), 1);
}
@@ -57,22 +62,27 @@ async fn retry_then_succeed() {
let (queue, worker) = EmailQueue::unbounded();
let attempts = Arc::new(AtomicUsize::new(0));
let a = attempts.clone();
let notify = Arc::new(Notify::new());
let n = notify.clone();
let _id = queue.enqueue(dummy_request()).unwrap();
worker.spawn(move |_job| {
let a = a.clone();
let n = n.clone();
async move {
let n = a.fetch_add(1, Ordering::SeqCst);
if n < 2 {
let count = a.fetch_add(1, Ordering::SeqCst);
if count < 2 {
Err(EmailError::Send("temp failure".into()))
} else {
n.notify_one();
Ok(())
}
}
});
tokio::time::sleep(std::time::Duration::from_millis(700)).await;
// Wait for final success notification
notify.notified().await;
assert_eq!(attempts.load(Ordering::SeqCst), 3); // 2 fails + 1 success
}
@@ -82,18 +92,22 @@ async fn terminal_error_destroyed_immediately() {
let store = queue.status_store().clone();
let attempts = Arc::new(AtomicUsize::new(0));
let a = attempts.clone();
let notify = Arc::new(Notify::new());
let n = notify.clone();
let id = queue.enqueue(dummy_request()).unwrap();
worker.spawn(move |_job| {
let a = a.clone();
let n = n.clone();
async move {
a.fetch_add(1, Ordering::SeqCst);
n.notify_one();
Err(EmailError::MissingRecipients)
}
});
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
notify.notified().await;
assert_eq!(attempts.load(Ordering::SeqCst), 1);
let entry = store.get(id).expect("should have status entry");
@@ -113,15 +127,23 @@ async fn bounded_channel_blocks_when_full() {
async fn status_store_tracks_lifecycle() {
let (queue, worker) = EmailQueue::unbounded();
let store = queue.status_store().clone();
let notify = Arc::new(Notify::new());
let n = notify.clone();
let id = queue.enqueue(dummy_request()).unwrap();
// Status should be Queued
let entry = store.get(id).unwrap();
assert_eq!(entry.status, emailks::pb::email::v1::SendStatus::Queued);
worker.spawn(move |_job| async move { Ok::<(), EmailError>(()) });
worker.spawn(move |_job| {
let n = n.clone();
async move {
n.notify_one();
Ok::<(), EmailError>(())
}
});
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
notify.notified().await;
let entry = store.get(id).unwrap();
assert_eq!(entry.status, emailks::pb::email::v1::SendStatus::Sent);
}