Skip to content

Commit d5e51a4

Browse files
NETOBSERV-2146: Fix missing traffic flows for Gateway owner resource (filter issue) (#1165)
* gateway api support
1 parent fcb155d commit d5e51a4

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

web/locales/en/plugin__netobserv-plugin.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@
371371
"Select a custom time range. Flows are selected based on their End Time value.": "Select a custom time range. Flows are selected based on their End Time value.",
372372
"Collection latency could be up to {{maxChunkAge}} corresponding to the current Loki \"max_chunk_age\" ingester configuration.": "Collection latency could be up to {{maxChunkAge}} corresponding to the current Loki \"max_chunk_age\" ingester configuration.",
373373
"Unable to get config": "Unable to get config",
374+
"This Deployment is managed by a Gateway": "This Deployment is managed by a Gateway",
375+
"To view the Gateway traffic, visit the Gateway resource page.": "To view the Gateway traffic, visit the Gateway resource page.",
374376
"Kind not managed": "Kind not managed",
375377
"Query is slow": "Query is slow",
376378
"Time range": "Time range",

web/src/components/netflow-traffic-tab.tsx

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
import { FeatureFlagHandler, K8sResourceCommon, SetFeatureFlag } from '@openshift-console/dynamic-plugin-sdk';
21
import {
2+
FeatureFlagHandler,
3+
K8sResourceCommon,
4+
ResourceLink,
5+
SetFeatureFlag
6+
} from '@openshift-console/dynamic-plugin-sdk';
7+
import {
8+
Alert,
9+
AlertActionLink,
310
Bullseye,
411
EmptyState,
512
EmptyStateBody,
@@ -60,6 +67,7 @@ export const NetflowTrafficTab: React.FC<NetflowTrafficTabProps> = ({ match, obj
6067
const [config, setConfig] = React.useState<Config>(defaultConfig);
6168
const [error, setError] = React.useState<string | undefined>();
6269
const [forcedFilters, setForcedFilters] = React.useState<Filters>();
70+
const [gatewayInfo, setGatewayInfo] = React.useState<{ name: string; namespace: string } | undefined>();
6371
const previous = usePrevious({ obj });
6472

6573
React.useEffect(() => {
@@ -103,13 +111,28 @@ export const NetflowTrafficTab: React.FC<NetflowTrafficTabProps> = ({ match, obj
103111
}
104112

105113
initState.current.push('forcedFiltersLoaded');
114+
115+
// Reset gateway info by default
116+
setGatewayInfo(undefined);
117+
106118
switch (obj?.kind) {
107119
case 'Pod':
108120
case 'Deployment':
109121
case 'StatefulSet':
110122
case 'DaemonSet':
111123
case 'Job':
112-
case 'CronJob':
124+
case 'CronJob': {
125+
// Check for Gateway label on Deployments
126+
if (obj.kind === 'Deployment') {
127+
const gatewayLabel = obj.metadata?.labels?.['gateway.networking.k8s.io/gateway-name'];
128+
if (gatewayLabel) {
129+
setGatewayInfo({
130+
name: gatewayLabel,
131+
namespace: obj.metadata!.namespace!
132+
});
133+
}
134+
}
135+
113136
setForcedFilters({
114137
list: [
115138
{
@@ -121,6 +144,7 @@ export const NetflowTrafficTab: React.FC<NetflowTrafficTabProps> = ({ match, obj
121144
match: 'bidirectional'
122145
});
123146
break;
147+
}
124148
case 'Service':
125149
// NOTE: Services are always on the destination side
126150
setForcedFilters({
@@ -227,6 +251,30 @@ export const NetflowTrafficTab: React.FC<NetflowTrafficTabProps> = ({ match, obj
227251
} else if (forcedFilters) {
228252
return (
229253
<div className="netobserv-tab-container" style={{ height: containerHeight - 190 }}>
254+
{gatewayInfo && (
255+
<Alert
256+
variant="info"
257+
isInline
258+
title={t('This Deployment is managed by a Gateway')}
259+
style={{ margin: '0 1rem 1rem 1rem' }}
260+
actionLinks={
261+
<AlertActionLink>
262+
<ResourceLink
263+
inline={true}
264+
groupVersionKind={{
265+
group: 'gateway.networking.k8s.io',
266+
version: 'v1',
267+
kind: 'Gateway'
268+
}}
269+
name={gatewayInfo.name}
270+
namespace={gatewayInfo.namespace}
271+
/>
272+
</AlertActionLink>
273+
}
274+
>
275+
{t('To view the Gateway traffic, visit the Gateway resource page.')}
276+
</Alert>
277+
)}
230278
<NetflowTrafficParent
231279
forcedNamespace={params?.ns || match?.params?.ns}
232280
forcedFilters={forcedFilters}

web/src/utils/autocomplete-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class AutoCompleteCache {
66
// Kinds are hard-coded for now.
77
// The some other controller kinds might not be in the list (e.g. DeploymentConfig),
88
// but it should still be possible to type manually
9-
private kinds = ['Pod', 'Service', 'Node', 'Deployment', 'StatefulSet', 'DaemonSet', 'Job', 'CronJob'];
9+
private kinds = ['Pod', 'Service', 'Node', 'Gateway', 'Deployment', 'StatefulSet', 'DaemonSet', 'Job', 'CronJob'];
1010
private names: Map<string, string[]> = new Map();
1111

1212
getClusters() {

web/webpack.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,23 @@ module.exports = {
392392
}
393393
}
394394
},
395+
{
396+
type: "console.tab/horizontalNav",
397+
properties: {
398+
model: {
399+
version: "v1beta1",
400+
group: "gateway.networking.k8s.io",
401+
kind: "Gateway"
402+
},
403+
component: {
404+
"$codeRef": "netflowTab.default"
405+
},
406+
"page": {
407+
name: "%plugin__netobserv-plugin~Network Traffic%",
408+
"href": "netflow"
409+
}
410+
}
411+
},
395412
{
396413
type: "console.tab/horizontalNav",
397414
properties: {

0 commit comments

Comments
 (0)