Skip to content

Commit fcfad14

Browse files
Merge pull request #91 from PeterYurkovich/fix-k8s-url-parsing
NO-JIRA: Fix an issue calling private methods in a static function
2 parents f89761a + a9b4c9c commit fcfad14

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

web/src/korrel8r/k8s.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class K8sNode extends Korrel8rNode {
4545
static fromURL(url: string): Korrel8rNode {
4646
const [path, params] = parseURL('k8s', 'k8s|search', url);
4747
const [, namespace, resource, name, events] = path.match(pathRegex) || [];
48-
const groupVersionKind = this.getGroupVersionKind(resource, params.get('kind'));
48+
const groupVersionKind = K8sNode.getGroupVersionKind(resource, params.get('kind'));
4949

5050
if (!groupVersionKind || !groupVersionKind.kind)
5151
throw new NodeError(`Expected k8s URL: ${url}`);
@@ -54,7 +54,7 @@ export class K8sNode extends Korrel8rNode {
5454
fields: {
5555
'involvedObject.namespace': namespace,
5656
'involvedObject.name': name,
57-
'involvedObject.apiVersion': this.apiVersionFor(groupVersionKind),
57+
'involvedObject.apiVersion': K8sNode.apiVersionFor(groupVersionKind),
5858
'involvedObject.kind': groupVersionKind.kind,
5959
},
6060
};
@@ -89,7 +89,7 @@ export class K8sNode extends Korrel8rNode {
8989
if (gvk.kind == eventGroupVersionKind.kind && !gvk.group) {
9090
events = '/events';
9191
// Focus on the events involved object rather than the event.
92-
gvk = this.makeGroupVersionKind(
92+
gvk = K8sNode.makeGroupVersionKind(
9393
data.fields['involvedObject.apiVersion'],
9494
data.fields['involvedObject.kind'],
9595
);
@@ -101,7 +101,7 @@ export class K8sNode extends Korrel8rNode {
101101
}
102102

103103
// Prepare parts of the URL
104-
const [gvk2, resource] = this.findKind(gvk); // Fill out partial GVK
104+
const [gvk2, resource] = K8sNode.findKind(gvk); // Fill out partial GVK
105105
gvk = gvk2;
106106
const nsPath = namespace ? `ns/${namespace}` : 'all-namespaces';
107107
const labelsParam = data.labels
@@ -132,11 +132,11 @@ export class K8sNode extends Korrel8rNode {
132132
}
133133

134134
// Return a GVK for the resource (path) or throw an error
135-
private static getGroupVersionKind(resource: string, kind: string): GroupVersionKind {
135+
static getGroupVersionKind(resource: string, kind: string): GroupVersionKind {
136136
if (resource && !resource.includes('~')) {
137137
// Try the resource as a straight resource name
138138
if (resource === 'projects') resource = 'namespaces';
139-
return this.findResource(resource);
139+
return K8sNode.findResource(resource);
140140
}
141141
const gvkStr = resource || kind; // Either kind or resource may be a g~v~k string.
142142
if (gvkStr) {
@@ -147,13 +147,13 @@ export class K8sNode extends Korrel8rNode {
147147
version: parts[1] || undefined,
148148
kind: parts[2],
149149
};
150-
return this.findKind(gvk)[0]; // Fill it out
150+
return K8sNode.findKind(gvk)[0]; // Fill it out
151151
}
152152
throw new NodeError(`Invalid k8s resource: ${gvkStr}`);
153153
}
154154

155155
// parseSelector parses a selector string as a query map.
156-
private static parseSelector(selector: string): { [key: string]: string } {
156+
static parseSelector(selector: string): { [key: string]: string } {
157157
if (!selector) return undefined;
158158
const labels: { [key: string]: string } = {};
159159
selector.split(',').forEach((pair: string) => {
@@ -164,7 +164,7 @@ export class K8sNode extends Korrel8rNode {
164164
}
165165

166166
// findResource returns the GroupVersionKind for a resource name (path component)
167-
private static findResource(resource: string): GroupVersionKind {
167+
static findResource(resource: string): GroupVersionKind {
168168
const model = getCachedResources()?.models.find(
169169
(m: Model) => m.path === resource && m.verbs.includes('watch'),
170170
);
@@ -173,7 +173,7 @@ export class K8sNode extends Korrel8rNode {
173173
}
174174

175175
// Returns the model matching a gvk or throws an error.
176-
private static findKind(gvk: GroupVersionKind): [fullGVK: GroupVersionKind, resource: string] {
176+
static findKind(gvk: GroupVersionKind): [fullGVK: GroupVersionKind, resource: string] {
177177
const model = getCachedResources()?.models.find(
178178
(m: Model) =>
179179
m.kind === gvk.kind &&
@@ -188,19 +188,19 @@ export class K8sNode extends Korrel8rNode {
188188
}
189189

190190
// makeGroupVersionKind from a kind and an apiVersion.
191-
private static makeGroupVersionKind(apiVersion: string, kind: string): GroupVersionKind {
191+
static makeGroupVersionKind(apiVersion: string, kind: string): GroupVersionKind {
192192
const parts = apiVersion.split('/');
193193
if (parts.length == 1) return { version: parts[0] || undefined, kind: kind };
194194
if (parts.length == 2)
195195
return { group: parts[0] || undefined, version: parts[1] || undefined, kind: kind };
196196
throw new NodeError('Invalid k8s apiVersion: ${apiVersion}');
197197
}
198198

199-
private static apiVersionFor(gvk: GroupVersionKind): string {
199+
static apiVersionFor(gvk: GroupVersionKind): string {
200200
return `${gvk.group ? `${gvk.group}/` : ''}${gvk.version || 'v1'}`;
201201
}
202202

203-
private static classFor(gvk: GroupVersionKind): string {
203+
static classFor(gvk: GroupVersionKind): string {
204204
return `k8s:${gvk.kind}.${gvk.version || 'v1'}.${gvk.group || ''}`;
205205
}
206206
}

0 commit comments

Comments
 (0)