diff --git a/src/extension.ts b/src/extension.ts index b2d9963..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 { @@ -242,15 +270,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 +290,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