Skip to content
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
24 changes: 23 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"K8s",
"Cloud",
"podman",
"Helm"
"Helm",
"kubernetes-extension-cloud-provider"
],
"icon": "images/openshift_extension.png",
"main": "./out/src/extension",
Expand Down Expand Up @@ -214,6 +215,7 @@
"onView:openshiftProjectExplorer",
"onView:extension.vsKubernetesExplorer",
"onView:openshiftComponentTypesView",
"onView:kubernetes.cloudExplorer",
"onCommand:openshift.welcome",
"onCommand:openshift.getStarted",
"onCommand:openshift.about",
Expand Down Expand Up @@ -795,6 +797,16 @@
"command": "openshift.component.deleteSourceFolder",
"title": "Delete Source Code Folder",
"category": "OpenShift"
},
{
"command": "openshift.sandbox.open.dashboard",
"title": "Open Developer Console",
"category": "OpenShift"
},
{
"command": "openshift.sandbox.signup",
"title": "Provision OpenShift Developer Sandbox",
"category": "OpenShift"
}
],
"keybindings": [
Expand Down Expand Up @@ -1146,6 +1158,16 @@
}
],
"view/item/context": [
{
"command": "openshift.sandbox.signup",
"category": "1@1",
"when": "viewItem == openshift.sandbox.status.none"
},
{
"command": "openshift.sandbox.open.dashboard",
"category": "1@1",
"when": "viewItem == openshift.sandbox.status.ready"
},
{
"command": "clusters.openshift.csv.create",
"group": "1@1",
Expand Down
167 changes: 167 additions & 0 deletions src/cloudProvider/redhatCloudProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import * as k8s from 'vscode-kubernetes-tools-api';
import * as vscode from 'vscode';
import { vsCommand } from '../vscommand';
import { createSandboxAPI, SBSignupResponse } from '../openshift/sandbox';
import ClusterViewLoader from '../webview/cluster/clusterViewLoader';
import path = require('path');

const sandboxAPI = createSandboxAPI();

class RedHatCloudItem extends vscode.TreeItem {

}

class RedHatTreeDataProvier implements vscode.TreeDataProvider<RedHatCloudItem> {
private eventEmitter: vscode.EventEmitter<RedHatCloudItem> = new vscode.EventEmitter<RedHatCloudItem>()
readonly onDidChangeTreeData: vscode.Event<RedHatCloudItem> = this.eventEmitter.event

getTreeItem(element: RedHatCloudItem): vscode.TreeItem | Thenable<vscode.TreeItem> {
return element
}

getChildren(element?: RedHatCloudItem): vscode.ProviderResult<RedHatCloudItem[]> {
if (!element) {
return this.getTopLevelItems();
}
return [];
}

getParent?(element: RedHatCloudItem): unknown {
throw new Error('Method not implemented.');
}

resolveTreeItem?(item: vscode.TreeItem, element: unknown, token: vscode.CancellationToken): vscode.ProviderResult<vscode.TreeItem> {
throw new Error('Method not implemented.');
}

private async getTopLevelItems(): Promise<RedHatCloudItem[]> {
const sessionCheck = await vscode.authentication.getSession('redhat-account-auth', ['openid'], { createIfNone: false });
if (sessionCheck) {
const sandboxItem = await this.buildDevSandboxItem();
const openshiftLocalItem = this.buildOpenshiftLocalItem();
return [sandboxItem, openshiftLocalItem];
}
const loginItem = new RedHatCloudItem('Sign in to Red Hat');
loginItem.iconPath = new vscode.ThemeIcon('account');
loginItem.tooltip = 'Sign in to Red Hat';
loginItem.command = {
command: 'cloud.redhat.login',
title: 'Sign in to Red Hat',
}

const signUpItem = new RedHatCloudItem('Create Red Hat Account');
signUpItem.tooltip = 'Create Red Hat Account';
signUpItem.iconPath = new vscode.ThemeIcon('add');
signUpItem.command = {
command: '_openshift.open.signup',
title: 'Create Red Hat Account',
tooltip: 'Create Red Hat Account'
}
return [loginItem, signUpItem];
}

private async buildDevSandboxItem() {
const signupStatus = await RedHatTreeDataProvier.getSandboxSignupStatus();
const sandboxItem = new RedHatCloudItem('Developer Sandbox');
sandboxItem.tooltip = 'Get 30-days free access to a shared OpenShift and Kubernetes cluster.';
sandboxItem.iconPath = vscode.Uri.file(path.join(__dirname, '..', '..', '..', 'images', 'title', 'logo.svg'));
if (!signupStatus) {
sandboxItem.contextValue = 'openshift.sandbox.status.none';
}
else if (signupStatus.status.ready) {
sandboxItem.contextValue = 'openshift.sandbox.status.ready';
}
sandboxItem.command = {
command: 'openshift.sandbox.open.setup',
title: 'Set up Developer Sandbox',
}
return sandboxItem;
}

private buildOpenshiftLocalItem() {
const openshiftLocalItem = new RedHatCloudItem('Openshift Local');
openshiftLocalItem.tooltip = 'Provision OpenShift 4 cluster to your local computer.';
openshiftLocalItem.iconPath = new vscode.ThemeIcon('vm');
openshiftLocalItem.command = {
command: 'openshift.local.open.setup',
title: 'Install OpenShift Local',
}
return openshiftLocalItem;
}

@vsCommand('openshift.sandbox.signup')
static async signupForSandbox(): Promise<string> {
const authSession = await vscode.authentication.getSession('redhat-account-auth', ['openid'], { createIfNone: false });
if (authSession) {
// eslint-disable-next-line dot-notation
const signupResponse = await sandboxAPI.signUp(authSession['idToken'] as string);
if (!signupResponse) {
return 'Sign up request for OpenShift Sandbox failed, please try again.';
}
await RedHatTreeDataProvier.refreshView();

}
}

@vsCommand('openshift.local.open.setup')
static async openCrCWizard(): Promise<void> {
const webViewPanel: vscode.WebviewPanel = await ClusterViewLoader.loadView('Add OpenShift Cluster');
await webViewPanel.webview.postMessage({ action: 'openCluster', param: 'crc' });
}

@vsCommand('openshift.sandbox.open.setup')
static async openSandboxWizard(): Promise<void> {
const webViewPanel: vscode.WebviewPanel = await ClusterViewLoader.loadView('Add OpenShift Cluster');
await webViewPanel.webview.postMessage({ action: 'openCluster', param: 'sandbox' });
}

@vsCommand('cloud.redhat.login', false)
static async loginToRedHatCloud(): Promise<void> {
const session = await vscode.authentication.getSession('redhat-account-auth', ['openid'], { createIfNone: true });
if (session) {
await RedHatTreeDataProvier.refreshView();
}
}

@vsCommand('_openshift.open.signup', false)
static async signupForRedHatAccount(): Promise<void> {
return vscode.commands.executeCommand('vscode.open', 'https://red.ht/3MkQ54W');
}

@vsCommand('openshift.sandbox.open.dashboard', false)
static async openDashboard(): Promise<void> {
const sandboxStatus = await RedHatTreeDataProvier.getSandboxSignupStatus();
if (sandboxStatus) {
return vscode.commands.executeCommand('vscode.open', sandboxStatus.consoleURL);
}
}

private static async getSandboxSignupStatus(): Promise<SBSignupResponse | undefined> {
const authSession = await vscode.authentication.getSession('redhat-account-auth', ['openid'], { createIfNone: false });
if (authSession) {
// eslint-disable-next-line dot-notation
return await sandboxAPI.getSignUpStatus(authSession['idToken'] as string);
}
return undefined;
}
private static async refreshView() {
const cloudExplorer = await k8s.extension.cloudExplorer.v1;
if (cloudExplorer.available) {
cloudExplorer.api.refresh();
}
}
}

class RedHatCloudProvider implements k8s.CloudExplorerV1.CloudProvider {
getKubeconfigYaml(cluster: any): Promise<string> {
throw new Error('Method not implemented.');
}
readonly cloudName = 'Red Hat OpenShift';
readonly treeDataProvider = new RedHatTreeDataProvier();
}

export const REDHAT_CLOUD_PROVIDER = new RedHatCloudProvider();
22 changes: 16 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
window,
workspace
} from 'vscode';
import * as k8s from 'vscode-kubernetes-tools-api';
import { REDHAT_CLOUD_PROVIDER } from './cloudProvider/redhatCloudProvider';
import { ComponentsTreeDataProvider } from './componentsView';
import { DebugSessionsView } from './debug';
import { OpenShiftExplorer } from './explorer';
Expand Down Expand Up @@ -56,7 +58,14 @@ async function verifyBundledBinaries(): Promise<{ odoPath: string, ocPath: strin
};
}

