Skip to content

Commit

Permalink
Merge pull request openshift-pipelines#71 from vikram-raj/fix-pipelin…
Browse files Browse the repository at this point in the history
…e-details-url

SRVKP-4155: build v1beta1 pipeline details url for 4.13 and below OCP cluster
  • Loading branch information
openshift-merge-bot[bot] authored Feb 15, 2024
2 parents 90a33ab + af5445e commit d1c1a0b
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 8 deletions.
3 changes: 3 additions & 0 deletions console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"component": {
"$codeRef": "pipelinesComponent.PipelinesOverviewPage"
}
},
"flags": {
"required": ["PIPELINE_TEKTON_RESULT_INSTALLED"]
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions locales/en/plugin__pipelines-console-plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"Average duration": "Average duration",
"Average Duration": "Average Duration",
"Cancelled": "Cancelled",
"ClusterVersion": "ClusterVersion",
"ClusterVersions": "ClusterVersions",
"Duration": "Duration",
"Failed": "Failed",
"Last day": "Last day",
Expand Down
34 changes: 34 additions & 0 deletions src/components/hooks/use-k8sGet-hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
K8sModel,
K8sResourceCommon,
k8sGet,
} from '@openshift-console/dynamic-plugin-sdk';
import * as React from 'react';

export const useK8sGet = <R extends K8sResourceCommon = K8sResourceCommon>(
kind: K8sModel,
name?: string,
namespace?: string,
): [R, boolean, unknown] => {
const [data, setData] = React.useState<R>();
const [loaded, setLoaded] = React.useState(false);
const [loadError, setLoadError] = React.useState();
React.useEffect(() => {
const fetch = async () => {
try {
setLoadError(null);
setLoaded(false);
setData(null);
const resource = await k8sGet<R>({ model: kind, name, ns: namespace });
setData(resource);
} catch (error) {
setLoadError(error);
} finally {
setLoaded(true);
}
};
fetch();
}, [kind, name, namespace]);

return [data, loaded, loadError];
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ import {
listPageTableColumnClasses as tableColumnClasses,
} from '../utils';
import PipelineRunsForPipelinesRow from './PipelineRunsForPipelinesRow';
import { ClusterVersionModel } from '../../../models';
import { ClusterVersionKind } from '../../../types';
import { useK8sGet } from '../../hooks/use-k8sGet-hook';

type PipelineRunsForPipelinesListProps = {
summaryData: SummaryProps[];
summaryDataFiltered?: SummaryProps[];
loaded: boolean;
};

export const getClusterVersion = (cv: ClusterVersionKind): string => {
return cv?.status?.history?.[0]?.version || cv?.spec?.desiredUpdate?.version;
};

const PipelineRunsForPipelinesList: React.FC<
PipelineRunsForPipelinesListProps
> = ({ summaryData, summaryDataFiltered, loaded }) => {
const { t } = useTranslation('plugin__pipelines-console-plugin');
const [clusterVersionData, clusterVersionLoaded] =
useK8sGet<ClusterVersionKind>(ClusterVersionModel, 'version');
const clusterVersion =
clusterVersionLoaded && getClusterVersion(clusterVersionData);
const EmptyMsg = () => (
<EmptyState variant={EmptyStateVariant.large}>
{t('No PipelineRuns found')}
Expand Down Expand Up @@ -109,6 +120,7 @@ const PipelineRunsForPipelinesList: React.FC<
loadError={false}
unfilteredData={summaryData}
EmptyMsg={EmptyMsg}
rowData={{ clusterVersion }}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,29 @@ import {
} from '@openshift-console/dynamic-plugin-sdk';
import { formatTime, formatTimeLastRunTime } from '../dateTime';
import { ALL_NAMESPACES_KEY } from '../../../consts';
import { PipelineModel } from '../../../models';
import { PipelineModel, PipelineModelV1Beta1 } from '../../../models';
import { useActiveNamespace } from '../../hooks/useActiveNamespace';

const pipelineReference = getReferenceForModel(PipelineModel);

const PipelineRunsForPipelinesRow: React.FC<RowProps<SummaryProps>> = ({
obj,
}) => {
const PipelineRunsForPipelinesRow: React.FC<
RowProps<SummaryProps, { clusterVersion: string }>
> = ({ obj, rowData }) => {
const [activeNamespace] = useActiveNamespace();
const [namespace, name] = obj.group_value.split('/');

const { clusterVersion } = rowData;
const isV1SupportCluster =
clusterVersion.split('.')[0] === '4' && clusterVersion.split('.')[1] > '13';
const pipelineReference = getReferenceForModel(
isV1SupportCluster ? PipelineModel : PipelineModelV1Beta1,
);
return (
<>
<td className={tableColumnClasses[0]}>
<ResourceLink
groupVersionKind={getGroupVersionKindForModel(PipelineModel)}
groupVersionKind={
isV1SupportCluster
? getGroupVersionKindForModel(PipelineModel)
: getGroupVersionKindForModel(PipelineModelV1Beta1)
}
name={name}
namespace={namespace}
/>
Expand Down
35 changes: 35 additions & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ export const PipelineModel = {
color,
};

export const PipelineModelV1Beta1 = {
apiGroup: 'tekton.dev',
apiVersion: 'v1beta1',
label: 'Pipeline',
// t('Pipeline')
labelKey: 'Pipeline',
// t('Pipelines')
labelPluralKey: 'Pipelines',
plural: 'pipelines',
abbr: 'PL',
namespaced: true,
kind: 'Pipeline',
id: 'pipeline',
labelPlural: 'Pipelines',
crd: true,
color,
};

export const RepositoryModel = {
apiGroup: 'pipelinesascode.tekton.dev',
apiVersion: 'v1alpha1',
Expand Down Expand Up @@ -71,3 +89,20 @@ export const RouteModel: K8sKind = {
kind: 'Route',
id: 'route',
};

export const ClusterVersionModel: K8sKind = {
label: 'ClusterVersion',
// t('ClusterVersion')
labelKey: 'ClusterVersion',
labelPlural: 'ClusterVersions',
// t('ClusterVersions')
labelPluralKey: 'ClusterVersions',
apiVersion: 'v1',
apiGroup: 'config.openshift.io',
plural: 'clusterversions',
abbr: 'CV',
namespaced: false,
kind: 'ClusterVersion',
id: 'clusterversion',
crd: true,
};
32 changes: 32 additions & 0 deletions src/types/openshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,35 @@ export type K8sResourceKind = K8sResourceCommon & {
status?: { [key: string]: any };
data?: { [key: string]: any };
};

export type UpdateHistory = {
state: 'Completed' | 'Partial';
startedTime: string;
completionTime: string;
version: string;
image: string;
verified: boolean;
};

export type Release = {
version: string;
image: string;
url?: string;
channels?: string[];
};
type ClusterVersionStatus = {
desired: Release;
history: UpdateHistory[];
};

type ClusterVersionSpec = {
channel: string;
clusterID: string;
desiredUpdate?: Release;
upstream?: string;
};

export type ClusterVersionKind = {
spec: ClusterVersionSpec;
status: ClusterVersionStatus;
} & K8sResourceCommon;

0 comments on commit d1c1a0b

Please sign in to comment.