Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit 23e9605

Browse files
authored
Add minor improvements prior to the repos UI (#4848)
* Add more information in the core API logs Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com> * Handle uncaught canI rejections Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com> * Remove "as unknown" in some types Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com> * Return 0 if equals in a sort function Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com> * Add more str cases in getPluginPackageName Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com> * Add repos api clients to KubeappsGrpcClient Signed-off-by: Antonio Gamez Diaz <agamez@vmware.com>
1 parent a2df5b1 commit 23e9605

12 files changed

Lines changed: 86 additions & 35 deletions

File tree

cmd/kubeapps-apis/core/packages/v1alpha1/packages.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewPackagesServer(pkgingPlugins []pluginsv1alpha1.PluginWithServer) (*packa
4646
plugin: p.Plugin,
4747
server: pkgsSrv,
4848
}
49-
log.Infof("Registered %v for core.packaging.v1alpha1 aggregation.", p.Plugin)
49+
log.Infof("Registered %v for core.packaging.v1alpha1 packages aggregation.", p.Plugin)
5050
}
5151
return &packagesServer{
5252
pluginsWithServers: pluginsWithServer,

cmd/kubeapps-apis/core/packages/v1alpha1/repositories.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewRepositoriesServer(pkgingPlugins []pluginsv1alpha1.PluginWithServer) (*r
4646
plugin: p.Plugin,
4747
server: pkgsSrv,
4848
}
49-
log.Infof("Registered %v for core.packaging.v1alpha1 aggregation.", p.Plugin)
49+
log.Infof("Registered %v for core.packaging.v1alpha1 repositories aggregation.", p.Plugin)
5050
}
5151
return &repositoriesServer{
5252
pluginsWithServers: pluginsWithServer,

dashboard/src/actions/namespace.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ describe("setNamespace", () => {
231231

232232
describe("canCreate", () => {
233233
it("checks if it can create namespaces", async () => {
234-
Kube.canI = jest.fn().mockReturnValue(true);
234+
Kube.canI = jest.fn().mockReturnValue({
235+
then: jest.fn(f => f(true)),
236+
catch: jest.fn(f => f(false)),
237+
});
235238
const expectedActions = [
236239
{
237240
type: getType(setAllowCreate),

dashboard/src/components/AppList/AppList.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ beforeEach(() => {
4545
spyOnUseDispatch = jest.spyOn(ReactRedux, "useDispatch").mockReturnValue(mockDispatch);
4646
Kube.canI = jest.fn().mockReturnValue({
4747
then: jest.fn(f => f(true)),
48+
catch: jest.fn(f => f(false)),
4849
});
4950
});
5051

@@ -126,6 +127,7 @@ context("when changing props", () => {
126127
it("should hide the all-namespace switch if the user doesn't have permissions", async () => {
127128
Kube.canI = jest.fn().mockReturnValue({
128129
then: jest.fn((f: any) => f(false)),
130+
catch: jest.fn(f => f(false)),
129131
});
130132
const wrapper = mountWrapper(defaultStore, <AppList />);
131133
expect(wrapper.find("input[type='checkbox']")).not.toExist();

dashboard/src/components/AppList/AppList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ function AppList() {
8181
useEffect(() => {
8282
// In order to be able to list applications in all namespaces, it's necessary to be able
8383
// to list/get secrets in all of them.
84-
Kube.canI(cluster, "", "secrets", "list", "").then(allowed => setCanSetAllNS(allowed));
84+
Kube.canI(cluster, "", "secrets", "list", "")
85+
.then(allowed => setCanSetAllNS(allowed))
86+
?.catch(() => setCanSetAllNS(false));
8587
}, [cluster]);
8688

8789
useEffect(() => {

dashboard/src/components/AppView/CustomAppView/CustomAppView.test.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import {
55
InstalledPackageDetail,
66
AvailablePackageDetail,
7+
ResourceRef,
78
} from "gen/kubeappsapis/core/packages/v1alpha1/packages";
89
import { getStore, mountWrapper } from "shared/specs/mountWrapper";
910
import CustomAppView from ".";
@@ -21,7 +22,7 @@ const defaultProps = {
2122
},
2223
} as InstalledPackageDetail,
2324
resourceRefs: {
24-
ingresses: [],
25+
ingresses: [] as ResourceRef[],
2526
deployments: [
2627
{
2728
cluster: "default",
@@ -31,10 +32,10 @@ const defaultProps = {
3132
namespaced: true,
3233
name: "ssh-server-example",
3334
namespace: "demo-namespace",
34-
},
35-
],
36-
statefulsets: [],
37-
daemonsets: [],
35+
} as ResourceRef,
36+
] as ResourceRef[],
37+
statefulsets: [] as ResourceRef[],
38+
daemonsets: [] as ResourceRef[],
3839
otherResources: [
3940
{
4041
cluster: "default",
@@ -44,8 +45,8 @@ const defaultProps = {
4445
namespaced: true,
4546
name: "ssh-server-example-root-pv-claim",
4647
namespace: "demo-namespace",
47-
},
48-
],
48+
} as ResourceRef,
49+
] as ResourceRef[],
4950
services: [
5051
{
5152
cluster: "default",
@@ -55,10 +56,10 @@ const defaultProps = {
5556
namespaced: true,
5657
name: "ssh-server-example",
5758
namespace: "demo-namespace",
58-
},
59-
],
60-
secrets: [],
61-
} as unknown as IAppViewResourceRefs,
59+
} as ResourceRef,
60+
] as ResourceRef[],
61+
secrets: [] as ResourceRef[],
62+
} as IAppViewResourceRefs,
6263
appDetails: {} as AvailablePackageDetail,
6364
};
6465

dashboard/src/components/Catalog/CatalogItems.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ export default function CatalogItems({
8080
? []
8181
: packageItems
8282
.concat(crdItems)
83-
.sort((a, b) => (a.item.name.toLowerCase() > b.item.name.toLowerCase() ? 1 : -1));
83+
.sort((a, b) =>
84+
a.item.name.toLowerCase() > b.item.name.toLowerCase()
85+
? 1
86+
: b.item.name.toLowerCase() > a.item.name.toLowerCase()
87+
? -1
88+
: 0,
89+
);
8490

8591
if (hasFinishedFetching && sortedItems.length === 0) {
8692
return <p>No application matches the current filter.</p>;

dashboard/src/components/Config/AppRepoList/AppRepoList.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ beforeEach(() => {
3434
spyOnUseDispatch = jest.spyOn(ReactRedux, "useDispatch").mockReturnValue(mockDispatch);
3535
Kube.canI = jest.fn().mockReturnValue({
3636
then: jest.fn(f => f(true)),
37+
catch: jest.fn(f => f(false)),
3738
});
3839
});
3940

@@ -76,6 +77,7 @@ it("fetches repos from all namespaces (without kubeappsNamespace)", () => {
7677
it("should hide the all-namespace switch if the user doesn't have permissions", async () => {
7778
Kube.canI = jest.fn().mockReturnValue({
7879
then: jest.fn((f: any) => f(false)),
80+
catch: jest.fn(f => f(false)),
7981
});
8082
const wrapper = mountWrapper(defaultStore, <AppRepoList />);
8183
expect(wrapper.find("input[type='checkbox']")).not.toExist();
@@ -162,6 +164,7 @@ describe("global and namespaced repositories", () => {
162164
it("shows the global repositories with the buttons deactivated if the current user is not allowed to modify them", () => {
163165
Kube.canI = jest.fn().mockReturnValue({
164166
then: jest.fn((f: any) => f(false)),
167+
catch: jest.fn(f => f(false)),
165168
});
166169
const wrapper = mountWrapper(
167170
getStore({

dashboard/src/components/Config/AppRepoList/AppRepoList.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,12 @@ function AppRepoList() {
8585
}, [allNS, currentNamespace]);
8686

8787
useEffect(() => {
88-
Kube.canI(cluster, "kubeapps.com", "apprepositories", "list", "").then(allowed =>
89-
setCanSetAllNS(allowed),
90-
);
91-
Kube.canI(
92-
kubeappsCluster,
93-
"kubeapps.com",
94-
"apprepositories",
95-
"update",
96-
globalReposNamespace,
97-
).then(allowed => setCanEditGlobalRepos(allowed));
88+
Kube.canI(cluster, "kubeapps.com", "apprepositories", "list", "")
89+
.then(allowed => setCanSetAllNS(allowed))
90+
?.catch(() => setCanSetAllNS(false));
91+
Kube.canI(kubeappsCluster, "kubeapps.com", "apprepositories", "update", globalReposNamespace)
92+
.then(allowed => setCanEditGlobalRepos(allowed))
93+
?.catch(() => setCanEditGlobalRepos(false));
9894
}, [cluster, kubeappsCluster, kubeappsNamespace, globalReposNamespace]);
9995

10096
const globalRepos: IAppRepository[] = [];

dashboard/src/shared/KubeappsGrpcClient.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,26 @@ describe("kubeapps grpc client creation", () => {
1818
const serviceClients = [
1919
kubeappsGrpcClient.getPluginsServiceClientImpl(),
2020
kubeappsGrpcClient.getPackagesServiceClientImpl(),
21+
kubeappsGrpcClient.getRepositoriesServiceClientImpl(),
22+
kubeappsGrpcClient.getResourcesServiceClientImpl(),
2123
];
2224
serviceClients.every(sc => expect(sc).not.toBeNull());
2325
});
2426

2527
it("should create the clients for each plugin service", async () => {
2628
const kubeappsGrpcClient = new KubeappsGrpcClient(fakeEmpyTransport);
27-
const serviceClients = [
29+
const packagesServiceClients = [
2830
kubeappsGrpcClient.getHelmPackagesServiceClientImpl(),
2931
kubeappsGrpcClient.getKappControllerPackagesServiceClientImpl(),
3032
kubeappsGrpcClient.getFluxv2PackagesServiceClientImpl(),
3133
];
32-
serviceClients.every(sc => expect(sc).not.toBeNull());
34+
const repositoriesServiceClients = [
35+
kubeappsGrpcClient.getHelmRepositoriesServiceClientImpl(),
36+
kubeappsGrpcClient.getKappControllerRepositoriesServiceClientImpl(),
37+
kubeappsGrpcClient.getFluxV2RepositoriesServiceClientImpl(),
38+
];
39+
packagesServiceClients.every(sc => expect(sc).not.toBeNull());
40+
repositoriesServiceClients.every(sc => expect(sc).not.toBeNull());
3341
});
3442
});
3543

0 commit comments

Comments
 (0)