Skip to content

Commit ed71b71

Browse files
Merge pull request #215 from shwetaap/COO-1684
COO-1684: Fix for Event query string not being updated
2 parents 08f403c + de492f4 commit ed71b71

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

web/src/__tests__/k8s.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ describe('K8sDomain.queryToLink', () => {
179179
url: `k8s/ns/x/rbac.authorization.k8s.io~v1~Role/y`,
180180
},
181181
{ query: `k8s:Pod:{}`, url: 'k8s/all-namespaces/core~v1~Pod' },
182+
// Event queries without fields (directly querying events by namespace)
183+
{
184+
query: 'k8s:Event.v1.events.k8s.io:{"namespace":"openshift-logging"}',
185+
url: 'k8s/ns/openshift-logging/events.k8s.io~v1~Event',
186+
},
187+
{
188+
query: 'k8s:Event.v1:{"namespace":"openshift-cluster-observability-operator"}',
189+
url: 'k8s/ns/openshift-cluster-observability-operator/core~v1~Event',
190+
},
182191
])('converts $query to $url', ({ url, query }) => {
183192
expect(k8s.queryToLink(Query.parse(query)).toString()).toEqual(new URIRef(url).toString());
184193
});

web/src/korrel8r/k8s.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,22 @@ export class K8sDomain extends Domain {
9595
let namespace = selector.namespace;
9696
let name = selector.name;
9797
let events = '';
98-
if (isEvent(model)) {
98+
if (isEvent(model) && selector.fields) {
9999
// Special case for events, generate URL of involved object with '/events' modifier.
100+
// Only apply this if fields are present (indicating an event about a specific object).
100101
const eventClass = this.modelClass(model);
101102
const about = eventAboutField(model);
102-
const [group, version] = parseAPIVersion(selector.fields[`${about}.apiVersion`]);
103+
const apiVersion = selector.fields[`${about}.apiVersion`];
103104
const kind = selector.fields[`${about}.kind`];
104-
model = findGVK(group, version, kind);
105-
if (!model) throw this.badQuery(query, `no resource matching ${eventClass}.${about}`);
106-
namespace = selector.fields[`${about}.namespace`] || '';
107-
name = selector.fields[`${about}.name`] || '';
108-
events = '/events';
105+
// Only treat as an involved object event if the required fields are present
106+
if (apiVersion && kind) {
107+
const [group, version] = parseAPIVersion(apiVersion);
108+
model = findGVK(group, version, kind);
109+
if (!model) throw this.badQuery(query, `no resource matching ${eventClass}.${about}`);
110+
namespace = selector.fields[`${about}.namespace`] || '';
111+
name = selector.fields[`${about}.name`] || '';
112+
events = '/events';
113+
}
109114
}
110115
// Prepare parts of the URL
111116
const nsPath = namespace ? `ns/${namespace}` : 'all-namespaces';

0 commit comments

Comments
 (0)