forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment.ts
More file actions
51 lines (46 loc) · 2.22 KB
/
deployment.ts
File metadata and controls
51 lines (46 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as vscode from 'vscode';
import { ClusterExplorerV1 } from 'vscode-kubernetes-tools-api';
import * as k8s from 'vscode-kubernetes-tools-api';
export class DeploymentConfigNodeContributor implements ClusterExplorerV1.NodeContributor {
contributesChildren(parent: ClusterExplorerV1.ClusterExplorerNode | undefined): boolean {
return !!parent && parent.nodeType === 'resource' && parent.resourceKind.manifestKind === 'BuildConfig';
}
async getChildren(parent: ClusterExplorerV1.ClusterExplorerNode | undefined): Promise<ClusterExplorerV1.Node[]> {
const kubectl = await k8s.extension.kubectl.v1;
if (kubectl.available) {
const result = await kubectl.api.invokeCommand(`get build -o jsonpath="{range .items[?(.metadata.labels.buildconfig=='${(parent as any).name}')]}{.metadata.namespace}{','}{.metadata.name}{','}{.metadata.annotations.openshift\\.io/build\\.number}{\\"\\n\\"}{end}"`);
const builds = result.stdout.split('\n')
.filter((value) => value !== '')
.map<Build>((item: string) => new Build(item.split(',')[0], item.split(',')[1], Number.parseInt(item.split(',')[2])));
return builds;
}
return [];
}
}
class Build implements ClusterExplorerV1.Node, ClusterExplorerV1.ClusterExplorerResourceNode {
nodeType: "resource";
readonly resourceKind: ClusterExplorerV1.ResourceKind = {
manifestKind: 'Build',
abbreviation: 'build'
};
readonly kind: ClusterExplorerV1.ResourceKind = this.resourceKind;
public id: string;
public resourceId: string;
// tslint:disable-next-line:variable-name
constructor(readonly namespace: string, readonly name: string, readonly number: number, readonly metadata?: any) {
this.id = this.resourceId = `build/${this.name}`;
}
async getChildren(): Promise<ClusterExplorerV1.Node[]> {
return [];
}
getTreeItem(): vscode.TreeItem {
const item = new vscode.TreeItem(`#${this.number} ${this.name}`);
item.contextValue = 'openShift.resource.build';
item.command = {
arguments: [this],
command: 'extension.vsKubernetesLoad',
title: "Load"
};
return item;
}
}