Skip to content

Commit f2b7e3c

Browse files
committed
Updating deployment.yaml doesn't reflect into openshift #4472
Fixes: #4472 Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
1 parent a78e502 commit f2b7e3c

10 files changed

Lines changed: 910 additions & 132 deletions

package-lock.json

Lines changed: 61 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"shelljs": "^0.10.0"
7878
},
7979
"devDependencies": {
80+
"@apidevtools/json-schema-ref-parser": "^12.0.2",
8081
"@codemirror/lang-yaml": "^6.1.2",
8182
"@devfile/api": "^2.2.2-1716821574",
8283
"@kubernetes/client-node": "^0.22.3",
@@ -190,7 +191,8 @@
190191
"xterm-addon-serialize": "^0.11.0",
191192
"xterm-addon-web-links": "^0.9.0",
192193
"xterm-addon-webgl": "^0.16.0",
193-
"xterm-headless": "^5.3.0"
194+
"xterm-headless": "^5.3.0",
195+
"yaml": "^2.8.0"
194196
},
195197
"overrides": {
196198
"cookie": "^1.0.2",

src/cli.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,30 @@ export class CliChannel {
9090
return result;
9191
}
9292

93+
async executeToolWithText(command: CommandText, opts?: cp.ExecOptions, fail = true, stdout?: string): Promise<CliExitData> {
94+
const commandActual = command.toString();
95+
const commandPrivacy = command.privacyMode(true).toString();
96+
const [cmd] = commandActual.split(' ');
97+
const toolLocation = await ToolsConfig.detect(cmd);
98+
const optsCopy = CliChannel.applyEnv(opts, CliChannel.createTelemetryEnv())
99+
100+
const result: CliExitData = await ChildProcessUtil.Instance.execute(
101+
toolLocation ? commandActual.replace(cmd, `"${toolLocation}"`) : commandActual, optsCopy, stdout);
102+
103+
if (result.error && fail) {
104+
if (result.error.code && result.error.code.toString() === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER') {
105+
void vscode.window.showErrorMessage('Do you want to change the maximum \'stdout\' buffer size by modifying the \'openshiftToolkit.execMaxBufferLength\' preference value?', 'Yes', 'Cancel')
106+
.then((answer)=> {
107+
if (answer === 'Yes') {
108+
void vscode.commands.executeCommand('workbench.action.openSettings', 'openshiftToolkit.execMaxBufferLength');
109+
}
110+
});
111+
}
112+
throw new VsCommandError(`${result.error.message}`, `Error when running command: ${commandPrivacy}`, result.error);
113+
};
114+
return result;
115+
}
116+
93117
async spawnTool(cmd: CommandText, opts: cp.SpawnOptions = {cwd: undefined, env: process.env}): Promise<cp.ChildProcess> {
94118
const toolLocation = await ToolsConfig.detect(cmd.command);
95119
const optWithTelemetryEnv = CliChannel.applyEnv(opts, CliChannel.createTelemetryEnv());

src/explorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { CommandOption, CommandText } from './base/command';
2828
import { ExecutionContext } from './cli';
2929
import * as Helm from './helm/helm';
3030
import { HelmRepo } from './helm/helmChartType';
31-
import { getOutputFormat, helmfsUri, kubefsUri } from './k8s/vfs/kuberesources.virtualfs';
31+
import { getOutputFormat, helmfsUri, kubefsUri } from './k8s/vfs/kuberesources.utils';
3232
import { Oc } from './oc/ocWrapper';
3333
import { Component } from './openshift/component';
3434
import { getServiceKindStubs, getServices } from './openshift/serviceHelpers';

src/extension.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import { Context as KcuContext } from '@kubernetes/client-node/dist/config_types';
77
import {
88
authentication,
9-
commands, env, ExtensionContext, languages, QuickPickItemKind,
9+
commands, Diagnostic, env, ExtensionContext, languages, QuickPickItemKind,
1010
StatusBarAlignment,
11-
StatusBarItem, window,
11+
StatusBarItem, TextDocument, window,
1212
workspace
1313
} from 'vscode';
1414
import { extension as k8sExtension } from 'vscode-kubernetes-tools-api';
@@ -26,7 +26,8 @@ import { Console as K8sConsole } from './k8s/console';
2626
import { DeploymentConfig as K8sDeploymentConfig } from './k8s/deploymentConfig';
2727
import { Route as K8sRoute } from './k8s/route';
2828
import { KubernetesResourceLinkProvider } from './k8s/vfs/kuberesources.linkprovider';
29-
import { K8S_RESOURCE_SCHEME, K8S_RESOURCE_SCHEME_READONLY, KubernetesResourceVirtualFileSystemProvider } from './k8s/vfs/kuberesources.virtualfs';
29+
import { K8S_RESOURCE_SCHEME, K8S_RESOURCE_SCHEME_READONLY, K8sResourceCache } from './k8s/vfs/kuberesources.utils';
30+
import { KubernetesResourceVirtualFileSystemProvider } from './k8s/vfs/kuberesources.virtualfs';
3031
import { Oc } from './oc/ocWrapper';
3132
import { OdoPreference } from './odo/odoPreference';
3233
import { Cluster } from './openshift/cluster';
@@ -53,7 +54,6 @@ import { WelcomePage } from './welcomePage';
5354
import { registerYamlHandlers } from './yaml/yamlDocumentFeatures';
5455
import { YamlFileCommands } from './yamlFileCommands';
5556

56-
// eslint-disable-next-line @typescript-eslint/no-empty-function
5757
// this method is called when your extension is deactivated
5858
export function deactivate(): void {
5959
// intentionally left blank
@@ -87,6 +87,30 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
8787
// Link from resources to referenced resources
8888
const resourceLinkProvider = new KubernetesResourceLinkProvider();
8989

90+
// Diagnostics for K8s resources
91+
async function updateDiagnostics(document: TextDocument): Promise<void> {
92+
if ( document.languageId !== 'yaml' && document.languageId !== 'json') return;
93+
94+
const diagnostics: Diagnostic[] = await K8sResourceCache.Instance.validateResourceDocument(document.uri, document.getText());;
95+
96+
diagnosticCollection.set(document.uri, diagnostics);
97+
}
98+
99+
const diagnosticCollection = languages.createDiagnosticCollection(extensionContext.extension.id);
100+
window.onDidChangeActiveTextEditor(editor => {
101+
if (editor) {
102+
void updateDiagnostics(editor.document);
103+
}
104+
});
105+
106+
workspace.onDidChangeTextDocument(event => {
107+
void updateDiagnostics(event.document);
108+
});
109+
110+
if (window.activeTextEditor) {
111+
void updateDiagnostics(window.activeTextEditor.document);
112+
}
113+
90114
const crcStatusItem = window.createStatusBarItem(StatusBarAlignment.Left);
91115
crcStatusItem.command = 'openshift.explorer.stopCluster';
92116

@@ -138,6 +162,9 @@ export async function activate(extensionContext: ExtensionContext): Promise<unkn
138162

139163
// Link from resources to referenced resources
140164
languages.registerDocumentLinkProvider({ scheme: K8S_RESOURCE_SCHEME }, resourceLinkProvider),
165+
166+
// Diagnostic collection for K8s Resources
167+
diagnosticCollection
141168
];
142169

143170
disposable.push(...registerCommands());

src/k8s/vfs/kuberesources.linkprovider.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
55

6+
import * as _ from 'lodash';
7+
import * as querystring from 'querystring';
68
import * as vscode from 'vscode';
79
import { DocumentLinkProvider, Uri } from 'vscode';
8-
9-
import * as querystring from 'querystring';
10-
import * as _ from 'lodash';
11-
import { MappingItem, Node, NodeProvider } from './locator-util';
10+
import * as jl from './json-locator';
1211
import * as kuberesources from './kuberesources';
12+
import { K8S_RESOURCE_SCHEME, K8S_RESOURCE_SCHEME_READONLY, getOutputFormat, helmfsUri, kubefsUri } from './kuberesources.utils';
13+
import { MappingItem, Node, NodeProvider } from './locator-util';
1314
import * as yl from './yaml-locator';
14-
import * as jl from './json-locator';
15-
import { K8S_RESOURCE_SCHEME, K8S_RESOURCE_SCHEME_READONLY, getOutputFormat, helmfsUri, kubefsUri } from './kuberesources.virtualfs';
1615

1716
// >>> URI Cache >>>
1817

@@ -38,10 +37,7 @@ function cacheEditingUris() {
3837
export class KubernetesResourceLinkProvider implements DocumentLinkProvider {
3938
provideDocumentLinks(document: vscode.TextDocument, _token: vscode.CancellationToken): vscode.ProviderResult<vscode.DocumentLink[]> {
4039
const sourceKind = k8sKind(document);
41-
const df = getDocumentFormat(document);
42-
const docs = (df === 'yaml' || df === 'yml') ?
43-
yl.yamlLocator.getYamlDocuments(document)
44-
: df === 'json' ? jl.jsonLocator.getJsonDocuments(document) : [];
40+
const docs = getParsedDocuments(document);
4541
const leaves = getLeafNodes(docs);
4642

4743
try {
@@ -54,13 +50,21 @@ export class KubernetesResourceLinkProvider implements DocumentLinkProvider {
5450
}
5551
}
5652

53+
export function getParsedDocuments(document: vscode.TextDocument): NodeProvider[] {
54+
const df = getDocumentFormat(document);
55+
const docs = (df === 'yaml' || df === 'yml') ?
56+
yl.yamlLocator.getYamlDocuments(document)
57+
: df === 'json' ? jl.jsonLocator.getJsonDocuments(document) : [];
58+
return docs;
59+
}
60+
5761
function getDocumentFormat(document: vscode.TextDocument): string | undefined {
5862
const path = document.uri.path;
5963
const sepIndex = path.indexOf('.');
6064
return sepIndex >= 0 ? path.substring(sepIndex + 1).toLocaleLowerCase() : undefined;
6165
}
6266

63-
function getLeafNodes(docs: NodeProvider[]): Node[] {
67+
export function getLeafNodes(docs: NodeProvider[]): Node[] {
6468
const rootNodes = _.flatMap(docs, (d) => d.nodes);
6569
const nonRootNodes = _.flatMap(rootNodes, (n) => descendants(n));
6670
const allNodes = rootNodes.concat(nonRootNodes);
@@ -80,13 +84,20 @@ function getLink(document: vscode.TextDocument, sourceKind: string, node: Node):
8084
return undefined;
8185
}
8286

83-
function range(document: vscode.TextDocument, node: MappingItem) {
87+
export function range(document: vscode.TextDocument, node: MappingItem): vscode.Range {
8488
return new vscode.Range(
8589
document.positionAt(node.value.startPosition),
8690
document.positionAt(node.value.endPosition)
8791
);
8892
}
8993

94+
export function keyRange(document: vscode.TextDocument, node: MappingItem): vscode.Range {
95+
return new vscode.Range(
96+
document.positionAt(node.key.startPosition),
97+
document.positionAt(node.key.endPosition)
98+
);
99+
}
100+
90101
function descendants(node: Node): Node[] {
91102
const direct = children(node);
92103
const indirect = direct.map((n) => descendants(n));

0 commit comments

Comments
 (0)