# Placeholder deployment that KEDA scales based on Argo queue depth.
# When scaled up, these pods request resources on the high-compute pool,
# triggering the Civo cluster autoscaler to add nodes.
apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
  name: argo-queue-placeholder
  namespace: crossplane-system
spec:
  providerConfigRef:
    name: kubernetes-provider
  forProvider:
    manifest:
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: argo-queue-placeholder
        namespace: argo
      spec:
        replicas: 0
        selector:
          matchLabels:
            app: argo-queue-placeholder
        template:
          metadata:
            labels:
              app: argo-queue-placeholder
          spec:
            nodeSelector:
              kubernetes.civo.com/node-pool: high-compute
            tolerations:
            - key: "kubernetes.civo.com/node-pool"
              operator: "Equal"
              value: "high-compute"
              effect: "NoSchedule"
            terminationGracePeriodSeconds: 0
            containers:
            - name: placeholder
              image: busybox
              command: ["sleep", "infinity"]
              resources:
                requests:
                  cpu: "1"
                  memory: 1Gi
---
# KEDA ScaledObject - scales placeholder based on pending Argo workflow pods.
# When workflows are submitted, their pods land in Pending state (no nodes).
# KEDA sees the pending pods and scales up the placeholder deployment,
# which also targets high-compute nodes, adding pressure for the cluster
# autoscaler to provision new nodes.
apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
  name: argo-queue-scaledobject
  namespace: crossplane-system
spec:
  providerConfigRef:
    name: kubernetes-provider
  forProvider:
    manifest:
      apiVersion: keda.sh/v1alpha1
      kind: ScaledObject
      metadata:
        name: argo-queue-scaler
        namespace: argo
      spec:
        scaleTargetRef:
          name: argo-queue-placeholder
        pollingInterval: 15
        cooldownPeriod: 300
        minReplicaCount: 0
        maxReplicaCount: 5
        triggers:
        - type: kubernetes-workload
          metadata:
            podSelector: "workflows.argoproj.io/completed=false"
            namespace: "argo"
            value: "1"