export async function activate(extensionContext: ExtensionContext): Promise<any> {
async function registerKubernetesCloudProvider(): Promise<void> {
const cloudProvider = await k8s.extension.cloudExplorer.v1;
if (cloudProvider.available) {
cloudProvider.api.registerCloudProvider(REDHAT_CLOUD_PROVIDER);
}
}

export async function activate(extensionContext: ExtensionContext): Promise<unknown> {
WelcomePage.createOrShow();
await commands.executeCommand('setContext', 'isVSCode', env.uiKind);
// UIKind.Desktop ==1 & UIKind.Web ==2. These conditions are checked for browser based & electron based IDE.
Expand Down Expand Up @@ -102,7 +111,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
kind: QuickPickItemKind.Separator
},
{
label:'Add OpenShift Cluster'
label: 'Add OpenShift Cluster'
},
{
label: 'Login to Cluster'
Expand Down Expand Up @@ -133,7 +142,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
{
label: 'Getting Started Walkthrough'
}
]);
]);
switch (selection?.label) {
case 'Add OpenShift Cluster':
await commands.executeCommand('openshift.explorer.addCluster');
Expand Down Expand Up @@ -166,8 +175,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
});
}

function createStatusBarItem(context: ExtensionContext)
{
function createStatusBarItem(context: ExtensionContext) {
const item = window.createStatusBarItem(StatusBarAlignment.Left, 1);
item.command = 'openshift.openStatusBar';
context.subscriptions.push(item);
Expand All @@ -176,7 +184,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>
item.show();
}

createStatusBarItem(extensionContext) ;
createStatusBarItem(extensionContext);

function updateStatusBarItem(statusBarItem: StatusBarItem, text: string): void {
if (!workspace.getConfiguration('openshiftToolkit').get('crcBinaryLocation')) {
Expand All @@ -192,6 +200,8 @@ export async function activate(extensionContext: ExtensionContext): Promise<any>

await ComponentTypesView.instance.getAllComponents();

await registerKubernetesCloudProvider();

startTelemetry(extensionContext);
await verifyBinariesInRemoteContainer();

Expand Down
2 changes: 1 addition & 1 deletion src/webview/@types/windows/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ interface Window {
cmdText?: string;
vscodeApi: VscodeAPI;
acquireVsCodeApi: () => VscodeAPI;
}
}
1 change: 0 additions & 1 deletion src/webview/cluster/clusterViewLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,4 @@ export default class ClusterViewLoader {
}
}
}

}