#!/usr/bin/env herodo
// Pre-flight check: Ensure Kubernetes cluster is accessible
try {
    if !run("kubectl cluster-info").execute().success {
        print("SKIPPED: Kubernetes cluster is not accessible");
        exit(0);
    }
} catch(e) {
    print("SKIPPED: Kubernetes cluster is not accessible: " + e);
    exit(0);
}

print("=== Redis Cluster Deployment ===");

let km = kubernetes("rediscluster");

print("Reset namespace 'rediscluster'");
reset_namespace(km, "rediscluster");

print("Deploy Redis Cluster");
let result = deploy_application(km, "rediscluster", "redis:7-alpine", 3, 6379, #{
    "app": "rediscluster",
    "type": "rediscluster",
    "engine": "redis"
}, #{
    "REDIS_PASSWORD": "redispassword",
    "REDIS_PORT": "6379",
    "REDIS_DATABASES": "16",
    "REDIS_MAXMEMORY": "256mb",
    "REDIS_MAXMEMORY_POLICY": "allkeys-lru"
});
print("✓ " + result);

// Get connection information automatically
let conn_info = service_connection_info(km, "rediscluster");

print("\n✅ Redis cluster deployed successfully!");
print("\n📋 Connection Information:");
print("  Service Type: " + conn_info.service_type);
print("  In-cluster host: " + conn_info.hostname);
print("  Port: " + conn_info.ports[0]);
print("  NodePort: " + conn_info.node_ports[0]);
print("  ClusterIP: " + conn_info.cluster_ip);

print("\n🔧 To connect from another pod:");
print("  redis-cli -h " + conn_info.hostname);

print("\n🔧 To connect from Mac host:");
print("  redis-cli -p " + conn_info.node_ports[0]);
