From 3c11247e9430372a822265dc353f0604f47a7618 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Wed, 27 Mar 2024 18:18:20 -0700 Subject: [PATCH 1/3] fix: add sandbox.open.login.url command disposable to subscriptions Signed-off-by: Denis Golovin --- src/extension.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index b2d9963..e4eff2d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -242,15 +242,17 @@ export async function activate(extensionContext: extensionApi.ExtensionContext): 'A free, private OpenShift environment including one project and a resource quota of 14 GB RAM, and 40 GB storage. It lasts 30 days.\n\nSign up at [https://developers.redhat.com/developer-sandbox](https://developers.redhat.com/developer-sandbox/?sc_cid=7013a000003SUmgAAG).', }; - extensionApi.commands.registerCommand('sandbox.open.login.url', () => { - extensionApi.env - .openExternal( - extensionApi.Uri.parse('https://developers.redhat.com/developer-sandbox/?sc_cid=7013a000003SUmgAAG'), - ) - .then(successful => { - TelemetryLogger.logUsage('sandboxOpenLoginUrlRequest', { successful }); - }); - }); + extensionContext.subscriptions.push( + extensionApi.commands.registerCommand('sandbox.open.login.url', () => { + extensionApi.env + .openExternal( + extensionApi.Uri.parse('https://developers.redhat.com/developer-sandbox/?sc_cid=7013a000003SUmgAAG'), + ) + .then(successful => { + TelemetryLogger.logUsage('sandboxOpenLoginUrlRequest', { successful }); + }); + }) + ); provider = extensionApi.provider.createProvider(providerOptions); @@ -260,7 +262,7 @@ export async function activate(extensionContext: extensionApi.ExtensionContext): const kubeconfigUri = extensionApi.kubernetes.getKubeconfig(); const kubeconfigFile = kubeconfigUri.fsPath; - console.log('Configfile location', kubeconfigFile); + console.log('Config file location', kubeconfigFile); const disposable = provider.setKubernetesProviderConnectionFactory({ // eslint-disable-next-line @typescript-eslint/no-explicit-any From de68c3d91a49fa6ff8cd882dc81ba0aacb97f9af Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Wed, 27 Mar 2024 18:24:47 -0700 Subject: [PATCH 2/3] fix: fix format errors Signed-off-by: Denis Golovin --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index e4eff2d..5167a0b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -251,7 +251,7 @@ export async function activate(extensionContext: extensionApi.ExtensionContext): .then(successful => { TelemetryLogger.logUsage('sandboxOpenLoginUrlRequest', { successful }); }); - }) + }), ); provider = extensionApi.provider.createProvider(providerOptions); From 9d112f8d0892ec0737eaea6e315ff1cd2783acf7 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Wed, 1 May 2024 14:28:07 -0700 Subject: [PATCH 3/3] fix: support pushing image to any openshift internal registry Signed-off-by: Denis Golovin --- src/extension.ts | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 5167a0b..95d1f76 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -35,6 +35,7 @@ interface InternalRegistryInfo { host: string; username: string; token: string; + namespace?: string; } const StartedStatus: extensionApi.ProviderConnectionStatus = 'started'; @@ -49,6 +50,9 @@ async function whoami(clusterUrl: string, token: string): Promise { headers: { Authorization: `Bearer ${token}`, }, + https: { + rejectUnauthorized: false, + }, }; const username: string = await got(`${clusterUrl}/apis/user.openshift.io/v1/users/~`, gotOptions).then(response => { @@ -64,12 +68,16 @@ async function whoami(clusterUrl: string, token: string): Promise { async function getOpenShiftInternalRegistryPublicHost(contextName: string): Promise { const config = kubeconfig.createOrLoadFromFile(extensionApi.kubernetes.getKubeconfig().fsPath); const context = config.getContextObject(contextName); + const namespace = context.namespace; const cluster = config.getCluster(context.cluster); const user = config.getUser(context.user); const gotOptions = { headers: { Authorization: `Bearer ${user.token}`, }, + https: { + rejectUnauthorized: false, + }, }; const publicRegistry: string = await got( `${cluster.server}/apis/image.openshift.io/v1/namespaces/openshift/imagestreams`, @@ -90,6 +98,7 @@ async function getOpenShiftInternalRegistryPublicHost(contextName: string): Prom return { host, username, + namespace, token: user.token, }; } @@ -101,10 +110,18 @@ export async function pushImageToOpenShiftRegistry(image: ImageInfo): Promise connection.status === 'started') .map(connection => connection.connection.name); if (!qp.length) { - extensionApi.window.showInformationMessage( - 'You have no running Developer Sandbox connections. Please create new one and try again.', + // try to use crc contexts + const config = kubeconfig.createOrLoadFromFile(extensionApi.kubernetes.getKubeconfig().fsPath); + const crcContexts = config.contexts.filter(context => + config.getCluster(context.cluster).server.startsWith(`https://api.crc.testing`), ); - return; + if (crcContexts.length === 0) { + extensionApi.window.showInformationMessage( + 'You have no running Developer Sandbox connections. Please create new one and try again.', + ); + return; + } + crcContexts.forEach(ct => qp.push(ct.name)); } let targetSb: string; if (qp.length > 1) { @@ -130,14 +147,25 @@ export async function pushImageToOpenShiftRegistry(image: ImageInfo): Promise {