Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardo-forina committed Jul 11, 2024
1 parent bdd240f commit 4e99169
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 306 deletions.
109 changes: 66 additions & 43 deletions podman-desktop-extension/packages/backend/src/api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class StreamshubImpl implements StreamshubApi {
}

async listConsoles(): Promise<StreamshubConsoleInfo[]> {
console.group('listConsoles');
const consoles: Record<string, StreamshubConsoleInfo> = {};
const { storagePath } = this.extensionContext;
try {
Expand Down Expand Up @@ -105,11 +106,15 @@ export class StreamshubImpl implements StreamshubApi {
};
}
});
} catch {}
} catch {
console.log('storagePath empty');
}
console.log({ containers, consoleContainers, consoles });
} catch (err) {
await podmanDesktopApi.window.showErrorMessage(`Error listing containers: ${err}`);
console.error('Error listing containers: ', err);
} finally {
console.groupEnd();
}
return Object.values(consoles);
}
Expand Down Expand Up @@ -154,7 +159,7 @@ export class StreamshubImpl implements StreamshubApi {
}

async getKubernetesClusters(): Promise<{ context: string; server: string; clusters: KubernetesCluster[] }> {
console.log('getKubernetesClusters');
console.group('getKubernetesClusters');
try {
const { stdout: context } = await podmanDesktopApi.process.exec('kubectl', ['config', 'current-context']);
console.log('getKubernetesClusters', { context });
Expand Down Expand Up @@ -218,10 +223,13 @@ export class StreamshubImpl implements StreamshubApi {
} catch (e) {
console.error(e);
throw e;
} finally {
console.groupEnd();
}
}

async containerChanges() {
console.log('containerChanges');
return this.notify(Messages.MSG_CONTAINERS_UPDATE);
}

Expand Down Expand Up @@ -254,6 +262,7 @@ async function getServerFromMinikube() {
}

async function getToken(namespace: string): Promise<string | undefined> {
console.group('getToken');
try {
const { stdout: tokenRaw } = await podmanDesktopApi.process.exec('kubectl', [
'describe',
Expand All @@ -280,56 +289,70 @@ async function getToken(namespace: string): Promise<string | undefined> {
`--duration=${365 * 24}h`,
]);
return token;
} finally {
console.groupEnd();
}
}

async function getNamespaceJaasConfigurations(namespace: string): Promise<Record<string, string[]>> {
const { stdout: usersRaw } = await podmanDesktopApi.process.exec('kubectl', [
'get',
'kafkausers',
'-n',
namespace,
'-o',
'json',
]);
const users = JSON.parse(usersRaw) as {
items: {
metadata: {
labels: {
'strimzi.io/cluster': string;
console.group('getNamespaceJaasConfigurations');
try {
const { stdout: usersRaw } = await podmanDesktopApi.process.exec('kubectl', [
'get',
'kafkausers',
'-n',
namespace,
'-o',
'json',
]);
const users = JSON.parse(usersRaw) as {
items: {
metadata: {
labels: {
'strimzi.io/cluster': string;
};
};
};
status: {
username: string;
secret: string;
};
}[];
};
const usersList = users.items.map(u => u.status.username);
const { stdout: secretsRaw } = await podmanDesktopApi.process.exec('kubectl', [
'get',
'secrets',
'-n',
namespace,
'-o',
'json',
...usersList,
]);
const secrets = JSON.parse(secretsRaw) as {
items: {
status: {
username: string;
secret: string;
};
}[];
};
const usersList = users.items.map(u => u.status.username);
const { stdout: secretsRaw } = await podmanDesktopApi.process.exec('kubectl', [
'get',
'secrets',
'-n',
namespace,
'-o',
'json',
...usersList,
]);
type Secret = {
data: {
'sasl.jaas.config': string;
};
metadata: {
name: string;
};
}[];
};
const jaasConfigurations: Record<string, string[]> = Object.fromEntries(
users.items.map(u => [
u.metadata.labels['strimzi.io/cluster'],
secrets.items.filter(s => s.metadata.name === u.status.secret).map(s => atob(s.data['sasl.jaas.config'])),
]),
);
return jaasConfigurations;
};
type Secrets = {
items: Secret[];
};
const secretsObj = JSON.parse(secretsRaw) as Secrets | Secret;
const secrets = 'items' in secretsObj ? secretsObj : { items: [secretsObj] };
console.log('secrets', secrets);
const jaasConfigurations: Record<string, string[]> = Object.fromEntries(
users.items.map(u => [
u.metadata.labels['strimzi.io/cluster'],
secrets.items.filter(s => s.metadata.name === u.status.secret).map(s => atob(s.data['sasl.jaas.config'])),
]),
);
return jaasConfigurations;
} catch (e) {
console.error('getNamespaceJaasConfigurations', e);
} finally {
console.groupEnd();
}
return {};
}
2 changes: 1 addition & 1 deletion podman-desktop-extension/packages/backend/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function activate(extensionContext: ExtensionContext): Promise<void
// handle it after a while
debounceTimeout = setTimeout(() => {
void streamshubApi.containerChanges();
}, 1000);
}, 100);
}),
);
}
Expand Down
10 changes: 9 additions & 1 deletion podman-desktop-extension/packages/backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ services:
NEXTAUTH_URL: http://localhost:3000
BACKEND_URL: http://console-api:8080/
labels:
io.streamshub.console.container: ui`,
io.streamshub.console.container: ui
console-registry:
image: quay.io/apicurio/apicurio-registry-mem:2.6.1.Final
ports:
- :8080
labels:
io.streamshub.console.container: registry
`,
);
}

