diff --git a/README.md b/README.md index 25d41724..64e057d7 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,8 @@ Enables agents to safely execute code and run arbitrary actions in isolated envi **Optional provider:** [NVIDIA OpenShell](docs/openshell.md) — policy-enforced sandboxes on top of Agent Sandbox (egress default-deny, L7 rules, Landlock, credential isolation with GenAI Gateway keys). Enable with `openshell_enabled: true` in `config.agent-toolkit.yaml`. +**Optional benchmarking:** [AgentSysPerf](docs/agentsysperf.md) — scored agent benchmarks and concurrency ladders with their system cost, on its own dashboard, Grafana and Langfuse. Enable with `agentsysperf_enabled: true` in `config.agent-toolkit.yaml`. + --- ### Memory, State & Context diff --git a/charts/pgvector/templates/statefulset.yaml b/charts/pgvector/templates/statefulset.yaml index 6fc6bb53..e6d2d9f5 100644 --- a/charts/pgvector/templates/statefulset.yaml +++ b/charts/pgvector/templates/statefulset.yaml @@ -61,9 +61,10 @@ spec: - name: init-scripts mountPath: /docker-entrypoint-initdb.d # initdb on slow storage (NFS) can outlast the liveness window; a restart mid-init leaves a broken cluster + # Over TCP: the image's temporary init server listens on the socket only, and stops after the init scripts. startupProbe: exec: - command: [pg_isready, -U, postgres] + command: [pg_isready, -h, 127.0.0.1, -U, postgres] periodSeconds: 10 failureThreshold: 90 livenessProbe: @@ -74,7 +75,7 @@ spec: failureThreshold: 3 readinessProbe: exec: - command: [pg_isready, -U, postgres] + command: [pg_isready, -h, 127.0.0.1, -U, postgres] initialDelaySeconds: 10 periodSeconds: 10 failureThreshold: 3 diff --git a/components.yaml b/components.yaml index 111d263d..f13f38a0 100644 --- a/components.yaml +++ b/components.yaml @@ -47,3 +47,27 @@ components: layer: agent-toolkit enabled: "{{ kuberay_enabled | default(false) | bool }}" depends_on: [] + + # AgentSysPerf (agentsysperf_enabled): benchmarks agents on this layer from the unmodified + # ext/agentsysperf checkout. Teardown always plans them, so switching off strands nothing. + - name: asp_platform + layer: agent-toolkit + teardown: both + enabled: "{{ (agentsysperf_enabled | default(false) | bool) or (component_action | default('install')) == 'teardown' }}" + depends_on: [pgvector, agent_sandbox] + + - name: asp_images + layer: agent-toolkit + teardown: both + enabled: >- + {{ ((agentsysperf_enabled | default(false) | bool) and (agentsysperf_image_source | default('build')) == 'build') + or (component_action | default('install')) == 'teardown' }} + depends_on: [asp_platform] + + - name: asp_dashboard + layer: agent-toolkit + teardown: both + enabled: >- + {{ ((agentsysperf_enabled | default(false) | bool) and (agentsysperf_dashboard_enabled | default(true) | bool)) + or (component_action | default('install')) == 'teardown' }} + depends_on: [asp_platform, asp_images] diff --git a/config.yaml b/config.yaml index f750482a..d48c8fd3 100644 --- a/config.yaml +++ b/config.yaml @@ -68,6 +68,18 @@ kuberay_enabled: false kuberay_namespace: "ray-system" kuberay_operator_version: "1.3.0" +# --- AgentSysPerf (optional) --- +# Agent benchmarking on this cluster: result store on pgvector, a LiteLLM key, the driver's +# RBAC and the dashboard. Runs: helm install ext/agentsysperf/deploy/chart -f . +agentsysperf_enabled: false # needs ext/agentsysperf (init agent-toolkit clones it) +agentsysperf_image_source: "build" # build: on the nodes from ext/agentsysperf | registry +agentsysperf_dashboard_enabled: true # https://agent-sysperf./, Keycloak sign-in +agentsysperf_dashboard_allowed_groups: [] # Keycloak groups; empty: the platform admin group +# agentsysperf_llm_model: "qwen2-5-coder-14b" # unset: the first model in llm_services_autodeploy_models +agentsysperf_driver_node: "" # pin the driver to this node; empty: any node with the images +agentsysperf_sandbox_nodes: [] # task-pod nodes for run-streams ladders; empty: the driver's node +agentsysperf_teardown_delete_results: false # true: teardown also drops the results database + # --- Istio mesh --- # Namespaces LiteLLM admits; add your own ambient-labelled agent namespace here. litellm_allowed_namespaces: diff --git a/docs/agentsysperf.md b/docs/agentsysperf.md new file mode 100644 index 00000000..b3ae73c2 --- /dev/null +++ b/docs/agentsysperf.md @@ -0,0 +1,67 @@ +# AgentSysPerf (Agent Benchmarking) + +[AgentSysPerf](https://github.com/intel/agentsysperf) benchmarks agents on this cluster. It records +scored Terminal-Bench runs and concurrency ladders together with their system cost, and shows them +on its own dashboard, in Grafana and in Langfuse. + +The toolkit installs and wires it; AgentSysPerf itself is used unmodified. Toolkit Manager's +`init agent-toolkit` clones it into `ext/agentsysperf` at the release pinned in +`configs/repos/repos.agent-toolkit.yaml`, and three components of this layer (`asp_platform`, +`asp_images`, `asp_dashboard`) set it up from that checkout. + +## Turn it on + +1. In `env//config.agent-toolkit.yaml`, set `agentsysperf_enabled: true`. An env created before + this release has no AgentSysPerf section: add the line. +2. Install as usual: `./toolkit_manager.sh install agent-toolkit --env `. An env inited before + this release must run `init agent-toolkit` once more, so that `ext/agentsysperf` is cloned. + +It needs `pgvector_enabled` and `agent_sandbox_enabled` (both on by default). LiteLLM +(`auth_type: litellm_vkey`), Langfuse and observability are used when present. The install stops +on OpenShift, and on `routing_mode: path` while the dashboard is on. + +## Settings + +All in the AgentSysPerf section of `env//config.agent-toolkit.yaml`: + +| Key | Default | Purpose | +|---|---|---| +| `agentsysperf_enabled` | `false` | The switch | +| `agentsysperf_image_source` | `build` | `build`: on the nodes from `ext/agentsysperf`; `registry`: published images | +| `agentsysperf_dashboard_enabled` | `true` | Dashboard at `https://agent-sysperf./`, Keycloak sign-in | +| `agentsysperf_dashboard_allowed_groups` | `[]` | Keycloak groups that may open it; empty: the platform admin group | +| `agentsysperf_llm_model` | first of `llm_services_autodeploy_models` | Model the driver calls through LiteLLM | +| `agentsysperf_driver_node` | `""` | Pin the driver to this node; empty: any node with the images | +| `agentsysperf_sandbox_nodes` | `[]` | Task-pod nodes for run-streams ladders; empty: the driver's node | +| `agentsysperf_teardown_delete_results` | `false` | `true`: teardown also drops the results database | + +While it is on, pgvector gets 600 connections and 8 GiB (run-streams ladders hold one connection +per slot). + +## What the install adds + +- a results database `aspdb` on the toolkit's pgvector +- a non-admin LiteLLM key (alias `agent-sysperf-driver`) +- the driver's ServiceAccount, RBAC and router token in `agent-sandbox-system` +- the cluster contract, ConfigMap `asp-cluster-env` (in `agent-sysperf` and `agent-sandbox-system`), which every run reads +- a Pushgateway and Grafana dashboards +- the images, built once and loaded on every node (`agentsysperf.intel.com/images` node label) +- the dashboard behind the gateway's Keycloak sign-in + +## Run a benchmark + +From the AgentSysPerf checkout: + +```bash +cd ext/agentsysperf +helm install smoke deploy/chart -n agent-sandbox-system -f deploy/chart/presets/smoke.yaml +helm install tb1 deploy/chart -n agent-sandbox-system -f deploy/chart/presets/tb2-gateway.yaml +``` + +The presets are described in `ext/agentsysperf/docs/TOOLKIT_ONBOARDING.md`. Runs started with +`helm install` are yours: teardown leaves their releases and Job pods. + +## Teardown + +`teardown agent-toolkit` (or `teardown asp_platform`) removes everything the install added and +revokes the LiteLLM key. It keeps the results database unless `agentsysperf_teardown_delete_results: true`. diff --git a/roles/agent_sandbox/tasks/install.yaml b/roles/agent_sandbox/tasks/install.yaml index 087848fa..3e2a6f0e 100644 --- a/roles/agent_sandbox/tasks/install.yaml +++ b/roles/agent_sandbox/tasks/install.yaml @@ -81,6 +81,31 @@ vars: _authz_args: "- --cache-enabled=true\n - --authz-mode=tokenreview\n - --authz-tokenreview-require-token=true" +# Ambient mesh callers reach the router as HBONE on 15008, which the upstream policy does not admit. +- name: "agent_sandbox | Admit mesh callers to the sandbox-router (HBONE)" + kubernetes.core.k8s: + state: present + definition: + apiVersion: networking.k8s.io/v1 + kind: NetworkPolicy + metadata: + name: eat-sandbox-router-mesh + namespace: "{{ agent_sandbox_namespace }}" + labels: + app.kubernetes.io/managed-by: agentic-ai-stack + spec: + podSelector: + matchLabels: + app.kubernetes.io/name: sandbox-router + app.kubernetes.io/component: sandbox-router + policyTypes: [Ingress] + ingress: + - from: + - namespaceSelector: {} + ports: + - {protocol: TCP, port: 15008} + when: istio_enabled | default(false) | bool + - name: "agent_sandbox | Wait for sandbox-router to be ready" kubernetes.core.k8s_info: kind: Deployment @@ -237,15 +262,22 @@ - "WarmPool : {{ kata_warm_pool_name }} (size={{ kata_warm_pool_size }})" - "Verify : kubectl get sandbox,pod -n {{ agent_sandbox_namespace }} -l sandbox=kata" +# The toolkit's own pods only (controller, router, warm pools): other workloads share the namespace. - name: "agent_sandbox | Wait for Agent Sandbox pods to be ready" kubernetes.core.k8s_info: kind: Pod namespace: "{{ agent_sandbox_namespace }}" register: _asb_pods + vars: + _asb_own: >- + {{ (_asb_pods.resources | default([]) | selectattr('metadata.labels.app', 'defined') + | selectattr('metadata.labels.app', 'in', ['agent-sandbox-controller', 'sandbox-router']) | list) + + (_asb_pods.resources | default([]) | selectattr('metadata.labels', 'defined') + | selectattr('metadata.labels', 'contains', 'agents.x-k8s.io/warm-pool-sandbox') | list) }} until: >- - _asb_pods.resources | default([]) | length > 0 and - (_asb_pods.resources | rejectattr('status.phase', 'in', ['Running', 'Succeeded']) | list | length == 0) and - (_asb_pods.resources | selectattr('status.phase', 'eq', 'Running') + _asb_own | length > 0 and + (_asb_own | rejectattr('status.phase', 'in', ['Running', 'Succeeded']) | list | length == 0) and + (_asb_own | selectattr('status.phase', 'eq', 'Running') | map(attribute='status.containerStatuses') | flatten | rejectattr('ready') | list | length == 0) retries: 60 delay: 10 diff --git a/roles/asp_common/defaults/main.yaml b/roles/asp_common/defaults/main.yaml new file mode 100644 index 00000000..dced856f --- /dev/null +++ b/roles/asp_common/defaults/main.yaml @@ -0,0 +1,45 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Shared by the asp_* components. Operators set the switch and settings in config.agent-toolkit.yaml. +agentsysperf_enabled: false +# The AgentSysPerf checkout that Toolkit Manager's init clones (repos.agent-toolkit.yaml); used unmodified. +agentsysperf_repo_dir: "{{ playbook_dir }}/../ext/agentsysperf" + +agentsysperf_namespace: "agent-sysperf" +agentsysperf_sandbox_namespace: "{{ agent_sandbox_namespace | default('agent-sandbox-system') }}" + +# build: on the nodes from ext/agentsysperf | registry: /agentsysperf-{driver,dashboard}: +agentsysperf_image_source: "build" +agentsysperf_registry: "" +agentsysperf_image_tag: "" # empty: the checkout's git describe +agentsysperf_images_rebuild: false +agentsysperf_build_node: "" # empty: the first control-plane node +agentsysperf_buildkit_version: "v0.35.1" +agentsysperf_buildkit_sha256: "b248c2b91698aafef11818fe8b681dc5e341581f7d5676709ff45ca1f29b0408" +agentsysperf_buildkit_url: "https://github.com/moby/buildkit/releases/download/{{ agentsysperf_buildkit_version }}/buildkit-{{ agentsysperf_buildkit_version }}.linux-amd64.tar.gz" +agentsysperf_host_dir: "/var/lib/agentsysperf" + +agentsysperf_llm_key_enabled: true +agentsysperf_llm_key_alias: "agent-sysperf-driver" +agentsysperf_rotate_llm_key: false +agentsysperf_llm_model: "{{ llm_services_autodeploy_models | default([], true) | first | default('', true) }}" + +agentsysperf_driver_sa: "agentsysperf-driver" +agentsysperf_driver_node: "" +agentsysperf_sandbox_nodes: [] +agentsysperf_sandbox_pool: "" +# Task-pod DNS without a proxy: public (agentsysperf_public_nameservers) | none +agentsysperf_sandbox_dns: "public" +agentsysperf_public_nameservers: [] + +agentsysperf_store_database: "aspdb" +agentsysperf_teardown_delete_results: false + +agentsysperf_observability_enabled: "{{ observability_enabled | default(true) }}" + +agentsysperf_dashboard_enabled: true +agentsysperf_dashboard_release: "agent-sysperf" +agentsysperf_dashboard_hostname: "agent-sysperf.{{ base_domain_name | default('inteltoolkits.ai') }}" +agentsysperf_dashboard_allowed_groups: [] +agentsysperf_dashboard_oidc_client_id: "agentsysperf-dashboard" diff --git a/roles/asp_common/tasks/facts.yaml b/roles/asp_common/tasks/facts.yaml new file mode 100644 index 00000000..3dbe0ffc --- /dev/null +++ b/roles/asp_common/tasks/facts.yaml @@ -0,0 +1,125 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Library tasks (include_role tasks_from, public): what every asp_* component derives. +- name: "agentsysperf | facts | The AgentSysPerf checkout" + ansible.builtin.stat: + path: "{{ agentsysperf_repo_dir }}/deploy/chart/Chart.yaml" + register: _asp_checkout + +# Teardown deletes by name and runs without it, so switching off never strands anything. +- name: "agentsysperf | facts | Install and validate need the checkout" + ansible.builtin.assert: + that: _asp_checkout.stat.exists or (component_action | default('install')) == 'teardown' + fail_msg: >- + agentsysperf_enabled is true, but {{ agentsysperf_repo_dir }} holds no AgentSysPerf checkout. + Clone it with: ./toolkit_manager.sh init agent-toolkit --env {{ env_name | default('local') }} + quiet: true + +- name: "agentsysperf | facts | Source ref of the checkout" + ansible.builtin.command: + argv: [git, -C, "{{ agentsysperf_repo_dir | realpath }}", describe, --always, --dirty, --match, "v[0-9]*"] + register: _asp_describe + changed_when: false + failed_when: false + check_mode: false + +- name: "agentsysperf | facts | Names" + ansible.builtin.set_fact: + _asp_repo: "{{ agentsysperf_repo_dir | realpath }}" + _asp_source_ref: "{{ _asp_describe.stdout | default('', true) | trim or 'unknown' }}" + # Also a label value: at most 63 of [A-Za-z0-9_.-], alphanumeric at both ends. + _asp_image_tag: >- + {{ (agentsysperf_image_tag or (_asp_describe.stdout | default('', true) | trim) or 'dev') + | regex_replace('[^A-Za-z0-9_.-]', '-') | truncate(63, true, '') + | regex_replace('^[^A-Za-z0-9]+|[^A-Za-z0-9]+$', '') }} + _asp_nodes: "{{ (groups['kube_control_plane'] | default([])) | union(groups['kube_node'] | default([])) }}" + _asp_istio: "{{ istio_enabled | default(true) | bool }}" + _asp_litellm_ns: "{{ litellm_namespace | default('litellm') }}" + _asp_pgvector_ns: "{{ pgvector_namespace | default('pgvector') }}" + _asp_nri_owner: >- + {{ 'toolkit' if (kubernetes_cpu_policy | default('nri-balloons')) == 'nri-balloons' + and (kubernetes_accelerator | default('cpu')) == 'cpu' else '' }} + _asp_proxy_url: "{{ https_proxy | default('', true) or http_proxy | default('', true) }}" + +- name: "agentsysperf | facts | Images" + ansible.builtin.set_fact: + _asp_driver_image: >- + {{ (agentsysperf_registry ~ '/agentsysperf-driver:' ~ agentsysperf_image_tag) + if agentsysperf_image_source == 'registry' else ('agentsysperf-driver:' ~ _asp_image_tag) }} + _asp_dashboard_repository: >- + {{ (agentsysperf_registry ~ '/agentsysperf-dashboard') if agentsysperf_image_source == 'registry' + else 'agentsysperf-dashboard' }} + _asp_dashboard_tag: "{{ agentsysperf_image_tag if agentsysperf_image_source == 'registry' else _asp_image_tag }}" + # Built images exist only on the nodes asp_images loaded them into. + _asp_node_selector: >- + {{ {} if agentsysperf_image_source == 'registry' else {'agentsysperf.intel.com/images': _asp_image_tag} }} + +- name: "agentsysperf | facts | Sandbox router" + kubernetes.core.k8s_info: + kind: Deployment + namespace: "{{ agentsysperf_sandbox_namespace }}" + name: "{{ item }}" + loop: [sandbox-router, sandbox-router-deployment] + register: _asp_routers + +- name: "agentsysperf | facts | LiteLLM" + kubernetes.core.k8s_info: + kind: Pod + namespace: "{{ _asp_litellm_ns }}" + label_selectors: [app.kubernetes.io/name=litellm] + field_selectors: [status.phase=Running] + register: _asp_litellm_pods + +- name: "agentsysperf | facts | Langfuse keys" + kubernetes.core.k8s_info: + kind: Secret + namespace: "{{ _asp_litellm_ns }}" + name: langfuse-api-keys + register: _asp_langfuse + no_log: true + +- name: "agentsysperf | facts | The kubernetes Service" + kubernetes.core.k8s_info: + kind: Service + namespace: default + name: kubernetes + register: _asp_k8s_svc + +# Task pods get the proxy by address: they have no resolver of their own. +- name: "agentsysperf | facts | Resolve the proxy" + ansible.builtin.command: + argv: [getent, ahostsv4, "{{ _asp_proxy_url | urlsplit('hostname') }}"] + register: _asp_proxy_lookup + changed_when: false + failed_when: false + check_mode: false + when: + - _asp_proxy_url | length > 0 + - not ((_asp_proxy_url | urlsplit('hostname')) is match('^[0-9.]+$')) + +- name: "agentsysperf | facts | Cluster facts" + vars: + _host: "{{ _asp_proxy_url | urlsplit('hostname') if _asp_proxy_url else '' }}" + _no_proxy_base: "{{ no_proxy | default('', true) }}" + ansible.builtin.set_fact: + _asp_router_v1: "{{ _asp_routers.results[0].resources | default([]) | length > 0 }}" + _asp_router_v0: "{{ _asp_routers.results[1].resources | default([]) | length > 0 }}" + _asp_has_litellm: "{{ _asp_litellm_pods.resources | default([]) | length > 0 }}" + _asp_has_langfuse: "{{ _asp_langfuse.resources | default([]) | length > 0 }}" + _asp_proxy_ips: >- + {{ [] if not _host + else ([_host] if _host is match('^[0-9.]+$') + else (_asp_proxy_lookup.stdout_lines | default([]) | map('split') | map('first') | unique | list)) }} + _asp_proxy_port: >- + {{ ((_asp_proxy_url | urlsplit('port')) or (443 if (_asp_proxy_url | urlsplit('scheme')) == 'https' else 80)) + if _asp_proxy_url else 0 }} + _asp_no_proxy: >- + {{ ([_no_proxy_base, '.svc', '.svc.cluster.local', '.cluster.local'] + + (_asp_k8s_svc.resources | default([]) | map(attribute='spec.clusterIP') | list)) | select | join(',') }} + _asp_dashboard_url: "https://{{ agentsysperf_dashboard_hostname }}/" + _asp_grafana_url: >- + {{ ('https://' ~ base_domain_name ~ (observability_grafana_path | default('/grafana'))) + if (routing_mode | default('subdomain')) == 'path' + else ('https://' ~ (observability_grafana_hostname | default('grafana.' ~ base_domain_name))) }} + _asp_langfuse_ui_url: "https://{{ langfuse_hostname | default('langfuse.' ~ base_domain_name) }}" diff --git a/roles/asp_dashboard/defaults/main.yaml b/roles/asp_dashboard/defaults/main.yaml new file mode 100644 index 00000000..8183b899 --- /dev/null +++ b/roles/asp_dashboard/defaults/main.yaml @@ -0,0 +1,6 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Shared settings: asp_common/defaults/main.yaml. +asp_dashboard_port: 7870 +asp_dashboard_helm_timeout: "600s" diff --git a/roles/asp_dashboard/tasks/install.yaml b/roles/asp_dashboard/tasks/install.yaml new file mode 100644 index 00000000..2cbb858b --- /dev/null +++ b/roles/asp_dashboard/tasks/install.yaml @@ -0,0 +1,133 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# The dashboard has no login of its own: only the gateway reaches it, and the gateway +# signs people in through Keycloak (the platform admin group unless groups are given). +- name: "asp_dashboard | Names" + ansible.builtin.set_fact: + _asp_dash_name: "{{ agentsysperf_dashboard_release }}-dashboard" + _asp_dash_host: "{{ agentsysperf_dashboard_hostname }}" + +- name: "asp_dashboard | Only the gateway reaches the dashboard" + ansible.builtin.include_role: + name: gateway + tasks_from: backend_ingress.yaml + vars: + gateway_backend_namespace: "{{ agentsysperf_namespace }}" + gateway_backend_selector: + app.kubernetes.io/name: agentsysperf-dashboard + app.kubernetes.io/instance: "{{ agentsysperf_dashboard_release }}" + gateway_backend_ports: ["{{ asp_dashboard_port }}"] + gateway_backend_policy_name: "{{ _asp_dash_name }}-gateway-only" + +- name: "asp_dashboard | Dashboard release" + kubernetes.core.helm: + name: "{{ agentsysperf_dashboard_release }}" + chart_ref: "{{ _asp_repo }}/deploy/dashboard/chart" + release_namespace: "{{ agentsysperf_namespace }}" + values: + fullnameOverride: "{{ _asp_dash_name }}" + baseUrlPath: "" + ingress: + enabled: false + persistence: + mode: ephemeral + postgresql: + urlSecret: + secretName: asp-pg-dsn + envFrom: + - configMapRef: + name: asp-cluster-env + - secretRef: + name: asp-langfuse + optional: true + image: + repository: "{{ _asp_dashboard_repository }}" + tag: "{{ _asp_dashboard_tag }}" + pullPolicy: IfNotPresent + nodeSelector: "{{ _asp_node_selector }}" + launchEnabled: false + launch: + jobs: + enabled: false + wait: true + timeout: "{{ asp_dashboard_helm_timeout }}" + +- name: "asp_dashboard | Publish {{ _asp_dash_host }}" + ansible.builtin.include_role: + name: gateway + tasks_from: publish.yaml + vars: + gateway_publish_name: agent-sysperf + gateway_publish_namespace: "{{ agentsysperf_namespace }}" + gateway_publish_host: "{{ _asp_dash_host }}" + gateway_publish_mode: subdomain + +- name: "asp_dashboard | Route" + kubernetes.core.k8s: + state: present + definition: + apiVersion: gateway.networking.k8s.io/v1 + kind: HTTPRoute + metadata: + name: "{{ _asp_dash_name }}" + namespace: "{{ agentsysperf_namespace }}" + labels: + app.kubernetes.io/part-of: agentsysperf + spec: + parentRefs: + - "{{ gateway_publish.parent_ref }}" + hostnames: + - "{{ _asp_dash_host }}" + rules: + - matches: + - path: + type: PathPrefix + value: / + backendRefs: + - name: "{{ _asp_dash_name }}" + port: "{{ asp_dashboard_port | int }}" + +- name: "asp_dashboard | Keycloak client" + ansible.builtin.include_role: + name: keycloak + tasks_from: oidc_client.yaml + vars: + keycloak_client: + id: "{{ agentsysperf_dashboard_oidc_client_id }}" + redirect_uris: ["https://{{ _asp_dash_host }}/oauth2/callback"] + post_logout_uris: ["https://{{ _asp_dash_host }}/"] + +- name: "asp_dashboard | Keycloak client secret" + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Secret + metadata: + name: "{{ _asp_dash_name }}-sso" + namespace: "{{ agentsysperf_namespace }}" + type: Opaque + data: + client-secret: "{{ keycloak_client_secret | b64encode }}" + no_log: true + +- name: "asp_dashboard | Sign in at the gateway" + ansible.builtin.include_role: + name: gateway + tasks_from: route_sso.yaml + vars: + gateway_route_name: "{{ _asp_dash_name }}" + gateway_route_namespace: "{{ agentsysperf_namespace }}" + gateway_route_policy_name: "{{ _asp_dash_name }}-sso" + gateway_sso: + issuer: "{{ keycloak_client_issuer }}" + issuer_internal: "{{ keycloak_client_issuer_internal }}" + client_id: "{{ agentsysperf_dashboard_oidc_client_id }}" + client_secret_name: "{{ _asp_dash_name }}-sso" + redirect_url: "https://{{ _asp_dash_host }}/oauth2/callback" + allowed_groups: "{{ agentsysperf_dashboard_allowed_groups or [keycloak_client_admin_group] }}" + +- name: "asp_dashboard | Ready" + ansible.builtin.debug: + msg: "AgentSysPerf dashboard: https://{{ _asp_dash_host }}/ (Keycloak sign-in)" diff --git a/roles/asp_dashboard/tasks/main.yaml b/roles/asp_dashboard/tasks/main.yaml new file mode 100644 index 00000000..266fe074 --- /dev/null +++ b/roles/asp_dashboard/tasks/main.yaml @@ -0,0 +1,18 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +- name: "asp_dashboard | dispatch | Assert supported action" + ansible.builtin.assert: + that: component_action | default('') in ['install', 'teardown', 'validate'] + fail_msg: "asp_dashboard: unsupported component_action='{{ component_action | default('') }}'" + quiet: true + +- name: "asp_dashboard | dispatch | Shared facts" + ansible.builtin.include_role: + name: asp_common + tasks_from: facts.yaml + public: true + +- name: "asp_dashboard | dispatch | Include {{ component_action }}" + ansible.builtin.include_tasks: + file: "{{ component_action }}.yaml" diff --git a/roles/asp_dashboard/tasks/teardown.yaml b/roles/asp_dashboard/tasks/teardown.yaml new file mode 100644 index 00000000..4b62c1f1 --- /dev/null +++ b/roles/asp_dashboard/tasks/teardown.yaml @@ -0,0 +1,53 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# The portal entry lives in the gateway's ConfigMap, which labels never take back; the +# rest is here for an env no install labelled. Safe when nothing was installed. +- name: "asp_dashboard | teardown | Sign-in policy" + ansible.builtin.include_role: + name: gateway + tasks_from: route_sso.yaml + vars: + gateway_route_name: "{{ agentsysperf_dashboard_release }}-dashboard" + gateway_route_namespace: "{{ agentsysperf_namespace }}" + gateway_route_policy_name: "{{ agentsysperf_dashboard_release }}-dashboard-sso" + gateway_route_state: absent + +- name: "asp_dashboard | teardown | Route" + kubernetes.core.k8s: + state: absent + api_version: gateway.networking.k8s.io/v1 + kind: HTTPRoute + name: "{{ agentsysperf_dashboard_release }}-dashboard" + namespace: "{{ agentsysperf_namespace }}" + failed_when: false + +- name: "asp_dashboard | teardown | Unpublish {{ agentsysperf_dashboard_hostname }}" + ansible.builtin.include_role: + name: gateway + tasks_from: unpublish.yaml + vars: + gateway_publish_name: agent-sysperf + gateway_publish_namespace: "{{ agentsysperf_namespace }}" + gateway_publish_host: "{{ agentsysperf_dashboard_hostname }}" + gateway_publish_mode: subdomain + +- name: "asp_dashboard | teardown | Dashboard release" + kubernetes.core.helm: + name: "{{ agentsysperf_dashboard_release }}" + release_namespace: "{{ agentsysperf_namespace }}" + state: absent + wait: true + +- name: "asp_dashboard | teardown | Gateway-only policy and client secret" + kubernetes.core.k8s: + state: absent + api_version: "{{ item.api }}" + kind: "{{ item.kind }}" + namespace: "{{ agentsysperf_namespace }}" + name: "{{ item.name }}" + loop: + - {api: networking.k8s.io/v1, kind: NetworkPolicy, name: "{{ agentsysperf_dashboard_release }}-dashboard-gateway-only"} + - {api: v1, kind: Secret, name: "{{ agentsysperf_dashboard_release }}-dashboard-sso"} + loop_control: + label: "{{ item.kind }}/{{ item.name }}" diff --git a/roles/asp_dashboard/tasks/validate.yaml b/roles/asp_dashboard/tasks/validate.yaml new file mode 100644 index 00000000..77a8498f --- /dev/null +++ b/roles/asp_dashboard/tasks/validate.yaml @@ -0,0 +1,31 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Read-only. +- name: "asp_dashboard | validate | Deployment, route and sign-in policy" + kubernetes.core.k8s_info: + api_version: "{{ item.api }}" + kind: "{{ item.kind }}" + namespace: "{{ agentsysperf_namespace }}" + name: "{{ item.name }}" + loop: + - {api: apps/v1, kind: Deployment, name: "{{ agentsysperf_dashboard_release }}-dashboard"} + - {api: gateway.networking.k8s.io/v1, kind: HTTPRoute, name: "{{ agentsysperf_dashboard_release }}-dashboard"} + - {api: gateway.envoyproxy.io/v1alpha1, kind: SecurityPolicy, name: "{{ agentsysperf_dashboard_release }}-dashboard-sso"} + loop_control: + label: "{{ item.kind }}/{{ item.name }}" + register: _asp_v_dash + +- name: "asp_dashboard | validate | Report" + vars: + _dep: "{{ _asp_v_dash.results[0].resources | first | default({}) }}" + _route: "{{ _asp_v_dash.results[1].resources | first | default({}) }}" + _ready: "{{ (_dep.status | default({})).readyReplicas | default(0) | int >= 1 }}" + _accepted: >- + {{ (_route.status | default({})).parents | default([]) | map(attribute='conditions') | flatten + | selectattr('type', 'equalto', 'Accepted') | selectattr('status', 'equalto', 'True') | list | length > 0 }} + _sso: "{{ _asp_v_dash.results[2].resources | length > 0 }}" + ansible.builtin.assert: + that: [_ready | bool, _accepted | bool, _sso | bool] + fail_msg: "AgentSysPerf dashboard: ready={{ _ready }}, route accepted={{ _accepted }}, sign-in policy={{ _sso }}." + success_msg: "AgentSysPerf dashboard ready at https://{{ agentsysperf_dashboard_hostname }}/ behind Keycloak sign-in." diff --git a/roles/asp_images/defaults/main.yaml b/roles/asp_images/defaults/main.yaml new file mode 100644 index 00000000..695d54cc --- /dev/null +++ b/roles/asp_images/defaults/main.yaml @@ -0,0 +1,5 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Shared settings: asp_common/defaults/main.yaml. +asp_images_dockerfiles: {driver: deploy/driver/Dockerfile, dashboard: deploy/dashboard/Dockerfile} diff --git a/roles/asp_images/tasks/build.yaml b/roles/asp_images/tasks/build.yaml new file mode 100644 index 00000000..6a7595aa --- /dev/null +++ b/roles/asp_images/tasks/build.yaml @@ -0,0 +1,118 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# A BuildKit of its own (binaries, config, cache and socket under agentsysperf_host_dir), +# with a containerd worker in k8s.io so builds land where the kubelet reads images. +- name: "asp_images | build | Directories" + ansible.builtin.file: + path: "{{ item }}" + state: directory + mode: "0755" + loop: + - "{{ _asp_bk_dir }}" + - "{{ _asp_bk_dir }}/bin" + delegate_to: "{{ _asp_build_node }}" + become: true + +- name: "asp_images | build | BuildKit {{ agentsysperf_buildkit_version }}" + ansible.builtin.get_url: + url: "{{ agentsysperf_buildkit_url }}" + dest: "{{ _asp_bk_dir }}/buildkit-{{ agentsysperf_buildkit_version }}.tar.gz" + checksum: "sha256:{{ agentsysperf_buildkit_sha256 }}" + mode: "0644" + delegate_to: "{{ _asp_build_node }}" + become: true + +- name: "asp_images | build | buildkitd and buildctl" + ansible.builtin.unarchive: + src: "{{ _asp_bk_dir }}/buildkit-{{ agentsysperf_buildkit_version }}.tar.gz" + dest: "{{ _asp_bk_dir }}" + remote_src: true + include: [bin/buildkitd, bin/buildctl] + creates: "{{ _asp_bk_dir }}/bin/buildkitd" + delegate_to: "{{ _asp_build_node }}" + become: true + +- name: "asp_images | build | buildkitd configuration" + ansible.builtin.copy: + dest: "{{ _asp_bk_dir }}/buildkitd.toml" + mode: "0644" + content: | + root = "{{ _asp_bk_dir }}/buildkit" + [grpc] + address = ["{{ _asp_bk_sock }}"] + [worker.oci] + enabled = false + [worker.containerd] + enabled = true + namespace = "k8s.io" + [worker.containerd.runtime] + name = "io.containerd.runc.v2" + options = { BinaryName = "{{ _asp_bin[_asp_build_node] }}/runc" } + delegate_to: "{{ _asp_build_node }}" + become: true + register: _asp_bk_conf + +- name: "asp_images | build | buildkitd service" + ansible.builtin.copy: + dest: /etc/systemd/system/asp-buildkitd.service + mode: "0644" + content: | + [Unit] + Description=BuildKit for AgentSysPerf image builds + After=containerd.service + Requires=containerd.service + + [Service] + {% if http_proxy | default('', true) or https_proxy | default('', true) %} + Environment="HTTP_PROXY={{ http_proxy | default('') }}" "HTTPS_PROXY={{ https_proxy | default('') }}" "NO_PROXY={{ no_proxy | default('') }}" + {% endif %} + ExecStart={{ _asp_bk_dir }}/bin/buildkitd --config {{ _asp_bk_dir }}/buildkitd.toml + Restart=on-failure + delegate_to: "{{ _asp_build_node }}" + become: true + register: _asp_bk_unit + +- name: "asp_images | build | Start buildkitd" + ansible.builtin.systemd_service: + name: asp-buildkitd + state: "{{ 'restarted' if (_asp_bk_conf is changed or _asp_bk_unit is changed) else 'started' }}" + daemon_reload: true + delegate_to: "{{ _asp_build_node }}" + become: true + +- name: "asp_images | build | Context on the build node" + ansible.builtin.set_fact: + _asp_ctx: >- + {{ _asp_repo if (hostvars[_asp_build_node].ansible_connection | default('ssh')) == 'local' + else _asp_bk_dir ~ '/src' }} + +- name: "asp_images | build | Copy the checkout to the build node" + ansible.builtin.copy: + src: "{{ _asp_repo }}/" + dest: "{{ _asp_bk_dir }}/src/" + mode: preserve + delegate_to: "{{ _asp_build_node }}" + become: true + when: _asp_ctx != _asp_repo + +- name: "asp_images | build | {{ item.key }}" + vars: + _proxy_args: >- + {{ ['http_proxy', 'https_proxy', 'no_proxy', 'HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY'] + | zip([http_proxy | default(''), https_proxy | default(''), no_proxy | default('')] * 2) + | selectattr('1') | map('join', '=') | map('regex_replace', '^', '--build-arg=') | list }} + ansible.builtin.command: + argv: >- + {{ [_asp_bin[_asp_build_node] ~ '/nerdctl', '--namespace', 'k8s.io', 'build', + '--build-arg=AGENTSYSPERF_SOURCE_REF=' ~ _asp_source_ref] + _proxy_args + + ['-f', _asp_ctx ~ '/' ~ item.value, '-t', 'agentsysperf-' ~ item.key ~ ':' ~ _asp_image_tag, _asp_ctx] }} + environment: + PATH: "{{ _asp_bk_dir }}/bin:{{ _asp_bin[_asp_build_node] }}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + BUILDKIT_HOST: "{{ _asp_bk_sock }}" + delegate_to: "{{ _asp_build_node }}" + become: true + loop: "{{ asp_images_dockerfiles | dict2items }}" + loop_control: + label: "agentsysperf-{{ item.key }}:{{ _asp_image_tag }}" + changed_when: true diff --git a/roles/asp_images/tasks/distribute.yaml b/roles/asp_images/tasks/distribute.yaml new file mode 100644 index 00000000..3051c377 --- /dev/null +++ b/roles/asp_images/tasks/distribute.yaml @@ -0,0 +1,51 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Multi-node without a registry: one tarball from the build node to every other node. +- name: "asp_images | distribute | Save on the build node" + ansible.builtin.command: + argv: >- + {{ [_asp_bin[_asp_build_node] ~ '/nerdctl', '--namespace', 'k8s.io', 'save', + '-o', _asp_bk_dir ~ '/images-' ~ _asp_image_tag ~ '.tar'] + _asp_images }} + delegate_to: "{{ _asp_build_node }}" + become: true + changed_when: true + +- name: "asp_images | distribute | Fetch to this host" + ansible.builtin.fetch: + src: "{{ _asp_bk_dir }}/images-{{ _asp_image_tag }}.tar" + dest: "{{ env_dir | default(playbook_dir) }}/logs/agentsysperf-images-{{ _asp_image_tag }}.tar" + flat: true + delegate_to: "{{ _asp_build_node }}" + become: true + +- name: "asp_images | distribute | Directory on each node" + ansible.builtin.file: + path: "{{ _asp_bk_dir }}" + state: directory + mode: "0755" + delegate_to: "{{ item }}" + become: true + loop: "{{ _asp_nodes | reject('equalto', _asp_build_node) | list }}" + +- name: "asp_images | distribute | Copy to each node" + ansible.builtin.copy: + src: "{{ env_dir | default(playbook_dir) }}/logs/agentsysperf-images-{{ _asp_image_tag }}.tar" + dest: "{{ _asp_bk_dir }}/images-{{ _asp_image_tag }}.tar" + mode: "0644" + delegate_to: "{{ item }}" + become: true + loop: "{{ _asp_nodes | reject('equalto', _asp_build_node) | list }}" + +- name: "asp_images | distribute | Load on each node" + ansible.builtin.command: + argv: ["{{ _asp_bin[item] }}/nerdctl", --namespace, k8s.io, load, -i, "{{ _asp_bk_dir }}/images-{{ _asp_image_tag }}.tar"] + delegate_to: "{{ item }}" + become: true + loop: "{{ _asp_nodes | reject('equalto', _asp_build_node) | list }}" + changed_when: true + +- name: "asp_images | distribute | Drop the local copy" + ansible.builtin.file: + path: "{{ env_dir | default(playbook_dir) }}/logs/agentsysperf-images-{{ _asp_image_tag }}.tar" + state: absent diff --git a/roles/asp_images/tasks/install.yaml b/roles/asp_images/tasks/install.yaml new file mode 100644 index 00000000..dca4a94e --- /dev/null +++ b/roles/asp_images/tasks/install.yaml @@ -0,0 +1,58 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Built once on one node into containerd's k8s.io namespace, then loaded on every other +# node, which is labelled so AgentSysPerf pods land only where the images are. +- name: "asp_images | Images and build node" + ansible.builtin.set_fact: + _asp_build_node: "{{ agentsysperf_build_node or (_asp_nodes | first) }}" + _asp_images: "{{ asp_images_dockerfiles.keys() | map('regex_replace', '^', 'agentsysperf-') | map('regex_replace', '$', ':' ~ _asp_image_tag) | list }}" + _asp_bk_dir: "{{ agentsysperf_host_dir }}" + _asp_bk_sock: "unix:///run/agentsysperf-buildkit.sock" + +- name: "asp_images | containerd on each node" + ansible.builtin.include_tasks: tools.yaml + +- name: "asp_images | Images already on each node" + ansible.builtin.command: + argv: ["{{ _asp_bin[item.0] }}/nerdctl", --namespace, k8s.io, image, inspect, "{{ item.1 }}"] + delegate_to: "{{ item.0 }}" + become: true + loop: "{{ _asp_nodes | product(_asp_images) | list }}" + register: _asp_have + changed_when: false + failed_when: false + check_mode: false + +- name: "asp_images | What is missing" + ansible.builtin.set_fact: + _asp_missing_nodes: "{{ _asp_have.results | rejectattr('rc', 'equalto', 0) | map(attribute='item') | map('first') | unique | list }}" + _asp_build_needed: >- + {{ agentsysperf_images_rebuild | bool or 'dirty' in _asp_image_tag + or (_asp_have.results | rejectattr('rc', 'equalto', 0) | map(attribute='item') | map('first') + | select('equalto', _asp_build_node) | list | length > 0) }} + +- name: "asp_images | Build" + ansible.builtin.include_tasks: build.yaml + when: _asp_build_needed | bool + +- name: "asp_images | Load on the other nodes" + ansible.builtin.include_tasks: distribute.yaml + when: >- + _asp_nodes | length > 1 + and (_asp_build_needed | bool or (_asp_missing_nodes | reject('equalto', _asp_build_node) | list | length > 0)) + +- name: "asp_images | Label the nodes that hold the images" + kubernetes.core.k8s: + state: patched + kind: Node + name: "{{ item }}" + definition: + metadata: + labels: + agentsysperf.intel.com/images: "{{ _asp_image_tag }}" + loop: "{{ _asp_nodes }}" + +- name: "asp_images | Ready" + ansible.builtin.debug: + msg: "{{ _asp_images | join(', ') }} on {{ _asp_nodes | join(', ') }} (source {{ _asp_source_ref }})" diff --git a/roles/asp_images/tasks/main.yaml b/roles/asp_images/tasks/main.yaml new file mode 100644 index 00000000..63085d35 --- /dev/null +++ b/roles/asp_images/tasks/main.yaml @@ -0,0 +1,18 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +- name: "asp_images | dispatch | Assert supported action" + ansible.builtin.assert: + that: component_action | default('') in ['install', 'teardown', 'validate'] + fail_msg: "asp_images: unsupported component_action='{{ component_action | default('') }}'" + quiet: true + +- name: "asp_images | dispatch | Shared facts" + ansible.builtin.include_role: + name: asp_common + tasks_from: facts.yaml + public: true + +- name: "asp_images | dispatch | Include {{ component_action }}" + ansible.builtin.include_tasks: + file: "{{ component_action }}.yaml" diff --git a/roles/asp_images/tasks/teardown.yaml b/roles/asp_images/tasks/teardown.yaml new file mode 100644 index 00000000..0e1f9be3 --- /dev/null +++ b/roles/asp_images/tasks/teardown.yaml @@ -0,0 +1,67 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Host changes labels cannot take back: the images, BuildKit and its files. Safe when +# nothing was installed. +- name: "asp_images | teardown | containerd binary on each node" + ansible.builtin.systemd_service: + name: containerd + delegate_to: "{{ item }}" + loop: "{{ _asp_nodes }}" + register: _asp_t_ctd + failed_when: false + +- name: "asp_images | teardown | AgentSysPerf images on each node" + vars: + _bin: "{{ (item.status.ExecStart | default('') | regex_search('path=[^ ;]+') | default('', true) | regex_replace('^path=', '')) | dirname }}" + ansible.builtin.shell: >- + set -o pipefail; + ids=$({{ _bin }}/nerdctl --namespace k8s.io image ls -q --filter reference='agentsysperf-*' | sort -u); + if [ -n "$ids" ]; then {{ _bin }}/nerdctl --namespace k8s.io rmi -f $ids && echo removed; fi + args: + executable: /bin/bash + delegate_to: "{{ item.item }}" + become: true + loop: "{{ _asp_t_ctd.results }}" + loop_control: + label: "{{ item.item }}" + register: _asp_t_rmi + changed_when: "'removed' in _asp_t_rmi.stdout" + failed_when: false + when: (item.status.ExecStart | default('')) | length > 0 + +- name: "asp_images | teardown | Stop buildkitd" + ansible.builtin.systemd_service: + name: asp-buildkitd + state: stopped + delegate_to: "{{ item }}" + become: true + loop: "{{ _asp_nodes }}" + failed_when: false + +- name: "asp_images | teardown | buildkitd service and files" + ansible.builtin.file: + path: "{{ item.1 }}" + state: absent + delegate_to: "{{ item.0 }}" + become: true + loop: "{{ _asp_nodes | product(['/etc/systemd/system/asp-buildkitd.service', agentsysperf_host_dir]) | list }}" + +- name: "asp_images | teardown | systemd reload" + ansible.builtin.systemd_service: + daemon_reload: true + delegate_to: "{{ item }}" + become: true + loop: "{{ _asp_nodes }}" + +- name: "asp_images | teardown | Node labels" + kubernetes.core.k8s: + state: patched + kind: Node + name: "{{ item }}" + definition: + metadata: + labels: + agentsysperf.intel.com/images: null + loop: "{{ _asp_nodes }}" + failed_when: false diff --git a/roles/asp_images/tasks/tools.yaml b/roles/asp_images/tasks/tools.yaml new file mode 100644 index 00000000..785bf064 --- /dev/null +++ b/roles/asp_images/tasks/tools.yaml @@ -0,0 +1,17 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# nerdctl and runc sit beside containerd: /.kubespray/bin on a single-node +# install, /usr/local/bin on multi-node. The running service says which. +- name: "asp_images | containerd binary on each node" + ansible.builtin.systemd_service: + name: containerd + delegate_to: "{{ item }}" + loop: "{{ _asp_nodes }}" + register: _asp_ctd + +- name: "asp_images | Where nerdctl and runc are" + ansible.builtin.set_fact: + _asp_bin: >- + {{ dict(_asp_nodes | zip(_asp_ctd.results | map(attribute='status.ExecStart') + | map('regex_search', 'path=[^ ;]+') | map('regex_replace', '^path=', '') | map('dirname'))) }} diff --git a/roles/asp_images/tasks/validate.yaml b/roles/asp_images/tasks/validate.yaml new file mode 100644 index 00000000..953b57da --- /dev/null +++ b/roles/asp_images/tasks/validate.yaml @@ -0,0 +1,38 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Read-only. +- name: "asp_images | validate | Images" + ansible.builtin.set_fact: + _asp_images: "{{ asp_images_dockerfiles.keys() | map('regex_replace', '^', 'agentsysperf-') | map('regex_replace', '$', ':' ~ _asp_image_tag) | list }}" + +- name: "asp_images | validate | containerd on each node" + ansible.builtin.include_tasks: tools.yaml + +- name: "asp_images | validate | Images on each node" + ansible.builtin.command: + argv: ["{{ _asp_bin[item.0] }}/nerdctl", --namespace, k8s.io, image, inspect, "{{ item.1 }}"] + delegate_to: "{{ item.0 }}" + become: true + loop: "{{ _asp_nodes | product(_asp_images) | list }}" + register: _asp_v_have + changed_when: false + failed_when: false + check_mode: false + +- name: "asp_images | validate | Node labels" + kubernetes.core.k8s_info: + kind: Node + label_selectors: ["agentsysperf.intel.com/images={{ _asp_image_tag }}"] + register: _asp_v_labelled + +- name: "asp_images | validate | Report" + vars: + _missing: "{{ _asp_v_have.results | rejectattr('rc', 'equalto', 0) | map(attribute='item') | map('join', ': ') | list }}" + _labelled: "{{ _asp_v_labelled.resources | map(attribute='metadata.name') | list }}" + ansible.builtin.assert: + that: + - _missing | length == 0 + - _asp_nodes | difference(_labelled) | length == 0 + fail_msg: "AgentSysPerf images missing {{ _missing }}; nodes not labelled {{ _asp_nodes | difference(_labelled) }}." + success_msg: "AgentSysPerf images {{ _asp_images | join(', ') }} on {{ _labelled | join(', ') }}." diff --git a/roles/asp_platform/defaults/main.yaml b/roles/asp_platform/defaults/main.yaml new file mode 100644 index 00000000..d81343fc --- /dev/null +++ b/roles/asp_platform/defaults/main.yaml @@ -0,0 +1,5 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Shared settings: asp_common/defaults/main.yaml. +asp_platform_helm_timeout: "300s" diff --git a/roles/asp_platform/tasks/contract.yaml b/roles/asp_platform/tasks/contract.yaml new file mode 100644 index 00000000..c3b9b2c5 --- /dev/null +++ b/roles/asp_platform/tasks/contract.yaml @@ -0,0 +1,93 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# asp-cluster-env is what the charts and the dashboard read (docs/TOOLKIT_ONBOARDING.md §3). +- name: "asp_platform | contract | The published contract" + kubernetes.core.k8s_info: + kind: ConfigMap + namespace: "{{ agentsysperf_sandbox_namespace }}" + name: asp-cluster-env + register: _asp_live_contract + +- name: "asp_platform | contract | Same major" + vars: + _live: "{{ ((_asp_live_contract.resources | first | default({})).data | default({})).AGENTSYSPERF_CONTRACT_VERSION | default('1') }}" + ansible.builtin.assert: + that: (_live | string).split('.') | first == '1' + fail_msg: "asp-cluster-env declares contract version {{ _live }}; this release writes version 1." + quiet: true + +- name: "asp_platform | contract | Driver node label, on that node only" + kubernetes.core.k8s: + state: patched + kind: Node + name: "{{ item }}" + definition: + metadata: + labels: + agentsysperf.intel.com/driver: "{{ 'true' if item == agentsysperf_driver_node else none }}" + loop: "{{ _asp_nodes }}" + when: agentsysperf_driver_node | length > 0 + +- name: "asp_platform | contract | Assemble" + vars: + _proxy: "{{ ('http://' ~ _asp_proxy_ips[0] ~ ':' ~ _asp_proxy_port) if _asp_proxy_ips | length > 0 else '' }}" + _llm: + OPENAI_API_BASE: "http://litellm.{{ _asp_litellm_ns }}.svc.cluster.local:4000" + AGENTSYSPERF_LLM_PATH: litellm + AGENTSYSPERF_GATEWAY_GUARDRAILS: "{{ guardrails_enabled | default(false) | bool | string | lower }}" + AGENTSYSPERF_GATEWAY_CACHE: "{{ litellm_cache_enabled | default(true) | bool | string | lower }}" + AGENTSYSPERF_GATEWAY_HYBRID_ROUTER: "{{ hybrid_router_enabled | default(false) | bool | string | lower }}" + ansible.builtin.set_fact: + _asp_contract: >- + {{ {'AGENTSYSPERF_CONTRACT_VERSION': '1', + 'AGENTSYSPERF_DRIVER_IMAGE': _asp_driver_image, + 'AGENTSYSPERF_IMAGE_PULL_POLICY': 'IfNotPresent', + 'AGENTSYSPERF_DRIVER_SA': agentsysperf_driver_sa, + 'AGENTSYSPERF_NODE_SELECTOR': (_asp_node_selector + | combine({'agentsysperf.intel.com/driver': 'true'} if agentsysperf_driver_node else {})) | to_json, + 'AGENTSYSPERF_TOLERATIONS': '[]', + 'AGENTSYSPERF_SOURCE_REF': _asp_source_ref if agentsysperf_image_source == 'build' else agentsysperf_image_tag, + 'SANDBOX_ROUTER_URL': 'http://sandbox-router-svc.' ~ agentsysperf_sandbox_namespace ~ '.svc.cluster.local:8080', + 'AGENTSYSPERF_DASHBOARD_URL': _asp_dashboard_url} + | combine({'AGENTSYSPERF_ROUTER_TOKEN_SECRET': 'asp-router-token', 'AGENTSYSPERF_ROUTER_TOKEN_SECRET_KEY': 'token'} + if _asp_router_v1 | bool else {}) + | combine(_llm if _asp_has_litellm | bool else {}) + | combine({'AGENTSYSPERF_LLM_MODEL': 'openai/' ~ agentsysperf_llm_model} + if _asp_has_litellm | bool and agentsysperf_llm_model | length > 0 else {}) + | combine({'AGENTSYSPERF_NRI_OWNER': 'toolkit'} if _asp_nri_owner == 'toolkit' else {}) + | combine({'AGENTSYSPERF_SANDBOX_NODES': agentsysperf_sandbox_nodes | to_json} if agentsysperf_sandbox_nodes | length > 0 else {}) + | combine({'AGENTSYSPERF_SANDBOX_POOL': agentsysperf_sandbox_pool} if agentsysperf_sandbox_pool | length > 0 else {}) + | combine({'AGENTSYSPERF_SANDBOX_NAMESERVERS': agentsysperf_public_nameservers | join(',')} + if not _proxy and agentsysperf_sandbox_dns == 'public' and agentsysperf_public_nameservers | length > 0 else {}) + | combine({'http_proxy': _proxy, 'https_proxy': _proxy, 'HTTP_PROXY': _proxy, 'HTTPS_PROXY': _proxy, + 'no_proxy': _asp_no_proxy, 'NO_PROXY': _asp_no_proxy} if _proxy else {}) + | combine({'LANGFUSE_HOST': _asp_langfuse.resources[0].data.LANGFUSE_HOST | b64decode, + 'AGENTSYSPERF_LANGFUSE_UI_URL': _asp_langfuse_ui_url} if _asp_has_langfuse | bool else {}) + | combine({'AGENTSYSPERF_PUSHGATEWAY': 'http://asp-pushgateway.' ~ agentsysperf_namespace ~ '.svc.cluster.local:9091', + 'AGENTSYSPERF_GRAFANA_URL': _asp_grafana_url} if agentsysperf_observability_enabled | bool else {}) }} + +# apply: keys this role never wrote (deploy/cluster/apply.sh's profile) are kept. +- name: "asp_platform | contract | asp-cluster-env in both namespaces" + kubernetes.core.k8s: + state: present + apply: true + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: asp-cluster-env + namespace: "{{ item }}" + labels: + app.kubernetes.io/part-of: agentsysperf + data: "{{ _asp_contract }}" + loop: + - "{{ agentsysperf_sandbox_namespace }}" + - "{{ agentsysperf_namespace }}" + +- name: "asp_platform | contract | Published" + ansible.builtin.debug: + msg: + - "Contract asp-cluster-env in {{ agentsysperf_sandbox_namespace }} and {{ agentsysperf_namespace }}: {{ _asp_contract | length }} keys" + - "Driver image {{ _asp_driver_image }} (source {{ _asp_source_ref }})" + - "LLM path: {{ 'LiteLLM, model ' ~ (agentsysperf_llm_model or 'unset') if _asp_has_litellm | bool else 'none' }}" diff --git a/roles/asp_platform/tasks/install.yaml b/roles/asp_platform/tasks/install.yaml new file mode 100644 index 00000000..5eff0272 --- /dev/null +++ b/roles/asp_platform/tasks/install.yaml @@ -0,0 +1,21 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +- name: "asp_platform | Checks before anything changes" + ansible.builtin.include_tasks: preflight.yaml + +- name: "asp_platform | Result store" + ansible.builtin.include_tasks: store.yaml + +- name: "asp_platform | Gateway key" + ansible.builtin.include_tasks: llm_key.yaml + when: agentsysperf_llm_key_enabled | bool and _asp_has_litellm | bool + +- name: "asp_platform | Driver RBAC" + ansible.builtin.include_tasks: runner.yaml + +- name: "asp_platform | Observability" + ansible.builtin.include_tasks: observability.yaml + +- name: "asp_platform | Contract" + ansible.builtin.include_tasks: contract.yaml diff --git a/roles/asp_platform/tasks/llm_key.yaml b/roles/asp_platform/tasks/llm_key.yaml new file mode 100644 index 00000000..dceb3d33 --- /dev/null +++ b/roles/asp_platform/tasks/llm_key.yaml @@ -0,0 +1,54 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# The raw key is returned once, so the Secret is the record: mint only when it is missing. +- name: "asp_platform | llm key | Existing Secret" + kubernetes.core.k8s_info: + kind: Secret + namespace: "{{ agentsysperf_sandbox_namespace }}" + name: asp-litellm-key + register: _asp_key_secret + no_log: true + +# Minted in the LiteLLM pod, so the master key never leaves it. No team or user: a +# non-admin key. Aliases outlive Secrets, so the old one is deleted first. +- name: "asp_platform | llm key | Mint a non-admin key" + kubernetes.core.k8s_exec: + namespace: "{{ _asp_litellm_ns }}" + pod: "{{ _asp_litellm_pods.resources[0].metadata.name }}" + container: litellm + command: "python -c \"import base64; exec(base64.b64decode('{{ _asp_mint_py | b64encode }}'))\"" + vars: + _asp_mint_py: | + import json, os, urllib.error, urllib.request + opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) + def call(path, body): + req = urllib.request.Request("http://127.0.0.1:4000" + path, json.dumps(body).encode(), + {"Authorization": "Bearer " + os.environ["PROXY_MASTER_KEY"], + "Content-Type": "application/json"}) + return json.load(opener.open(req, timeout=60)) + try: + call("/key/delete", {"key_aliases": ["{{ agentsysperf_llm_key_alias }}"]}) + except urllib.error.HTTPError as err: + if err.code not in (400, 404): + raise + body = {"key_alias": "{{ agentsysperf_llm_key_alias }}", "metadata": {"cache": {"no-cache": True} } } + print(call("/key/generate", body)["key"]) + register: _asp_key_minted + no_log: true + when: _asp_key_secret.resources | length == 0 or agentsysperf_rotate_llm_key | bool + +- name: "asp_platform | llm key | Store it" + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Secret + metadata: + name: asp-litellm-key + namespace: "{{ agentsysperf_sandbox_namespace }}" + type: Opaque + data: + OPENAI_API_KEY: "{{ _asp_key_minted.stdout | trim | b64encode }}" + no_log: true + when: _asp_key_minted is not skipped diff --git a/roles/asp_platform/tasks/main.yaml b/roles/asp_platform/tasks/main.yaml new file mode 100644 index 00000000..f3579c16 --- /dev/null +++ b/roles/asp_platform/tasks/main.yaml @@ -0,0 +1,18 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +- name: "asp_platform | dispatch | Assert supported action" + ansible.builtin.assert: + that: component_action | default('') in ['install', 'teardown', 'validate'] + fail_msg: "asp_platform: unsupported component_action='{{ component_action | default('') }}'" + quiet: true + +- name: "asp_platform | dispatch | Shared facts" + ansible.builtin.include_role: + name: asp_common + tasks_from: facts.yaml + public: true + +- name: "asp_platform | dispatch | Include {{ component_action }}" + ansible.builtin.include_tasks: + file: "{{ component_action }}.yaml" diff --git a/roles/asp_platform/tasks/observability.yaml b/roles/asp_platform/tasks/observability.yaml new file mode 100644 index 00000000..e80c7943 --- /dev/null +++ b/roles/asp_platform/tasks/observability.yaml @@ -0,0 +1,72 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +- name: "asp_platform | observability | ServiceMonitor CRD" + kubernetes.core.k8s_info: + api_version: apiextensions.k8s.io/v1 + kind: CustomResourceDefinition + name: servicemonitors.monitoring.coreos.com + register: _asp_sm_crd + when: agentsysperf_observability_enabled | bool + +# AgentSysPerf's own manifest, with what Pod Security "restricted" needs (the image's nobody user). +- name: "asp_platform | observability | Pushgateway that runs push to" + kubernetes.core.k8s: + state: present + definition: >- + {%- set out = [] -%} + {%- for d in _asp_pgw_docs -%} + {%- if d.kind == 'Deployment' -%} + {%- set cs = d.spec.template.spec.containers | map('combine', {'securityContext': _asp_pgw_ctr_sc}, recursive=True) | list -%} + {%- set d = d | combine({'spec': {'template': {'spec': {'securityContext': _asp_pgw_pod_sc, 'containers': cs}}}}, recursive=True) -%} + {%- endif -%} + {%- set _ = out.append(d) -%} + {%- endfor -%} + {{ out }} + vars: + _asp_pgw_docs: >- + {{ lookup('ansible.builtin.file', _asp_repo ~ '/deploy/observability/pushgateway.yaml') | from_yaml_all | select | list + | rejectattr('kind', 'equalto', 'ServiceMonitor' if _asp_sm_crd.resources | default([]) | length == 0 else '') | list }} + _asp_pgw_pod_sc: {runAsNonRoot: true, runAsUser: 65534, runAsGroup: 65534, seccompProfile: {type: RuntimeDefault}} + _asp_pgw_ctr_sc: {allowPrivilegeEscalation: false, capabilities: {drop: [ALL]}} + when: agentsysperf_observability_enabled | bool + +# The platform Grafana loads grafana_dashboard="1" ConfigMaps from every namespace. +- name: "asp_platform | observability | Grafana dashboards" + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: "{{ item.name }}" + namespace: "{{ agentsysperf_namespace }}" + labels: + grafana_dashboard: "1" + data: "{{ {item.file: lookup('ansible.builtin.file', _asp_repo ~ '/monitoring/grafana/dashboards/' ~ item.file)} }}" + loop: + - {name: asp-grafana-dashboard, file: agentsysperf_dashboard.json} + - {name: asp-grafana-streams, file: asp_streams_compare.json} + loop_control: + label: "{{ item.name }}" + when: agentsysperf_observability_enabled | bool + +# LiteLLM already traces to Langfuse; the dashboard's trace page reads with the same keys. +- name: "asp_platform | observability | Langfuse keys" + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Secret + metadata: + name: asp-langfuse + namespace: "{{ item }}" + type: Opaque + data: + LANGFUSE_PUBLIC_KEY: "{{ _asp_langfuse.resources[0].data.LANGFUSE_PUBLIC_KEY }}" + LANGFUSE_SECRET_KEY: "{{ _asp_langfuse.resources[0].data.LANGFUSE_SECRET_KEY }}" + loop: + - "{{ agentsysperf_namespace }}" + - "{{ agentsysperf_sandbox_namespace }}" + no_log: true + when: _asp_has_langfuse | bool diff --git a/roles/asp_platform/tasks/preflight.yaml b/roles/asp_platform/tasks/preflight.yaml new file mode 100644 index 00000000..edb9debf --- /dev/null +++ b/roles/asp_platform/tasks/preflight.yaml @@ -0,0 +1,112 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +- name: "asp_platform | preflight | Supported here" + ansible.builtin.assert: + that: (cluster_distribution | default('kubernetes')) != 'openshift' + fail_msg: "AgentSysPerf does not support OpenShift yet: set agentsysperf_enabled: false." + quiet: true + +- name: "asp_platform | preflight | Dashboard routing" + ansible.builtin.assert: + that: not (agentsysperf_dashboard_enabled | bool) or (routing_mode | default('subdomain')) == 'subdomain' + fail_msg: "The AgentSysPerf dashboard needs routing_mode: subdomain; or set agentsysperf_dashboard_enabled: false." + quiet: true + +- name: "asp_platform | preflight | Image source" + ansible.builtin.assert: + that: >- + agentsysperf_image_source == 'build' + or (agentsysperf_image_source == 'registry' and agentsysperf_registry | length > 0 and agentsysperf_image_tag | length > 0) + fail_msg: "agentsysperf_image_source is build or registry; registry needs agentsysperf_registry and agentsysperf_image_tag." + quiet: true + +- name: "asp_platform | preflight | The proxy resolves" + ansible.builtin.assert: + that: not _asp_proxy_url or _asp_proxy_ips | length > 0 + fail_msg: "The proxy in {{ _asp_proxy_url }} does not resolve on this host: task pods get it by address." + quiet: true + +- name: "asp_platform | preflight | The toolkit's pgvector" + kubernetes.core.k8s_info: + kind: Pod + namespace: "{{ _asp_pgvector_ns }}" + label_selectors: [app.kubernetes.io/name=pgvector] + field_selectors: [status.phase=Running] + register: _asp_pgv_pods + +- name: "asp_platform | preflight | pgvector runs" + ansible.builtin.assert: + that: _asp_pgv_pods.resources | length > 0 + fail_msg: "AgentSysPerf stores its results on the toolkit's pgvector, which is not running: set pgvector_enabled: true." + quiet: true + +- name: "asp_platform | preflight | agent-sandbox pieces" + kubernetes.core.k8s_info: + api_version: "{{ item.api }}" + kind: "{{ item.kind }}" + namespace: "{{ item.ns | default(omit) }}" + name: "{{ item.name }}" + loop: + - {api: apiextensions.k8s.io/v1, kind: CustomResourceDefinition, name: sandboxes.agents.x-k8s.io} + - {api: v1, kind: Service, ns: "{{ agentsysperf_sandbox_namespace }}", name: sandbox-router-svc} + loop_control: + label: "{{ item.kind }}/{{ item.name }}" + register: _asp_sandbox_deps + +- name: "asp_platform | preflight | agent-sandbox runs" + ansible.builtin.assert: + that: + - _asp_sandbox_deps.results | selectattr('resources', 'equalto', []) | list | length == 0 + - (_asp_router_v1 | bool) != (_asp_router_v0 | bool) + fail_msg: >- + AgentSysPerf runs its tasks in agent-sandbox pods: it needs agent_sandbox_enabled: true and exactly + one sandbox router Deployment (sandbox-router or sandbox-router-deployment; delete a stale one). + quiet: true + +- name: "asp_platform | preflight | Router policies" + kubernetes.core.k8s_info: + api_version: networking.k8s.io/v1 + kind: NetworkPolicy + namespace: "{{ agentsysperf_sandbox_namespace }}" + register: _asp_netpols + when: _asp_istio | bool and _asp_router_v1 | bool + +# The driver stays in the ambient mesh, so its calls reach the router as HBONE on 15008. +- name: "asp_platform | preflight | The router admits mesh traffic" + vars: + _router_labels: [["app.kubernetes.io/name", "sandbox-router"], ["app.kubernetes.io/component", "sandbox-router"]] + _hbone: >- + {%- set found = namespace(ok=false) -%} + {%- for p in _asp_netpols.resources | default([]) -%} + {%- set sel = p.spec.podSelector | default({}) -%} + {%- set match = sel.matchLabels | default({}) -%} + {%- if sel.matchExpressions | default([]) | length == 0 + and match.items() | map('list') | list | difference(_router_labels) | length == 0 -%} + {%- for rule in p.spec.ingress | default([]) -%} + {%- if rule.ports is not defined + or rule.ports | map(attribute='port', default='') | map('string') | select('equalto', '15008') | list | length > 0 -%} + {%- set found.ok = true -%} + {%- endif -%} + {%- endfor -%} + {%- endif -%} + {%- endfor -%} + {{ found.ok }} + ansible.builtin.assert: + that: _hbone | bool + fail_msg: >- + The sandbox router admits no Istio ambient traffic (TCP 15008), so the driver cannot reach it. + Update the agent-toolkit layer to a release whose agent_sandbox role admits 15008 to the router. + quiet: true + when: _asp_istio | bool and _asp_router_v1 | bool + +- name: "asp_platform | preflight | What runs will lack" + vars: + _gaps: >- + {{ ([] if _asp_has_litellm | bool else ['LiteLLM is not running: tb2-gateway and live runs have no gateway']) + + ([] if agentsysperf_llm_model | length > 0 else ['agentsysperf_llm_model is empty: set the model the gateway serves']) + + ([] if _asp_proxy_ips | length > 0 or agentsysperf_public_nameservers | length > 0 or agentsysperf_sandbox_dns == 'none' + else ['no proxy and no agentsysperf_public_nameservers: image-mode task pods cannot resolve package indexes']) }} + ansible.builtin.debug: + msg: "{{ _gaps }}" + when: _gaps | length > 0 diff --git a/roles/asp_platform/tasks/runner.yaml b/roles/asp_platform/tasks/runner.yaml new file mode 100644 index 00000000..a9b9f7f8 --- /dev/null +++ b/roles/asp_platform/tasks/runner.yaml @@ -0,0 +1,58 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Behind a proxy the task pods may reach it, by address, and nothing else private. +- name: "asp_platform | runner | Task-pod egress" + ansible.builtin.set_fact: + _asp_sandbox_egress: >- + {{ {'enabled': true, + 'proxyCidrs': _asp_proxy_ips | map('regex_replace', '$', '/32') | list, + 'proxyPorts': [_asp_proxy_port | int]} + if _asp_proxy_ips | length > 0 else {'enabled': false} }} + +- name: "asp_platform | runner | Driver ServiceAccount and RBAC (asp-runner)" + kubernetes.core.helm: + name: asp-runner + chart_ref: "{{ _asp_repo }}/deploy/chart" + release_namespace: "{{ agentsysperf_sandbox_namespace }}" + values: + run: + enabled: false + serviceAccount: + name: "{{ agentsysperf_driver_sa }}" + persistence: + mode: ephemeral + rbac: + balloonPolicy: + enabled: "{{ _asp_nri_owner == 'toolkit' }}" + sandboxEgress: "{{ _asp_sandbox_egress }}" + wait: true + timeout: "{{ asp_platform_helm_timeout }}" + +# agent-sandbox v1.x authenticates router calls with a ServiceAccount token (TokenReview, +# no audience). Until the driver reads its own rotated token, this Secret holds one. +- name: "asp_platform | runner | Router token for the driver" + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Secret + type: kubernetes.io/service-account-token + metadata: + name: asp-router-token + namespace: "{{ agentsysperf_sandbox_namespace }}" + annotations: + kubernetes.io/service-account.name: "{{ agentsysperf_driver_sa }}" + when: _asp_router_v1 | bool + +- name: "asp_platform | runner | Wait for the token" + kubernetes.core.k8s_info: + kind: Secret + namespace: "{{ agentsysperf_sandbox_namespace }}" + name: asp-router-token + register: _asp_router_token + until: (_asp_router_token.resources | first | default({})).data.token is defined + retries: 12 + delay: 5 + no_log: true + when: _asp_router_v1 | bool diff --git a/roles/asp_platform/tasks/store.yaml b/roles/asp_platform/tasks/store.yaml new file mode 100644 index 00000000..59ed841d --- /dev/null +++ b/roles/asp_platform/tasks/store.yaml @@ -0,0 +1,74 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# In the mesh: the toolkit's mTLS is strict, so a pod outside it cannot reach pgvector. +- name: "asp_platform | store | Namespace {{ agentsysperf_namespace }}" + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Namespace + metadata: + name: "{{ agentsysperf_namespace }}" + labels: >- + {{ ({'istio.io/dataplane-mode': 'ambient'} if _asp_istio | bool else {}) + | combine({'pod-security.kubernetes.io/enforce': 'restricted', + 'pod-security.kubernetes.io/audit': 'restricted', + 'pod-security.kubernetes.io/warn': 'restricted'} if enforce_pss | default(false) | bool else {}) }} + +- name: "asp_platform | store | pgvector credentials" + kubernetes.core.k8s_info: + kind: Secret + namespace: "{{ _asp_pgvector_ns }}" + name: pgvector-credentials + register: _asp_pgv_secret + no_log: true + +- name: "asp_platform | store | Users" + vars: + _d: "{{ _asp_pgv_secret.resources[0].data }}" + ansible.builtin.set_fact: + _asp_pg_su: "{{ _d.POSTGRES_USER | b64decode }}" + _asp_pg_user: "{{ (_d.username | default(_d.POSTGRES_USER)) | b64decode }}" + _asp_pg_pass: "{{ (_d.password | default(_d.POSTGRES_PASSWORD)) | b64decode }}" + no_log: true + +# psql over the pod's local socket, which pgvector trusts. +- name: "asp_platform | store | Is {{ agentsysperf_store_database }} there" + kubernetes.core.k8s_exec: + namespace: "{{ _asp_pgvector_ns }}" + pod: "{{ _asp_pgv_pods.resources[0].metadata.name }}" + command: >- + psql -U {{ _asp_pg_su }} -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='{{ agentsysperf_store_database }}'" + register: _asp_db_check + changed_when: false + check_mode: false + +- name: "asp_platform | store | Create {{ agentsysperf_store_database }}" + kubernetes.core.k8s_exec: + namespace: "{{ _asp_pgvector_ns }}" + pod: "{{ _asp_pgv_pods.resources[0].metadata.name }}" + command: >- + psql -U {{ _asp_pg_su }} -d postgres -c "CREATE DATABASE {{ agentsysperf_store_database }} OWNER {{ _asp_pg_user }}" + when: (_asp_db_check.stdout | default('') | trim) != '1' + +# Keepalives: a run holds one connection idle through the whole agent phase. +- name: "asp_platform | store | DSN Secret in both namespaces" + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Secret + metadata: + name: asp-pg-dsn + namespace: "{{ item }}" + type: Opaque + data: + dsn: >- + {{ ('postgresql://' ~ (_asp_pg_user | urlencode) ~ ':' ~ (_asp_pg_pass | urlencode) + ~ '@pgvector.' ~ _asp_pgvector_ns ~ '.svc.cluster.local:5432/' ~ agentsysperf_store_database + ~ '?keepalives=1&keepalives_idle=300&keepalives_interval=30&keepalives_count=3') | b64encode }} + loop: + - "{{ agentsysperf_namespace }}" + - "{{ agentsysperf_sandbox_namespace }}" + no_log: true diff --git a/roles/asp_platform/tasks/teardown.yaml b/roles/asp_platform/tasks/teardown.yaml new file mode 100644 index 00000000..f4f92b22 --- /dev/null +++ b/roles/asp_platform/tasks/teardown.yaml @@ -0,0 +1,97 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# After the labelled objects are gone: what labels cannot take back, and the objects +# themselves in an env no install labelled. Safe when nothing was installed. +- name: "asp_platform | teardown | Revoke the gateway key" + kubernetes.core.k8s_exec: + namespace: "{{ _asp_litellm_ns }}" + pod: "{{ _asp_litellm_pods.resources[0].metadata.name }}" + container: litellm + command: "python -c \"import base64; exec(base64.b64decode('{{ _asp_revoke_py | b64encode }}'))\"" + vars: + _asp_revoke_py: | + import json, os, urllib.request + opener = urllib.request.build_opener(urllib.request.ProxyHandler({})) + req = urllib.request.Request("http://127.0.0.1:4000/key/delete", + json.dumps({"key_aliases": ["{{ agentsysperf_llm_key_alias }}"]}).encode(), + {"Authorization": "Bearer " + os.environ["PROXY_MASTER_KEY"], + "Content-Type": "application/json"}) + try: + opener.open(req, timeout=60) + print("revoked") + except Exception as err: + print("not revoked: %s" % err) + register: _asp_revoke + changed_when: "'revoked' == (_asp_revoke.stdout | default('') | trim)" + failed_when: false + no_log: true + when: _asp_has_litellm | bool + +- name: "asp_platform | teardown | pgvector" + kubernetes.core.k8s_info: + kind: Pod + namespace: "{{ _asp_pgvector_ns }}" + label_selectors: [app.kubernetes.io/name=pgvector] + field_selectors: [status.phase=Running] + register: _asp_t_pgv + when: agentsysperf_teardown_delete_results | bool + +- name: "asp_platform | teardown | pgvector superuser" + kubernetes.core.k8s_info: + kind: Secret + namespace: "{{ _asp_pgvector_ns }}" + name: pgvector-credentials + register: _asp_t_pgv_secret + no_log: true + when: agentsysperf_teardown_delete_results | bool + +- name: "asp_platform | teardown | Drop {{ agentsysperf_store_database }} (agentsysperf_teardown_delete_results)" + kubernetes.core.k8s_exec: + namespace: "{{ _asp_pgvector_ns }}" + pod: "{{ _asp_t_pgv.resources[0].metadata.name }}" + command: >- + psql -U {{ _asp_t_pgv_secret.resources[0].data.POSTGRES_USER | b64decode }} + -d postgres -c "DROP DATABASE IF EXISTS {{ agentsysperf_store_database }} WITH (FORCE)" + when: + - agentsysperf_teardown_delete_results | bool + - _asp_t_pgv.resources | default([]) | length > 0 + - _asp_t_pgv_secret.resources | default([]) | length > 0 + +- name: "asp_platform | teardown | Driver RBAC release" + kubernetes.core.helm: + name: asp-runner + release_namespace: "{{ agentsysperf_sandbox_namespace }}" + state: absent + wait: true + +- name: "asp_platform | teardown | Contract and Secrets" + kubernetes.core.k8s: + state: absent + api_version: v1 + kind: "{{ item.kind }}" + namespace: "{{ agentsysperf_sandbox_namespace }}" + name: "{{ item.name }}" + loop: + - {kind: ConfigMap, name: asp-cluster-env} + - {kind: Secret, name: asp-pg-dsn} + - {kind: Secret, name: asp-litellm-key} + - {kind: Secret, name: asp-langfuse} + - {kind: Secret, name: asp-router-token} + loop_control: + label: "{{ item.kind }}/{{ item.name }}" + +- name: "asp_platform | teardown | Namespace {{ agentsysperf_namespace }}" + kubernetes.core.k8s: + state: absent + api_version: v1 + kind: Namespace + name: "{{ agentsysperf_namespace }}" + wait: true + wait_timeout: 300 + +- name: "asp_platform | teardown | Results" + ansible.builtin.debug: + msg: >- + {{ 'Dropped ' ~ agentsysperf_store_database ~ '.' if agentsysperf_teardown_delete_results | bool + else 'Kept the results database ' ~ agentsysperf_store_database ~ ' on pgvector (agentsysperf_teardown_delete_results: true drops it).' }} diff --git a/roles/asp_platform/tasks/validate.yaml b/roles/asp_platform/tasks/validate.yaml new file mode 100644 index 00000000..520c91c8 --- /dev/null +++ b/roles/asp_platform/tasks/validate.yaml @@ -0,0 +1,76 @@ +# Copyright (C) 2026 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +--- +# Read-only. +- name: "asp_platform | validate | Contract" + kubernetes.core.k8s_info: + kind: ConfigMap + namespace: "{{ item }}" + name: asp-cluster-env + loop: + - "{{ agentsysperf_sandbox_namespace }}" + - "{{ agentsysperf_namespace }}" + register: _asp_v_contract + +- name: "asp_platform | validate | Secrets and the driver's ServiceAccount" + kubernetes.core.k8s_info: + kind: "{{ item.kind }}" + namespace: "{{ item.ns }}" + name: "{{ item.name }}" + loop: >- + {{ [{'kind': 'Secret', 'ns': agentsysperf_sandbox_namespace, 'name': 'asp-pg-dsn'}, + {'kind': 'Secret', 'ns': agentsysperf_namespace, 'name': 'asp-pg-dsn'}, + {'kind': 'ServiceAccount', 'ns': agentsysperf_sandbox_namespace, 'name': agentsysperf_driver_sa}] + + ([{'kind': 'Secret', 'ns': agentsysperf_sandbox_namespace, 'name': 'asp-litellm-key'}] + if agentsysperf_llm_key_enabled | bool and _asp_has_litellm | bool else []) + + ([{'kind': 'Secret', 'ns': agentsysperf_sandbox_namespace, 'name': 'asp-router-token'}] if _asp_router_v1 | bool else []) }} + loop_control: + label: "{{ item.kind }} {{ item.ns }}/{{ item.name }}" + register: _asp_v_objects + no_log: true + +- name: "asp_platform | validate | Result store" + kubernetes.core.k8s_info: + kind: Pod + namespace: "{{ _asp_pgvector_ns }}" + label_selectors: [app.kubernetes.io/name=pgvector] + field_selectors: [status.phase=Running] + register: _asp_v_pgv + +- name: "asp_platform | validate | pgvector superuser" + kubernetes.core.k8s_info: + kind: Secret + namespace: "{{ _asp_pgvector_ns }}" + name: pgvector-credentials + register: _asp_v_pgv_secret + no_log: true + +- name: "asp_platform | validate | {{ agentsysperf_store_database }} exists" + kubernetes.core.k8s_exec: + namespace: "{{ _asp_pgvector_ns }}" + pod: "{{ _asp_v_pgv.resources[0].metadata.name }}" + command: >- + psql -U {{ _asp_v_pgv_secret.resources[0].data.POSTGRES_USER | b64decode }} + -d postgres -tAc "SELECT count(*) FROM pg_database WHERE datname='{{ agentsysperf_store_database }}'" + register: _asp_v_db + changed_when: false + failed_when: false + check_mode: false + when: _asp_v_pgv.resources | length > 0 and _asp_v_pgv_secret.resources | length > 0 + +- name: "asp_platform | validate | Report" + vars: + _contract_ok: >- + {{ _asp_v_contract.results | map(attribute='resources') | map('length') | min > 0 + and (_asp_v_contract.results[0].resources[0].data.AGENTSYSPERF_CONTRACT_VERSION | default('1') | string).split('.') | first == '1' }} + _missing: "{{ _asp_v_objects.results | selectattr('resources', 'equalto', []) | map(attribute='item') | map(attribute='name') | list }}" + _db_ok: "{{ (_asp_v_db.stdout | default('') | trim) == '1' }}" + ansible.builtin.assert: + that: + - _contract_ok | bool + - _missing | length == 0 + - _db_ok | bool + fail_msg: >- + AgentSysPerf platform: contract {{ 'ok' if _contract_ok | bool else 'MISSING or another major' }}; + missing objects {{ _missing }}; result store {{ 'ok' if _db_ok | bool else 'MISSING' }}. + success_msg: "AgentSysPerf platform: contract v1 in both namespaces, Secrets, driver RBAC and {{ agentsysperf_store_database }} present." diff --git a/roles/pgvector/defaults/main.yaml b/roles/pgvector/defaults/main.yaml index 05c17294..97326930 100644 --- a/roles/pgvector/defaults/main.yaml +++ b/roles/pgvector/defaults/main.yaml @@ -21,12 +21,10 @@ pgvector_password: "{{ lookup('password', '/dev/null length=24 chars=ascii_lette # Resources -pgvector_resources: - requests: - cpu: "250m" - memory: "512Mi" - limits: - cpu: "2" - memory: "2Gi" +# Larger while AgentSysPerf is on: its run-streams ladders hold one connection per slot (+ 10) +pgvector_resources: >- + {{ {'requests': {'cpu': '1', 'memory': '2Gi'}, 'limits': {'cpu': '8', 'memory': '8Gi'}} + if agentsysperf_enabled | default(false) | bool + else {'requests': {'cpu': '250m', 'memory': '512Mi'}, 'limits': {'cpu': '2', 'memory': '2Gi'}} }} # PostgreSQL server settings, e.g. max_connections: 600; empty keeps the image defaults -pgvector_parameters: {} +pgvector_parameters: "{{ {'max_connections': '600', 'shared_buffers': '1GB'} if agentsysperf_enabled | default(false) | bool else {} }}"