Skip to content

Commit

Permalink
Don't cache clients that are created (without auth) when app loads. (#…
Browse files Browse the repository at this point in the history
…3338)

Signed-off-by: Michael Nelson <[email protected]>
  • Loading branch information
absoludity authored Sep 1, 2021
1 parent 9657e47 commit b063daa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
6 changes: 3 additions & 3 deletions dashboard/src/shared/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { KubeappsGrpcClient } from "./KubeappsGrpcClient";
export const KUBEOPS_ROOT_URL = "api/kubeops/v1";
export class App {
// TODO(agamez): move to the core 'PackagesServiceClientImpl' when pagination is ready there
private static client = new KubeappsGrpcClient().getHelmPackagesServiceClientImpl();
private static client = () => new KubeappsGrpcClient().getHelmPackagesServiceClientImpl();

public static async GetInstalledPackageSummaries(
cluster: string,
namespace?: string,
page?: number,
size?: number,
) {
return await this.client.GetInstalledPackageSummaries({
return await this.client().GetInstalledPackageSummaries({
context: { cluster: cluster, namespace: namespace },
paginationOptions: { pageSize: size || 0, pageToken: page?.toString() || "0" },
});
Expand All @@ -25,7 +25,7 @@ export class App {
namespace: string,
releaseName: string,
) {
return await this.client.GetInstalledPackageDetail({
return await this.client().GetInstalledPackageDetail({
installedPackageRef: {
identifier: releaseName,
context: { cluster: cluster, namespace: namespace },
Expand Down
8 changes: 4 additions & 4 deletions dashboard/src/shared/Chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { KubeappsGrpcClient } from "./KubeappsGrpcClient";

export default class Chart {
// TODO(agamez): move to the core 'PackagesServiceClientImpl' when pagination is ready there
private static client = new KubeappsGrpcClient().getHelmPackagesServiceClientImpl();
private static client = () => new KubeappsGrpcClient().getHelmPackagesServiceClientImpl();

public static async getAvailablePackageSummaries(
cluster: string,
Expand All @@ -17,7 +17,7 @@ export default class Chart {
size: number,
query?: string,
): Promise<GetAvailablePackageSummariesResponse> {
return await this.client.GetAvailablePackageSummaries({
return await this.client().GetAvailablePackageSummaries({
context: { cluster: cluster, namespace: namespace },
filterOptions: {
query: query,
Expand All @@ -32,7 +32,7 @@ export default class Chart {
namespace: string,
id: string,
): Promise<GetAvailablePackageVersionsResponse> {
return await this.client.GetAvailablePackageVersions({
return await this.client().GetAvailablePackageVersions({
availablePackageRef: {
context: { cluster: cluster, namespace: namespace },
identifier: id,
Expand All @@ -46,7 +46,7 @@ export default class Chart {
id: string,
version?: string,
): Promise<GetAvailablePackageDetailResponse> {
return await this.client.GetAvailablePackageDetail({
return await this.client().GetAvailablePackageDetail({
pkgVersion: version,
availablePackageRef: {
context: { cluster: cluster, namespace: namespace },
Expand Down
27 changes: 5 additions & 22 deletions dashboard/src/shared/KubeappsGrpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ export class KubeappsGrpcClient {
private grpcWebImpl!: GrpcWebImpl;
private transport: grpc.TransportFactory;

// core apis
private packagesServiceClientImpl!: PackagesServiceClientImpl;
private pluginsServiceClientImpl!: PluginsServiceClientImpl;

// plugins package apis
private helmPackagesServiceClientImpl!: HelmPackagesServiceClientImpl;
private kappControllerPackagesServiceClientImpl!: KappControllerPackagesServiceClientImpl;
private fluxv2PackagesServiceClientImpl!: FluxV2PackagesServiceClientImpl;

constructor(transport?: grpc.TransportFactory) {
this.transport = transport ?? grpc.CrossBrowserHttpTransport({});
}
Expand All @@ -49,33 +40,25 @@ export class KubeappsGrpcClient {

// Core APIs
public getPackagesServiceClientImpl() {
return this.packagesServiceClientImpl || new PackagesServiceClientImpl(this.getGrpcClient());
return new PackagesServiceClientImpl(this.getGrpcClient());
}

public getPluginsServiceClientImpl() {
return this.pluginsServiceClientImpl || new PluginsServiceClientImpl(this.getGrpcClient());
return new PluginsServiceClientImpl(this.getGrpcClient());
}

// Plugins (packages) APIs
// TODO(agamez): ideally, these clients should be loaded automatically from a list of configured plugins
public getHelmPackagesServiceClientImpl() {
return (
this.helmPackagesServiceClientImpl || new HelmPackagesServiceClientImpl(this.getGrpcClient())
);
return new HelmPackagesServiceClientImpl(this.getGrpcClient());
}

public getKappControllerPackagesServiceClientImpl() {
return (
this.kappControllerPackagesServiceClientImpl ||
new KappControllerPackagesServiceClientImpl(this.getGrpcClient())
);
return new KappControllerPackagesServiceClientImpl(this.getGrpcClient());
}

public getFluxv2PackagesServiceClientImpl() {
return (
this.fluxv2PackagesServiceClientImpl ||
new FluxV2PackagesServiceClientImpl(this.getGrpcClient())
);
return new FluxV2PackagesServiceClientImpl(this.getGrpcClient());
}
}

Expand Down

0 comments on commit b063daa

Please sign in to comment.