Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't cache clients that are created (without auth) when app loads. #3338

Merged
merged 1 commit into from
Sep 1, 2021
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
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