Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BuildConfig and Builds to Clusters View #882

Merged
merged 3 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 47 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import path = require('path');
import fsx = require('fs-extra');
import * as k8s from 'vscode-kubernetes-tools-api';
import { ClusterExplorerV1 } from 'vscode-kubernetes-tools-api';
import { DeploymentConfigNodeContributor } from './k8s/deployment';

export let contextGlobalState: vscode.ExtensionContext;

Expand Down Expand Up @@ -93,7 +94,9 @@ export async function activate(context: vscode.ExtensionContext) {
clusterExplorer.api.nodeSources.resourceFolder("Templates", "Templates", "Template", "template").if(isOpenShift).at(undefined),
clusterExplorer.api.nodeSources.resourceFolder("ImageStreams", "ImageStreams", "ImageStream", "ImageStream").if(isOpenShift).at("Workloads"),
clusterExplorer.api.nodeSources.resourceFolder("Routes", "Routes", "Route", "route").if(isOpenShift).at("Network"),
clusterExplorer.api.nodeSources.resourceFolder("DeploymentConfigs", "DeploymentConfigs", "DeploymentConfig", "dc").if(isOpenShift).at("Workloads")
clusterExplorer.api.nodeSources.resourceFolder("DeploymentConfigs", "DeploymentConfigs", "DeploymentConfig", "dc").if(isOpenShift).at("Workloads"),
clusterExplorer.api.nodeSources.resourceFolder("BuildConfigs", "BuildConfigs", "BuildConfig", "bc").if(isOpenShift).at("Workloads"),
new DeploymentConfigNodeContributor()
];
nodeContributors.forEach(element => {
clusterExplorer.api.registerNodeContributor(element);
Expand Down Expand Up @@ -129,7 +132,7 @@ async function customizeAsync(node: ClusterExplorerV1.ClusterExplorerResourceNod
treeItem.iconPath = vscode.Uri.file(path.join(__dirname, "../../images/context/cluster-node.png"));
}
}
if (node.nodeType as unknown === 'resource' && node.resourceKind.manifestKind === 'Project') {
if (node.nodeType === 'resource' && node.resourceKind.manifestKind === 'Project') {
// assuming now that it’s a project node
const projectName = node.name;
if (projectName === lastNamespace) {
Expand All @@ -138,6 +141,9 @@ async function customizeAsync(node: ClusterExplorerV1.ClusterExplorerResourceNod
treeItem.contextValue = `${treeItem.contextValue || ''}.openshift.inactiveProject`;
}
}
if (node.nodeType === 'resource' && node.resourceKind.manifestKind === 'BuildConfig') {
treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
}
}

async function isOpenShift(): Promise<boolean> {
Expand Down
50 changes: 50 additions & 0 deletions src/k8s/deployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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;
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;
}
}