Skip to content

add view for showing the associated gateways #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,20 @@
},
"component": { "$codeRef": "GatewaySingleOverview" }
}
},
{
"type": "console.tab/horizontalNav",
"properties": {
"model": {
"group": "gateway.networking.k8s.io",
"version": "v1",
"kind": "HTTPRoute"
},
"page": {
"name": "Attached",
"href": "attached"
},
"component": { "$codeRef": "HTTPRouteSingleOverview" }
}
}
]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"loadType": "Preload"
},
"exposedModules": {
"GatewaySingleOverview": "./components/GatewaySingleOverview"
"GatewaySingleOverview": "./components/GatewaySingleOverview",
"HTTPRouteSingleOverview": "./components/HTTPRouteSingleOverview"
},
"dependencies": {
"@console/pluginAPI": "*"
Expand Down
142 changes: 61 additions & 81 deletions src/components/AttachedResources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
HTTPRoute: {
groupVersionKind: { group: 'gateway.networking.k8s.io', version: 'v1', kind: 'HTTPRoute' },
isList: true,
// Search cluster-wide for HTTPRoutes that might reference this gateway
},
Gateway: {
groupVersionKind: { group: 'gateway.networking.k8s.io', version: 'v1', kind: 'Gateway' },
isList: true,
},
};

Expand All @@ -35,87 +38,64 @@

const resourceGroup = resource.apiVersion.includes('/') ? resource.apiVersion.split('/')[0] : '';

