From d08e4e0bcd09f8abf6c2e2303e6039254ee38780 Mon Sep 17 00:00:00 2001 From: Vikram Raj Date: Wed, 21 Feb 2024 21:33:02 +0530 Subject: [PATCH] Switch to service from external result route endpoint --- src/components/utils/summary-api.ts | 2 +- src/components/utils/tekton-results.ts | 39 +++++++++++++++----------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/components/utils/summary-api.ts b/src/components/utils/summary-api.ts index 4c84f314..0eda7f17 100644 --- a/src/components/utils/summary-api.ts +++ b/src/components/utils/summary-api.ts @@ -1,5 +1,5 @@ -import { consoleProxyFetchJSON } from './proxy'; import { SummaryProps } from '../pipelines-overview/utils'; +import { consoleProxyFetchJSON } from './proxy'; import { TektonResultsOptions, createTektonResultsSummaryUrl, diff --git a/src/components/utils/tekton-results.ts b/src/components/utils/tekton-results.ts index 86ceaea9..90470dde 100644 --- a/src/components/utils/tekton-results.ts +++ b/src/components/utils/tekton-results.ts @@ -5,7 +5,7 @@ import { Selector, k8sGet, } from '@openshift-console/dynamic-plugin-sdk'; -import { RouteModel, TektonResultModel } from '../../models'; +import { TektonResultModel } from '../../models'; import { PipelineRunKind, TaskRunKind } from '../../types'; import { K8sResourceKind } from '../../types/openshift'; import { consoleProxyFetchJSON } from './proxy'; @@ -212,13 +212,17 @@ export const createTektonResultsUrl = async ( name: 'result', }); const targetNamespace = tektonResult?.spec?.targetNamespace; - const route: K8sResourceKind = await k8sGet({ - model: RouteModel, - name: 'tekton-results-api-service', - ns: targetNamespace, - }); - const tektonResultUrl = route?.spec.host; - const URL = `https://${tektonResultUrl}/apis/results.tekton.dev/v1alpha2/parents/${namespace}/results/-/records?${new URLSearchParams( + const serverPort = tektonResult?.spec?.server_port ?? '8080'; + const tlsHostname = tektonResult?.spec?.tls_hostname_override; + let tektonResultsAPI; + if (tlsHostname) { + tektonResultsAPI = `${tlsHostname}:${serverPort}`; + } else if (targetNamespace && serverPort) { + tektonResultsAPI = `tekton-results-api-service.${targetNamespace}.svc.cluster.local:${serverPort}`; + } else { + tektonResultsAPI = `tekton-results-api-service.openshift-pipelines.svc.cluster.local:${serverPort}`; + } + const URL = `https://${tektonResultsAPI}/apis/results.tekton.dev/v1alpha2/parents/${namespace}/results/-/records?${new URLSearchParams( { // default sort should always be by `create_time desc` // order_by: 'create_time desc', not supported yet @@ -371,16 +375,17 @@ export const createTektonResultsSummaryUrl = async ( name: 'result', }); const targetNamespace = tektonResult?.spec?.targetNamespace; - const route: K8sResourceKind = await k8sGet({ - model: RouteModel, - name: 'tekton-results-api-service', - ns: targetNamespace, - }); - const tektonResultUrl = route?.spec.host; - if (!tektonResultUrl) { - throw new Error('route.spec.host is undefined'); + const serverPort = tektonResult?.spec?.server_port ?? '8080'; + const tlsHostname = tektonResult?.spec?.tls_hostname_override; + let tektonResultsAPI; + if (tlsHostname) { + tektonResultsAPI = `${tlsHostname}:${serverPort}`; + } else if (targetNamespace && serverPort) { + tektonResultsAPI = `tekton-results-api-service.${targetNamespace}.svc.cluster.local:${serverPort}`; + } else { + tektonResultsAPI = `tekton-results-api-service.openshift-pipelines.svc.cluster.local:${serverPort}`; } - const URL = `https://${tektonResultUrl}/apis/results.tekton.dev/v1alpha2/parents/${namespace}/results/-/records/summary?${new URLSearchParams( + const URL = `https://${tektonResultsAPI}/apis/results.tekton.dev/v1alpha2/parents/${namespace}/results/-/records/summary?${new URLSearchParams( { summary: `${options?.summary}`, ...(options?.groupBy ? { group_by: `${options.groupBy}` } : {}),