diff --git a/ci/playbooks/install-openstack-lightspeed.yml b/ci/playbooks/install-openstack-lightspeed.yml new file mode 100644 index 00000000..b5492197 --- /dev/null +++ b/ci/playbooks/install-openstack-lightspeed.yml @@ -0,0 +1,548 @@ +--- +# Copyright Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +- name: Deploy OpenStack Lightspeed operator + hosts: "{{ cifmw_target_hook_host | default('localhost') }}" + connection: local + vars: + # OpenStack Lightspeed configuration + # Note: Using openstack-lightspeed namespace per operator's suggested namespace + openstack_lightspeed_namespace: "{{ cifmw_openstack_lightspeed_namespace | default('openstack-lightspeed') }}" + openstack_lightspeed_operator_group: "{{ cifmw_openstack_lightspeed_operator_group | default('openstack-lightspeed-operator-group') }}" + openstack_lightspeed_catalog_image: "{{ cifmw_openstack_lightspeed_catalog_image | default('quay.io/openstack-lightspeed/operator-catalog:latest') }}" + openstack_lightspeed_catalog_name: "{{ cifmw_openstack_lightspeed_catalog_name | default('openstack-lightspeed-catalog') }}" + + # Kubeconfig path - use user-provided or default to CRC location + kubeconfig_path: "{{ cifmw_openshift_kubeconfig | default(ansible_env.HOME ~ '/.crc/machines/crc/kubeconfig') }}" + environment: + KUBECONFIG: "{{ kubeconfig_path }}" + + tasks: + - name: Install and wait for OpenStack Lightspeed + block: + # STEP 1: Deploy OpenStack Lightspeed catalog + + - name: Create CatalogSource for OpenStack Lightspeed + kubernetes.core.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: CatalogSource + metadata: + name: "{{ openstack_lightspeed_catalog_name }}" + namespace: "openshift-marketplace" + spec: + sourceType: grpc + image: "{{ openstack_lightspeed_catalog_image }}" + displayName: "OpenStack Lightspeed Operator" + publisher: "Red Hat" + + - name: Wait for CatalogSource to be ready + kubernetes.core.k8s_info: + api_version: operators.coreos.com/v1alpha1 + kind: CatalogSource + name: "{{ openstack_lightspeed_catalog_name }}" + namespace: "openshift-marketplace" + register: catalog_source + until: + - catalog_source.resources is defined + - catalog_source.resources | length > 0 + - catalog_source.resources[0].status.connectionState.lastObservedState is defined + - catalog_source.resources[0].status.connectionState.lastObservedState == "READY" + retries: 30 + delay: 10 + + # STEP 2: Deploy OpenStack Lightspeed operator + # Note: OpenStack Lightspeed operator will automatically install + # and manage the OpenShift Lightspeed operator as a dependency + + - name: Create namespace for OpenStack Lightspeed + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Namespace + metadata: + name: "{{ openstack_lightspeed_namespace }}" + + - name: Create OperatorGroup for OpenStack Lightspeed + kubernetes.core.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1 + kind: OperatorGroup + metadata: + name: "{{ openstack_lightspeed_operator_group }}" + namespace: "{{ openstack_lightspeed_namespace }}" + spec: + targetNamespaces: + - "{{ openstack_lightspeed_namespace }}" + + - name: Subscribe to OpenStack Lightspeed operator + kubernetes.core.k8s: + state: present + definition: + apiVersion: operators.coreos.com/v1alpha1 + kind: Subscription + metadata: + name: "openstack-lightspeed-operator" + namespace: "{{ openstack_lightspeed_namespace }}" + spec: + channel: "alpha" + name: "openstack-lightspeed-operator" + source: "{{ openstack_lightspeed_catalog_name }}" + sourceNamespace: "openshift-marketplace" + installPlanApproval: "Automatic" + + - name: Wait for OpenStack Lightspeed CSV to be ready + kubernetes.core.k8s_info: + api_version: operators.coreos.com/v1alpha1 + kind: ClusterServiceVersion + namespace: "{{ openstack_lightspeed_namespace }}" + label_selectors: + - "operators.coreos.com/openstack-lightspeed-operator.{{ openstack_lightspeed_namespace }}" + register: osls_csv + until: + - osls_csv.resources is defined + - osls_csv.resources | length > 0 + - osls_csv.resources[0].status.phase is defined + - osls_csv.resources[0].status.phase == "Succeeded" + retries: 30 + delay: 10 + + # STEP 3: Create prerequisites (secrets and certificates) + + - name: Deploy the mock LLM provider + when: cifmw_openstack_lightspeed_mock_enabled | default(false) | bool + block: + - name: Create mock LLM API server code ConfigMap + register: mock_code + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: mock-llm-code + namespace: "{{ openstack_lightspeed_namespace }}" + data: + app.py: | + import json + import uuid + + from fastapi import FastAPI, Request + from fastapi.responses import JSONResponse, StreamingResponse + + app = FastAPI() + mock_model = {{ cifmw_openstack_lightspeed_model_name | to_json }} + + def retrieval_call(body): + # Ask OGX to retrieve real documents once per user turn. + messages = body.get("messages") or [] + user_index = next(( + i for i in range(len(messages) - 1, -1, -1) + if messages[i].get("role") == "user" + ), None) + if user_index is None or any( + message.get("role") == "tool" for message in messages[user_index + 1:] + ): + return None + tool_choice = body.get("tool_choice", "auto") + if tool_choice == "none": + return None + query = messages[user_index].get("content") + if isinstance(query, list): + query = "\n".join(part["text"] for part in query if part.get("type") == "text") + if not query: + return None + for tool in body.get("tools") or []: + function = tool.get("function", {}) + name = function.get("name") + if tool.get("type") != "function" or name not in ("file_search", "knowledge_search"): + continue + if isinstance(tool_choice, dict) and tool_choice.get("function", {}).get("name") != name: + continue + return { + "id": "call_" + uuid.uuid4().hex, + "type": "function", + "function": {"name": name, "arguments": json.dumps({"query": query})}, + } + return None + + @app.get("/v1/models") + async def models_get(): + return { + "object": "list", + "data": [{ + "id": mock_model, + "object": "model", + "created": 1234567890, + "owned_by": "mock", + }], + } + + @app.post("/v1/chat/completions") + async def completions_post(request: Request): + try: + body = await request.json() + except Exception: + body = {} + + if not isinstance(body, dict): + body = {} + model = body.get("model") or mock_model + + # The OpenAI API expects 'messages' (for chat) or 'prompt' (for completions), but for mock, we will accept either + response = { + "id": "cmpl-123", + "object": "chat.completion", + "created": 1234567890, + "model": model, + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "Hello, this is a dummy chat completion." + }, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 5, + "completion_tokens": 7, + "total_tokens": 12 + } + } + + choice = response["choices"][0] + tool_call = retrieval_call(body) + if tool_call is not None: + choice["message"]["content"] = None + choice["message"]["tool_calls"] = [tool_call] + choice["finish_reason"] = "tool_calls" + + # The provider adapter requests streaming even for /v1/query. + if body.get("stream"): + def stream_chunks(): + chunk = { + "id": response["id"], + "object": "chat.completion.chunk", + "created": response["created"], + "model": model, + } + delta = {"content": choice["message"]["content"]} + if tool_call is not None: + delta = {"tool_calls": [{"index": 0, **tool_call}]} + for delta, finish_reason in [ + ({"role": "assistant"}, None), + (delta, None), + ({}, choice["finish_reason"]), + ]: + chunk["choices"] = [{ + "index": 0, + "delta": delta, + "finish_reason": finish_reason, + }] + yield "data: " + json.dumps(chunk) + "\n\n" + + stream_options = body.get("stream_options") or {} + if stream_options.get("include_usage"): + chunk["choices"] = [] + chunk["usage"] = response["usage"] + yield "data: " + json.dumps(chunk) + "\n\n" + yield "data: [DONE]\n\n" + + return StreamingResponse(stream_chunks(), media_type="text/event-stream") + + return JSONResponse(content=response) + + - name: Inspect the existing mock LLM Pod + kubernetes.core.k8s_info: + api_version: v1 + kind: Pod + name: mock-llm-api-server-pod + namespace: "{{ openstack_lightspeed_namespace }}" + register: existing_mock_pod + + - name: Restart mock LLM when its code or readiness configuration changes + kubernetes.core.k8s: + state: absent + api_version: v1 + kind: Pod + name: mock-llm-api-server-pod + namespace: "{{ openstack_lightspeed_namespace }}" + wait: true + when: >- + mock_code is changed or + (existing_mock_pod.resources | length > 0 and + existing_mock_pod.resources[0].spec.containers[0].readinessProbe is not defined) + + - name: Create mock LLM API server Pod + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Pod + metadata: + name: mock-llm-api-server-pod + namespace: "{{ openstack_lightspeed_namespace }}" + labels: + app: mock-llm-api-server-pod + spec: + containers: + - name: mock-llm-api-server + image: registry.redhat.io/ubi8/python-311:latest + readinessProbe: + tcpSocket: + port: 8000 + periodSeconds: 5 + ports: + - containerPort: 8000 + volumeMounts: + - name: app-code + mountPath: /app + workingDir: /app + command: + - sh + - -c + - | + pip install "fastapi[standard]" && \ + uvicorn app:app --host 0.0.0.0 --port 8000 + volumes: + - name: app-code + configMap: + name: mock-llm-code + + - name: Create mock LLM API server Service + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Service + metadata: + name: mock-llm-api-server-pod + namespace: "{{ openstack_lightspeed_namespace }}" + spec: + selector: + app: mock-llm-api-server-pod + ports: + - protocol: TCP + port: 8000 + targetPort: 8000 + + - name: Wait for mock LLM API server to be ready + kubernetes.core.k8s_info: + api_version: v1 + kind: Pod + name: mock-llm-api-server-pod + namespace: "{{ openstack_lightspeed_namespace }}" + wait: true + wait_condition: + type: Ready + status: "True" + wait_timeout: 300 + + - name: Create LLM API token secret + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Secret + metadata: + name: "{{ cifmw_openstack_lightspeed_llm_credentials | default('openstack-lightspeed-apitoken') }}" + namespace: "{{ openstack_lightspeed_namespace }}" + stringData: + apitoken: "{{ cifmw_openstack_lightspeed_api_token }}" + when: cifmw_openstack_lightspeed_api_token is defined + no_log: true + + - name: Verify LLM credentials secret exists + kubernetes.core.k8s_info: + kind: Secret + name: "{{ cifmw_openstack_lightspeed_llm_credentials | default('openstack-lightspeed-apitoken') }}" + namespace: "{{ openstack_lightspeed_namespace }}" + register: secret_check + failed_when: secret_check.resources | length == 0 + when: cifmw_openstack_lightspeed_api_token is not defined + no_log: true + + - name: Download TLS CA certificate from URL + ansible.builtin.uri: + url: "{{ cifmw_openstack_lightspeed_ca_cert_url }}" + return_content: true + register: ca_cert_download + when: cifmw_openstack_lightspeed_ca_cert_url is defined + + - name: Create TLS CA certificate bundle ConfigMap + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: "{{ cifmw_openstack_lightspeed_tls_ca_cert_bundle | default('openstack-lightspeed-certs') }}" + namespace: "{{ openstack_lightspeed_namespace }}" + data: + ca-bundle.crt: >- + {{ ca_cert_download.content if cifmw_openstack_lightspeed_ca_cert_url is defined else cifmw_openstack_lightspeed_ca_cert }} + when: cifmw_openstack_lightspeed_ca_cert_url is defined or cifmw_openstack_lightspeed_ca_cert is defined + + - name: Verify TLS certificate bundle ConfigMap exists + kubernetes.core.k8s_info: + kind: ConfigMap + name: "{{ cifmw_openstack_lightspeed_tls_ca_cert_bundle | default('openstack-lightspeed-certs') }}" + namespace: "{{ openstack_lightspeed_namespace }}" + register: cert_check + failed_when: cert_check.resources | length == 0 + when: cifmw_openstack_lightspeed_ca_cert_url is defined or cifmw_openstack_lightspeed_ca_cert is defined + + # STEP 4: Create OpenStackLightspeed CR to deploy the service + # Note: Uses configurable parameters for LLM integration + + - name: Create OpenStackLightspeed custom resource + kubernetes.core.k8s: + state: present + definition: + apiVersion: lightspeed.openstack.org/v1beta1 + kind: OpenStackLightspeed + metadata: + name: "{{ cifmw_openstack_lightspeed_cr_name | default('openstacklightspeed-sample') }}" + namespace: "{{ openstack_lightspeed_namespace }}" + spec: + ogx: >- + {{ {'containerImage': cifmw_openstack_lightspeed_ogx_image} + if cifmw_openstack_lightspeed_ogx_image is defined else omit }} + defaultModel: default-model + models: + - name: default-model + llmEndpoint: "{{ cifmw_openstack_lightspeed_llm_endpoint }}" + llmEndpointType: "{{ cifmw_openstack_lightspeed_llm_endpoint_type | default('openai') }}" + modelName: "{{ cifmw_openstack_lightspeed_model_name }}" + llmCredentials: "{{ cifmw_openstack_lightspeed_llm_credentials | default('openstack-lightspeed-apitoken') }}" + tlsCACertBundle: "{{ cifmw_openstack_lightspeed_tls_ca_cert_bundle | default('openstack-lightspeed-certs') if (cifmw_openstack_lightspeed_ca_cert is defined + or cifmw_openstack_lightspeed_ca_cert_url is defined) else omit }}" + + - name: Wait for OpenStackLightspeed CR to be ready + kubernetes.core.k8s_info: + api_version: lightspeed.openstack.org/v1beta1 + kind: OpenStackLightspeed + name: "{{ cifmw_openstack_lightspeed_cr_name | default('openstacklightspeed-sample') }}" + namespace: "{{ openstack_lightspeed_namespace }}" + register: cr_status + until: + - cr_status.resources is defined + - cr_status.resources | length > 0 + - cr_status.resources[0].status is defined + - cr_status.resources[0].status.conditions is defined + - cr_status.resources[0].status.conditions | selectattr('type', 'equalto', 'Ready') | map(attribute='status') | select('equalto', 'True') | list | + length > 0 + retries: "{{ cifmw_openstack_lightspeed_ready_retries | default(120) | int }}" + delay: 10 + + - name: Prepare test-operator access and prerequisites + block: + - name: Authorize the test Pod's explicitly projected client token + kubernetes.core.k8s: + state: present + definition: + apiVersion: rbac.authorization.k8s.io/v1 + kind: ClusterRoleBinding + metadata: + name: "lightspeed-access-{{ cifmw_test_operator_namespace | default('openstack') }}" + roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: lightspeed-access + subjects: + # The current test-operator uses the namespace's default account. + - kind: ServiceAccount + name: default + namespace: "{{ cifmw_test_operator_namespace | default('openstack') }}" + + - name: Create test-operator dummy config ConfigMap + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: ConfigMap + metadata: + name: "test-operator-dummy-config" + namespace: "{{ openstack_lightspeed_namespace }}" + labels: + app: "lightspeed-tests" + persistent: "true" + managed-by: "test-operator" + data: + clouds.yaml: | + # Dummy file - not used by lightspeed tests + # Required by test-operator but lightspeed tests don't need OpenStack + register: _result + retries: 5 + delay: 10 + until: _result is not failed + + - name: Create test-operator dummy secret + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Secret + metadata: + name: "test-operator-dummy-secret" + namespace: "{{ openstack_lightspeed_namespace }}" + labels: + app: "lightspeed-tests" + persistent: "true" + managed-by: "test-operator" + type: Opaque + stringData: + secure.yaml: | + # Dummy file - not used by lightspeed tests + # Required by test-operator but lightspeed tests don't need OpenStack + register: _result + retries: 5 + delay: 10 + until: _result is not failed + + - name: Create dataplane-ansible-ssh-private-key-secret + kubernetes.core.k8s: + state: present + definition: + apiVersion: v1 + kind: Secret + metadata: + name: "dataplane-ansible-ssh-private-key-secret" + namespace: "{{ openstack_lightspeed_namespace }}" + labels: + app: "lightspeed-tests" + persistent: "true" + managed-by: "test-operator" + type: Opaque + stringData: + ssh-privatekey: | + # Dummy SSH key - not used by lightspeed tests + register: _result + retries: 5 + delay: 10 + until: _result is not failed + + - name: Display deployment summary + ansible.builtin.debug: + msg: + - "✓ OpenStack Lightspeed operator deployed in namespace: {{ openstack_lightspeed_namespace }}" + - "✓ OpenStack Lightspeed CR created: {{ cifmw_openstack_lightspeed_cr_name | default('openstacklightspeed-sample') }}" + - "✓ OpenShift Lightspeed operator will be automatically managed by OpenStack Lightspeed" diff --git a/ci/vars-lightspeed.yml b/ci/vars-lightspeed.yml new file mode 100644 index 00000000..a74ec6c4 --- /dev/null +++ b/ci/vars-lightspeed.yml @@ -0,0 +1,4 @@ +--- +pre_tests_01_deploy_lightspeed_operator: + source: "{{ ansible_user_dir }}/{{ zuul.projects['github.com/openstack-k8s-operators/lightspeed-operator'].src_dir }}/ci/playbooks/install-openstack-lightspeed.yml" + type: playbook diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml index 4de0c5f0..e0ebf56f 100644 --- a/zuul.d/jobs.yaml +++ b/zuul.d/jobs.yaml @@ -20,26 +20,107 @@ - name: ci/playbooks/cleanup_lightspeed_secret.yml cleanup: true vars: - pre_tests_01_deploy_lightspeed_operator: - source: install-openstack-lightspeed.yml - type: playbook + cifmw_extras: + - '@scenarios/centos-9/multinode-ci.yml' + - '@scenarios/centos-9/hci_ceph_backends.yml' + - "@{{ ansible_user_dir }}/{{ zuul.projects['github.com/openstack-k8s-operators/lightspeed-operator'].src_dir }}/ci/vars-lightspeed.yml" + + cifmw_run_tests: true + cifmw_test_operator_fail_on_test_failure: true + # Run Lightspeed integration tests through test-operator. + cifmw_test_operator_stages: + - name: lightspeed + type: ansibletest + + cifmw_test_operator_namespace: openstack + cifmw_test_operator_privileged: false + cifmw_test_operator_selinux_level: s0:c478,c978 + cifmw_test_operator_ansibletest_name: ansibletest + cifmw_test_operator_ansibletest_image: quay.io/podified-antelope-centos9/openstack-ansible-tests + cifmw_test_operator_ansibletest_image_tag: current-podified + cifmw_test_operator_ansibletest_ansible_git_repo: https://github.com/openstack-k8s-operators/lightspeed-tests + cifmw_test_operator_ansibletest_ansible_git_branch: "" + cifmw_test_operator_ansibletest_ansible_playbook_path: playbooks/run_lightspeed_tests.yaml + cifmw_test_operator_ansibletest_ansible_inventory: | + localhost ansible_connection=local ansible_python_interpreter=python3 + cifmw_test_operator_ansibletest_debug: false + cifmw_test_operator_ansibletest_resources: + requests: + cpu: 1000m + memory: 1Gi + limits: + cpu: 2000m + memory: 2Gi + # Allow bootstrap to save parameters before runner and PVC facts exist. + # The collector supplies those facts when it creates this Pod. + # Match AnsibleTest UID/GID 227 and its SELinux label to read the PVC. + # The role exposes a full Pod override, not a reader security-context setting. + cifmw_test_operator_log_pod_definition: + apiVersion: v1 + kind: Pod + metadata: + name: >- + test-operator-logs-pod-{{ run_test_fw | default('ansibletest') }}-{{ + test_operator_instance_name | default('ansibletest-lightspeed') }} + namespace: "{{ cifmw_test_operator_namespace }}" + spec: + securityContext: + runAsUser: 227 + runAsGroup: 227 + fsGroup: 227 + seLinuxOptions: + level: "{{ cifmw_test_operator_selinux_level }}" + containers: + - name: test-operator-logs-container + image: "{{ cifmw_test_operator_logs_image | default('quay.io/quay/busybox') }}" + command: ["sleep"] + args: ["infinity"] + # Resolve the collector's nested instance-name template before use. + volumeMounts: >- + {{ (_test_operator_volume_mounts | default([]) | to_json) + | replace('{{ test_operator_instance_name }}', + test_operator_instance_name | default('ansibletest-lightspeed')) + | from_json }} + volumes: "{{ _test_operator_volumes | default([]) }}" + tolerations: "{{ cifmw_test_operator_tolerations | default(omit) }}" + nodeSelector: "{{ cifmw_test_operator_node_selector | default(omit) }}" + cifmw_test_operator_ansibletest_ansible_var_files: | + test_suite_path: /var/lib/ansible/ansible + lightspeed_url: "https://lightspeed-app-server.{{ cifmw_openstack_lightspeed_namespace | default('openstack-lightspeed') }}.svc.cluster.local:8443" + lightspeed_timeout: 120 + lightspeed_model: "provider-default-model/default-model" + pytest_args: "-v --tb=short --color=no -m 'not llm_dependent' tests/integration" + junit_xml_path: /var/lib/AnsibleTests/external_files/baseline.xml + cifmw_test_operator_ansibletest_extra_mounts: + - name: lightspeed + extraVol: + - propagation: [AnsibleTest] + extraVolType: Undefined + volumes: + - name: lightspeed-client-token + projected: + sources: + - serviceAccountToken: + path: token + expirationSeconds: 3600 + mounts: + - name: lightspeed-client-token + mountPath: /var/run/secrets/kubernetes.io/serviceaccount + readOnly: true + + # Fake LLM only; real-provider credentials are a follow-up. + cifmw_openstack_lightspeed_mock_enabled: true # Operator catalog image from content-provider dependency cifmw_openstack_lightspeed_catalog_image: "{{ content_provider_registry_ip }}:5001/openstack-k8s-operators/lightspeed-operator-index:{{ zuul.patchset }}" - # LLM configuration - cifmw_openstack_lightspeed_llm_endpoint: "https://api.example.com/v1/chat/completions" + # Mock provider deployed by the operator-owned hook + cifmw_openstack_lightspeed_llm_endpoint: "http://mock-llm-api-server-pod.openstack-lightspeed.svc.cluster.local:8000/v1" + cifmw_openstack_lightspeed_llm_endpoint_type: "openai" cifmw_openstack_lightspeed_model_name: "example-model" + # Replace the pre-run provider token with a dummy value for the mock. + cifmw_openstack_lightspeed_api_token: "dummy-token-for-ci" - # api_token intentionally unset: the hook verifies the pre-created Secret - # instead. The openai_credentials var is out of scope here (see playbook). - - # TLS CA cert omitted for CI - not needed for dummy endpoint testing - # Operator fails to parse invalid PEM data; omitting allows reconciliation to proceed - # to expected failure point (LLM credential validation) - # Uncomment and provide valid PEM cert when testing with real LLM endpoint - - # cifmw_openstack_lightspeed_ca_cert: "dummy-cert-for-ci" cifmw_os_must_gather_additional_namespaces: "openstack-lightspeed" cifmw_os_must_gather_omc: false