const attachedRoutes = React.useMemo(() => {
let routesArray: K8sResourceKind[] = [];

// Process HTTPRoutes
const httpRoutes = watchedResources.HTTPRoute;
console.log('HTTPROUTES', httpRoutes);

if (httpRoutes?.loaded && !httpRoutes.loadError && httpRoutes.data) {
console.log('ALL HTTP ROUTES:', httpRoutes.data);
const matchingRoutes = (httpRoutes.data as K8sResourceKind[]).filter((route) => {
console.log('CHECKING ROUTE:', route.metadata.name);
console.log('ROUTE STATUS:', route.status);

const statusParents = route.status?.parents ?? [];
console.log('STATUS PARENTS FOR ROUTE', route.metadata.name, ':', statusParents);

// Also check spec.parentRefs as fallback for debugging
const specParents = route.spec?.parentRefs ?? [];
console.log('SPEC PARENTS FOR ROUTE', route.metadata.name, ':', specParents);

console.log('LOOKING FOR GATEWAY:', {
name: resource.metadata.name,
namespace: resource.metadata.namespace,
kind: resource.kind,
group: resourceGroup,
const attachedResources = React.useMemo(() => {
let results: K8sResourceKind[] = [];

const checkParentRef = (parentRef: any, targetResource: K8sResourceKind) => {

Check warning on line 44 in src/components/AttachedResources.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (!parentRef) return false;

const refNamespace = parentRef.namespace ?? targetResource.metadata.namespace;
const refGroup = parentRef.group ?? 'gateway.networking.k8s.io';
const refKind = parentRef.kind ?? 'Gateway';

return (
parentRef.name === targetResource.metadata.name &&
refNamespace === targetResource.metadata.namespace &&
refGroup === resourceGroup &&
refKind === targetResource.kind
);
};

if (resource.kind === 'Gateway') {
const httpRoutes = watchedResources.HTTPRoute;
if (httpRoutes?.loaded && !httpRoutes.loadError && httpRoutes.data) {
const matchingRoutes = httpRoutes.data.filter((route) => {
const statusParents = route.status?.parents ?? [];
const specParents = route.spec?.parentRefs ?? [];

const statusMatch = statusParents.some((parent: any) =>

Check warning on line 66 in src/components/AttachedResources.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
checkParentRef(parent.parentRef, resource),
);
const specMatch = specParents.some((parentRef: any) =>

Check warning on line 69 in src/components/AttachedResources.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
checkParentRef(parentRef, resource),
);

return statusMatch || specMatch;
});
results = results.concat(matchingRoutes);
}
}

// Check both status.parents and spec.parentRefs for matches
const checkParentRef = (parentRef: any) => {
if (!parentRef) return false;

const refNamespace = parentRef.namespace ?? resource.metadata.namespace;
const refGroup = parentRef.group ?? 'gateway.networking.k8s.io';
const refKind = parentRef.kind ?? 'Gateway';

const matches =
parentRef.name === resource.metadata.name &&
refNamespace === resource.metadata.namespace &&
refGroup === resourceGroup &&
refKind === resource.kind;

console.log('MATCH CHECK:', {
parentRef,
expected: {
name: resource.metadata.name,
namespace: resource.metadata.namespace,
group: resourceGroup,
kind: resource.kind,
},
actual: {
name: parentRef.name,
namespace: refNamespace,
group: refGroup,
kind: refKind,
},
matches,
if (resource.kind === 'HTTPRoute') {
const gateways = watchedResources.Gateway;
if (gateways?.loaded && !gateways.loadError && gateways.data) {
const matchingGateways = gateways.data.filter((gateway) => {
const specParents = resource.spec?.parentRefs ?? [];

return specParents.some((parentRef: any) => {

Check warning on line 85 in src/components/AttachedResources.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
return (
parentRef.name === gateway.metadata.name &&
(parentRef.namespace ?? resource.metadata.namespace) === gateway.metadata.namespace &&
(parentRef.group ?? 'gateway.networking.k8s.io') === resourceGroup &&
(parentRef.kind ?? 'Gateway') === gateway.kind
);
});

return matches;
};

// First check status.parents
const statusMatch = statusParents.some((parent: any) => {
console.log('CHECKING STATUS PARENT REF:', parent.parentRef);
return checkParentRef(parent.parentRef);
});

// Also check spec.parentRefs as fallback
const specMatch = specParents.some((parentRef: any) => {
console.log('CHECKING SPEC PARENT REF:', parentRef);
return checkParentRef(parentRef);
});

return statusMatch || specMatch;
});
console.log('MATCHING ROUTES:', matchingRoutes);

routesArray = routesArray.concat(matchingRoutes);
results = results.concat(matchingGateways);
}
}

return routesArray;
return results;
}, [watchedResources, resource, resourceGroup]);

const columns: TableColumn<K8sResourceKind>[] = [
Expand Down Expand Up @@ -200,21 +180,21 @@
</Alert>
</AlertGroup>
)}
{attachedRoutes.length === 0 && allLoaded ? (
{attachedResources.length === 0 && allLoaded ? (
<EmptyState
titleText={
<Title headingLevel="h4" size="lg">
{t('No attached routes found')}
{t('No attached resources found')}
</Title>
}
icon={SearchIcon}
>
<EmptyStateBody>{t('No route resources matched')}</EmptyStateBody>
<EmptyStateBody>{t('No matching resources found')}</EmptyStateBody>
</EmptyState>
) : (
<VirtualizedTable<K8sResourceKind>
data={attachedRoutes}
unfilteredData={attachedRoutes}
data={attachedResources}
unfilteredData={attachedResources}
loaded={allLoaded}
loadError={combinedLoadError}
columns={columns}
Expand Down
1 change: 0 additions & 1 deletion src/components/GatewaySingleOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ const GatewayPoliciesPage: React.FC = () => {
);
};


export default GatewayPoliciesPage;
55 changes: 55 additions & 0 deletions src/components/HTTPRouteSingleOverview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { PageSection, Title } from '@patternfly/react-core';
import {
useK8sWatchResources,
K8sResourceCommon,
useActiveNamespace,
} from '@openshift-console/dynamic-plugin-sdk';

import extractResourceNameFromURL from '../utils/nameFromPath';
import { Helmet } from 'react-helmet';
import AttachedResources from './AttachedResources';

const HTTPRouteSingleOverview: React.FC = () => {
const { t } = useTranslation('plugin__gateway-api-console-plugin');
const [activeNamespace] = useActiveNamespace();
const location = useLocation();

const httpRouteName = extractResourceNameFromURL(location.pathname);
const resources = {
httpRoute: {
groupVersionKind: {
group: 'gateway.networking.k8s.io',
version: 'v1',
kind: 'HTTPRoute',
},
namespace: activeNamespace,
name: httpRouteName,
isList: false,
},
};

const watchedResources = useK8sWatchResources<{ httpRoute: K8sResourceCommon }>(resources);
const { loaded, loadError, data: httpRoute } = watchedResources.httpRoute;

return (
<>
<Helmet>
<title data-test="example-page-title">{t('Associated Gateways')}</title>
</Helmet>
<PageSection hasBodyWrapper={false}>
<Title headingLevel="h2">{t('Associated Gateways')}</Title>
{!loaded ? (
<div>Loading...</div>
) : loadError ? (
<div>Error loading HTTPRoute: {loadError.message}</div>
) : (
<AttachedResources resource={httpRoute} />
)}
</PageSection>
</>
);
};
export default HTTPRouteSingleOverview;
Loading