#!/usr/bin/env herodo
//! Kubernetes Basic Operations
//! Demonstrates creating and managing Kubernetes resources using fluent API

let k = kubernetes();

print("=== Kubernetes Resources ===");
print(k.md()); // markdown view of all namespaces

// Reset entire cluster
print("\n=== Reset Cluster ===");
k.reset();

// Create namespace and resources
print("\n=== Create Namespace and Resources ===");
let ns = k.namespace("demo");
ns.reset();

// ConfigMap
ns.configmap("app-config")
    .set("app_name", "myapp")
    .set("debug", "true")
    .apply();

// Secret
ns.secret("app-secrets")
    .set("api_key", "secret123")
    .set("db_password", "pass456")
    .apply();

// Pod
let pod = ns.pod("app-pod")
    .image("nginx:latest")
    .env("APP_NAME", "myapp")
    // .env_from_configmap("app-config")  // Optional: import config as env vars
    // .env_from_secret("app-secrets")    // Optional: import secrets as env vars
    .label("app", "myapp")
    .port(80)
    // .memory(128, 512)                  // Optional: request/limit in MB
    // .cpu(500, 2000)                    // Optional: request/limit in millicores
    .apply();

print("Pod created");

// Service
ns.service("web-service")
    .selector("app", "myapp")
    .expose(80).to_container(8080)
    // .nodeport()                        // Optional: expose via NodePort
    // .via_node(30080)                   // Optional: node port number
    .apply();

print("Service created");

// Summary
print("\n=== Summary ===");
print("Pods: " + ns.pods_list());
print("Services: " + ns.services_list());
print("ConfigMaps: " + ns.configmaps_list());
print("Secrets: " + ns.secrets_list());
