Skip to content

Commit 0682709

Browse files
vrubezhnydatho7561
authored andcommitted
Migrate Kubernetes Resource Link Provider #4118
Plus enjencements: - Respect to Output Format preference - Support JSON file format - Links deduplication (preventing to open multiple files for the same links) when hyperlinking Fixes: #4118 Signed-off-by: Victor Rubezhny <[email protected]>
1 parent 8f74bd4 commit 0682709

10 files changed

+880
-37
lines changed

package-lock.json

+59
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@
8181
"hasha": "^5.2.2",
8282
"js-yaml": "^4.1.0",
8383
"json-schema": "^0.4.0",
84+
"json-to-ast": "^2.1.0",
8485
"lodash": "^4.17.21",
8586
"make-fetch-happen": "^13.0.1",
8687
"mkdirp": "^3.0.1",
88+
"node-yaml-parser": "^0.0.9",
8789
"portfinder": "^1.0.32",
8890
"rxjs": "^7.8.1",
8991
"semver": "^7.6.2",
@@ -137,6 +139,7 @@
137139
"bootstrap": "^5.3.3",
138140
"chai": "^4.4.1",
139141
"chokidar": "^3.6.0",
142+
"clipboardy": "^2.3.0",
140143
"codecov": "^3.8.2",
141144
"dpdm": "^3.14.0",
142145
"esbuild": "^0.19.12",
@@ -180,8 +183,7 @@
180183
"vscode-extension-tester": "^8.1",
181184
"xterm-addon-fit": "^0.8.0",
182185
"xterm-addon-web-links": "^0.9.0",
183-
"xterm-addon-webgl": "^0.16.0",
184-
"clipboardy": "^2.3.0"
186+
"xterm-addon-webgl": "^0.16.0"
185187
},
186188
"activationEvents": [
187189
"onView:openshiftProjectExplorer",

src/explorer.ts

+5-28
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,9 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
708708
*/
709709
loadKubernetesCore(namespace: string | null, value: string) {
710710
const outputFormat = getOutputFormat();
711-
const uri = kubefsUri(namespace, value, outputFormat);
711+
// Names are to be only lowercase,
712+
// see: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names
713+
const uri = kubefsUri(namespace, value.toLocaleLowerCase(), outputFormat, undefined, true);
712714
this.loadKubernetesDocument(uri);
713715
}
714716

@@ -718,7 +720,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
718720
* @param revision Installed Helm Chart revision
719721
*/
720722
loadKubernetesHelmChart(releaseName: string, revision: number | undefined) {
721-
const uri = helmfsUri(releaseName, revision);
723+
const uri = helmfsUri(releaseName, revision, true);
722724
this.loadKubernetesDocument(uri);
723725
}
724726

@@ -727,19 +729,7 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
727729
* @param uri A Kubernetes document Uri
728730
*/
729731
loadKubernetesDocument(uri: Uri) {
730-
const query = this.getComparableQuery(uri);
731-
const openUri = workspace.textDocuments.map((doc) => doc.uri)
732-
.find((docUri) => {
733-
return (docUri.scheme === uri.scheme &&
734-
docUri.authority === uri.authority &&
735-
docUri.fragment === uri.fragment &&
736-
docUri.path === uri.path &&
737-
this.getComparableQuery(docUri) === query);
738-
});
739-
740-
// If open document is found for the URI provided, we use its URI to bring its editor to the front
741-
// instead of openning a new editor
742-
workspace.openTextDocument(openUri ? openUri : uri).then(
732+
workspace.openTextDocument(uri).then(
743733
(doc) => {
744734
if (doc) {
745735
void window.showTextDocument(doc);
@@ -748,19 +738,6 @@ export class OpenShiftExplorer implements TreeDataProvider<ExplorerItem>, Dispos
748738
(err) => window.showErrorMessage(`Error loading document: ${err}`));
749739
}
750740

751-
/*
752-
* Returns the query string of the specified Uri without "nonce" param,
753-
* so the query strings can be compared.
754-
* The "nonce" param is generated as current time value for every KubefsUri created,
755-
* f.i., "_=1709642987392", and are always added to the end of the query string (so
756-
* they always have the preceeding query parameters sepacator character ("&") added),
757-
* so the query strings, if they aren't cleared from "nonce" param, can be compared for
758-
* Uri objects even when they point to the same document.
759-
*/
760-
getComparableQuery(uri: Uri): string {
761-
return uri.query.replace(/&_=[0-9]+/g, '');
762-
}
763-
764741
@vsCommand('openshift.resource.delete')
765742
public static async deleteResource(component: KubernetesObject) {
766743
await Progress.execFunctionWithProgress(`Deleting '${component.kind}/${component.metadata.name}'`, async (_) => {

src/extension.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import * as path from 'path';
77
import {
88
authentication,
9-
commands, env, ExtensionContext, QuickPickItemKind,
9+
commands, env, ExtensionContext, languages, QuickPickItemKind,
1010
StatusBarAlignment,
1111
StatusBarItem, window,
1212
workspace
@@ -37,6 +37,7 @@ import { registerYamlHandlers } from './yaml/yamlDocumentFeatures';
3737
import fsx = require('fs-extra');
3838
import { Oc } from './oc/ocWrapper';
3939
import { K8S_RESOURCE_SCHEME, K8S_RESOURCE_SCHEME_READONLY, KubernetesResourceVirtualFileSystemProvider } from './k8s/vfs/kuberesources.virtualfs';
40+
import { KubernetesResourceLinkProvider } from './k8s/vfs/kuberesources.linkprovider';
4041

4142
// eslint-disable-next-line @typescript-eslint/no-empty-function
4243
// this method is called when your extension is deactivated
@@ -81,7 +82,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
8182
const resourceDocProvider = new KubernetesResourceVirtualFileSystemProvider();
8283

8384
// Link from resources to referenced resources
84-
// const resourceLinkProvider = new KubernetesResourceLinkProvider();
85+
const resourceLinkProvider = new KubernetesResourceLinkProvider();
8586

8687
// pick kube config in case multiple are configured
8788
await setKubeConfig();
@@ -129,7 +130,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
129130
workspace.registerFileSystemProvider(K8S_RESOURCE_SCHEME_READONLY, resourceDocProvider, { isReadonly: true }),
130131

131132
// Link from resources to referenced resources
132-
// languages.registerDocumentLinkProvider({ scheme: K8S_RESOURCE_SCHEME }, resourceLinkProvider),
133+
languages.registerDocumentLinkProvider({ scheme: K8S_RESOURCE_SCHEME }, resourceLinkProvider),
133134

134135
];
135136
disposable.forEach((value) => extensionContext.subscriptions.push(value));

0 commit comments

Comments
 (0)