# KCL Dependency configuration for cilium taskserv
# Defines comprehensive dependency, resource, and health requirements

import provisioning.dependencies as schema

# Cilium taskserv dependency configuration
_dependencies = schema.TaskservDependencies {
    name = "cilium"

    # Critical dependencies - must be installed first
    requires = ["kubernetes", "containerd"]

    # Optional enhancements - install if available
    optional = ["coredns", "proxy"]

    # Cannot coexist with other CNI solutions
    conflicts = ["calico", "flannel", "weave"]

    # Services provided by this taskserv
    provides = ["cni", "network-policy", "load-balancer", "service-mesh", "hubble-ui"]

    # Resource requirements for Cilium installation
    resources = schema.ResourceRequirement {
        cpu = "500m"            # 500m CPU for network processing
        memory = "512Mi"        # 512MB RAM for network state
        disk = "2Gi"           # 2GB for logs and network data
        network = True          # Core network functionality
        privileged = True       # Needs privileged access for network operations
    }

    # Health checks for Cilium components
    health_checks = [
        schema.HealthCheck {
            command = "kubectl get pods -n kube-system -l k8s-app=cilium | grep -v Running | wc -l | grep -q '^0$'"
            interval = 60
            timeout = 15
            retries = 3
            success_threshold = 2
            failure_threshold = 3
        },
        schema.HealthCheck {
            command = "kubectl exec -n kube-system ds/cilium -- cilium status | grep -q 'OK'"
            interval = 120
            timeout = 20
            retries = 3
        },
        schema.HealthCheck {
            command = "kubectl get ciliumnodeconfig -A | wc -l | grep -v '^0$'"
            interval = 180
            timeout = 10
            retries = 2
        }
    ]

    # Readiness probe for installation completion
    readiness_probe = schema.HealthCheck {
        command = "kubectl get nodes -o jsonpath='{.items[*].status.conditions[?(@.type==\"Ready\")].status}' | grep -v True | wc -l | grep -q '^0$'"
        interval = 30
        timeout = 10
        retries = 8
        success_threshold = 3
    }

    # Installation phases for ordered deployment
    phases = [
        schema.InstallationPhase {
            name = "pre-install"
            order = 1
            parallel = False
            required = True
        },
        schema.InstallationPhase {
            name = "install"
            order = 2
            parallel = False
            required = True
        },
        schema.InstallationPhase {
            name = "post-install"
            order = 3
            parallel = True
            required = True
        },
        schema.InstallationPhase {
            name = "validate"
            order = 4
            parallel = False
            required = True
        }
    ]

    # Installation control
    timeout = 600               # 10 minutes for CNI setup
    retry_count = 3

    # Platform compatibility
    os_support = ["linux"]
    arch_support = ["amd64", "arm64"]
    k8s_versions = ["1.31.x", "1.30.x", "1.29.x", "1.28.x"]
}

# Output for dynamic dependency resolution
_dependencies