Expand Down
3 changes: 2 additions & 1 deletion podman-desktop-extension/packages/backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"resolveJsonModule": true,
"lib": [
"ES2017",
"ES2021",
"webworker",
"dom",
],
Expand All @@ -28,4 +29,4 @@
"../shared/*.ts",
"../shared/**/*.ts"
],
}
}
106 changes: 53 additions & 53 deletions podman-desktop-extension/packages/frontend/src/Clusters.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,80 @@
import ClusterNameColumn from '/@/lib/ClusterNameColumn.svelte';
import ClusterNamespaceColumn from '/@/lib/ClusterNamespaceColumn.svelte';
import ClusterVersionColumn from '/@/lib/ClusterVersionColumn.svelte';
import ConsoleActions from '/@/lib/ConsoleActions.svelte';
import NavPage from '/@/lib/upstream/NavPage.svelte';
import type {StreamshubConsoleInfo} from '/@shared/src/models/streamshub';
import {Table, TableColumn, TableRow} from '@podman-desktop/ui-svelte';
import {onMount} from 'svelte';
export let project: string;
let consoleObj: StreamshubConsoleInfo | undefined = undefined;
let clusters: ClusterListColumn[] | undefined = undefined;
let consoleObj: StreamshubConsoleInfo | undefined = undefined;
let clusters: ClusterListColumn[] | undefined = undefined;
type ClusterListColumn = ClusterList & {
selected: boolean;
project: string;
}
onMount(async () => {
const consoles = await streamshubClient.listConsoles();
consoleObj = consoles.find(c => c.project === project);
console.log({ project, consoles, object: consoleObj });
clusters = (await getKafkaClusters()).map(c => ({ ...c, selected: false, project }));
});
type ClusterListColumn = ClusterList & {
selected: boolean;
project: string;
};
onMount(async () => {
const consoles = await streamshubClient.listConsoles();
consoleObj = consoles.find(c => c.project === project);
console.log({ project, consoles, object: consoleObj });
clusters = (await getKafkaClusters()).map(c => ({ ...c, selected: false, project }));
});
async function getKafkaClusters(): Promise<ClusterList[]> {
const sp = new URLSearchParams({
'fields[kafkas]': 'name,namespace,kafkaVersion',
sort: 'name',
});
const kafkaClustersQuery = sp.toString();
const url = `${consoleObj!.api.baseUrl}/api/kafkas?${kafkaClustersQuery}`;
try {
const res = await fetch(url);
const rawData = await res.json();
console.log('getKafkaClusters', rawData);
return ClustersResponseSchema.parse(rawData).data;
} catch (err) {
console.error('getKafkaClusters', err);
return [];
}
async function getKafkaClusters(): Promise<ClusterList[]> {
const sp = new URLSearchParams({
'fields[kafkas]': 'name,namespace,kafkaVersion',
sort: 'name',
});
const kafkaClustersQuery = sp.toString();
const url = `${consoleObj!.api.baseUrl}/api/kafkas?${kafkaClustersQuery}`;
try {
const res = await fetch(url);
const rawData = await res.json();
console.log('getKafkaClusters', rawData);
return ClustersResponseSchema.parse(rawData).data;
} catch (err) {
console.error('getKafkaClusters', err);
return [];
}
}
let selectedItemsNumber: number;
let table: Table;
let selectedItemsNumber: number;
let table: Table;
let nameColumn = new TableColumn<ClusterList>('Cluster', {
renderer: ClusterNameColumn,
comparator: (a, b) => a.attributes.name.localeCompare(b.attributes.name),
});
let nameColumn = new TableColumn<ClusterList>('Cluster', {
renderer: ClusterNameColumn,
comparator: (a, b) => a.attributes.name.localeCompare(b.attributes.name),
});
let namespaceColumn = new TableColumn<ClusterList>('Kubernetes namespace', {
renderer: ClusterNamespaceColumn,
comparator: (a, b) => a.attributes.namespace.localeCompare(b.attributes.namespace),
});
let namespaceColumn = new TableColumn<ClusterList>('Kubernetes namespace', {
renderer: ClusterNamespaceColumn,
comparator: (a, b) => a.attributes.namespace.localeCompare(b.attributes.namespace),
});
let versionColumn = new TableColumn<ClusterList>('Kafka version', {
renderer: ClusterVersionColumn,
comparator: (a, b) => a.attributes.namespace.localeCompare(b.attributes.namespace),
});
let versionColumn = new TableColumn<ClusterList>('Kafka version', {
renderer: ClusterVersionColumn,
comparator: (a, b) => a.attributes.namespace.localeCompare(b.attributes.namespace),
});
const columns: TableColumn<ClusterList, ClusterList | string>[] = [
nameColumn,
namespaceColumn,
versionColumn,
];
const columns: TableColumn<ClusterList, ClusterList | string>[] = [nameColumn, namespaceColumn, versionColumn];
const row = new TableRow<ClusterList>({});
const row = new TableRow<ClusterList>({});
</script>

<NavPage
lastPage="{{ name: 'Streamshub', path: '/' }}"
loading={clusters === undefined}
loading="{clusters === undefined}"
searchEnabled="{false}"
title={consoleObj?.project ?? ''}
>
title="{consoleObj?.project ?? ''}">
<svelte:fragment slot="additional-actions">
{#if consoleObj}
<ConsoleActions object="{consoleObj}" showManagedActions="{false}" />
{/if}
</svelte:fragment>

<div class="flex min-w-full h-full py-5" slot="content">
{#if clusters}
<Table
Expand All @@ -95,5 +96,4 @@
{/if}
{/if}
</div>

</NavPage>
Loading

0 comments on commit 4e99169

Please sign in to comment.