From 90d5f12be39c54e25665c323388d0b91c95d019c Mon Sep 17 00:00:00 2001 From: Itay Matza Date: Tue, 8 Apr 2025 12:15:48 +0300 Subject: [PATCH 1/2] Add hcp testing Change-Id: If7b04c6e6bf35fd6d7077ec4906ef9aa42b7de0f --- jobs_definitions/hcp_testing.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 jobs_definitions/hcp_testing.yaml diff --git a/jobs_definitions/hcp_testing.yaml b/jobs_definitions/hcp_testing.yaml new file mode 100644 index 0000000..0302211 --- /dev/null +++ b/jobs_definitions/hcp_testing.yaml @@ -0,0 +1,9 @@ +--- +user_cloud: "shiftstack-hosted_cluster" +ocp_cluster_name: "shiftstack-hcp" +ocp_base_domain: "hypershift.lab" +kubeconfig: "~/{{ ocp_cluster_name }}-kubeconfig" + +stages: + - verification + - cinder_csi_tests From de9af61fe8e4bb14fecdb370116b5e42a3d046af Mon Sep 17 00:00:00 2001 From: Itay Matza Date: Wed, 23 Apr 2025 12:23:53 +0300 Subject: [PATCH 2/2] Retrieve OpenShift API and Ingress IPs Add logic to dynamically retrieve OpenShift API and Ingress IP addresses. The values are extracted using oc commands with fallback mechanisms to handle DNS, router-default service, or install-config configmap parsing. - Adds retrieve_api_ip.yml and retrieve_ingress_ip.yml - Adds retrieve_openshift_ips.yml to combine both - Integrates via include_role from openstack_test - Supports KUBECONFIG via a role variable - Sets facts: api_accessible_ip, apps_accessible_ip Change-Id: Id34d3bcbcbcc4777e651b24050f3cd582ed7b441 --- .../roles/openstack_test/tasks/main.yml | 8 +-- .../tasks/retrieve_api_ip.yml | 24 +++++++++ .../tasks/retrieve_ingress_ip.yml | 53 +++++++++++++++++++ .../tasks/retrieve_openshift_ips.yml | 14 +++++ 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 collection/tools/roles/tools_get_deploy_info/tasks/retrieve_api_ip.yml create mode 100644 collection/tools/roles/tools_get_deploy_info/tasks/retrieve_ingress_ip.yml create mode 100644 collection/tools/roles/tools_get_deploy_info/tasks/retrieve_openshift_ips.yml diff --git a/collection/stages/roles/openstack_test/tasks/main.yml b/collection/stages/roles/openstack_test/tasks/main.yml index 0eaa57c..bf9e11a 100644 --- a/collection/stages/roles/openstack_test/tasks/main.yml +++ b/collection/stages/roles/openstack_test/tasks/main.yml @@ -12,10 +12,10 @@ - name: Run openstack-test block: - - name: Include vars from registered resources - ansible.builtin.include_vars: - file: "{{ resources_file }}" - name: resources + - name: Retrieve OpenShift API and Ingress IPs + ansible.builtin.include_role: + name: shiftstack.tools.tools_get_deploy_info + tasks_from: retrieve_openshift_ips.yml # DNS resolution management needed for RHOSO pods to be able to resolve # shift-on-stack cluster Apps endpoints (for telemetry tests the RHOSO diff --git a/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_api_ip.yml b/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_api_ip.yml new file mode 100644 index 0000000..a5b552d --- /dev/null +++ b/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_api_ip.yml @@ -0,0 +1,24 @@ +--- +# Retrieve OpenShift API IP + +- name: Get OpenShift API hostname (strip port) + ansible.builtin.shell: >- + set -o pipefail && + oc get infrastructure cluster -o jsonpath='{.status.apiServerURL}' | + sed -E 's|https?://||' | cut -d: -f1 + register: api_host + changed_when: false + environment: + KUBECONFIG: "{{ kubeconfig }}" + +- name: Resolve API IP + ansible.builtin.shell: >- + set -o pipefail && + getent ahosts {{ api_host.stdout }} | awk '{print $1}' | head -n1 + register: api_ip + changed_when: false + failed_when: api_ip.stdout == "" + +- name: Set API IP fact + ansible.builtin.set_fact: + api_accessible_ip: "{{ api_ip.stdout }}" diff --git a/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_ingress_ip.yml b/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_ingress_ip.yml new file mode 100644 index 0000000..9adfc09 --- /dev/null +++ b/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_ingress_ip.yml @@ -0,0 +1,53 @@ +--- +# Retrieve OpenShift Ingress IP + +- name: Get Ingress domain from default ingresscontroller + ansible.builtin.shell: >- + oc get -n openshift-ingress-operator ingresscontroller default -o jsonpath='{.status.domain}' + register: ingress_domain + changed_when: false + environment: + KUBECONFIG: "{{ kubeconfig }}" + +- name: Try to resolve Ingress IP from DNS + ansible.builtin.shell: >- + set -o pipefail && + getent ahosts {{ ingress_domain.stdout }} | awk '{print $1}' | head -n1 + register: ingress_ip_dns + changed_when: false + failed_when: false + +- name: Fallback - Get Ingress IP from router-default service + ansible.builtin.shell: >- + oc get -n openshift-ingress svc router-default -o jsonpath='{.status.loadBalancer.ingress[0].ip}' + register: ingress_ip_lb + when: ingress_ip_dns.stdout == "" + changed_when: false + failed_when: false + environment: + KUBECONFIG: "{{ kubeconfig }}" + +- name: Fallback - Get Ingress IP from install-config in ConfigMap + ansible.builtin.shell: | + set -o pipefail && + oc get cm cluster-config-v1 -n kube-system -o jsonpath="{.data['install-config']}" | \ + awk ' + /ingressVIPs:/ {getline; print $2; exit} + /ingressVIP:/ {print $2; exit} + /ingressFloatingIP:/ {print $2; exit} + ' | tr -d '"' + register: ingress_ip_cm + when: + - ingress_ip_dns.stdout == "" + - ingress_ip_lb.stdout == "" + changed_when: false + failed_when: ingress_ip_cm.stdout == "" + environment: + KUBECONFIG: "{{ kubeconfig }}" + +- name: Set Ingress IP fact + ansible.builtin.set_fact: + apps_accessible_ip: >- + {{ ingress_ip_dns.stdout if ingress_ip_dns.stdout else + ingress_ip_lb.stdout if ingress_ip_lb.stdout else + ingress_ip_cm.stdout }} diff --git a/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_openshift_ips.yml b/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_openshift_ips.yml new file mode 100644 index 0000000..99c57d0 --- /dev/null +++ b/collection/tools/roles/tools_get_deploy_info/tasks/retrieve_openshift_ips.yml @@ -0,0 +1,14 @@ +--- +# Main task: retrieve both API and Ingress IPs + +- name: Retrieve OpenShift API IP + ansible.builtin.include_tasks: retrieve_api_ip.yml + +- name: Retrieve OpenShift Ingress IP + ansible.builtin.include_tasks: retrieve_ingress_ip.yml + +- name: Show retrieved IPs + ansible.builtin.debug: + msg: + - "API IP: {{ api_accessible_ip }}" + - "Ingress IP: {{ apps_accessible_ip }}"