Skip to content

Commit

Permalink
List operator resources in all namespaces (#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor committed Nov 3, 2020
1 parent f0d8b77 commit 4234dfa
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
30 changes: 30 additions & 0 deletions dashboard/src/actions/operators.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,36 @@ describe("getResources", () => {
await store.dispatch(operatorActions.getResources("default", "default"));
expect(store.getActions()).toEqual(expectedActions);
});

it("ignores csv without owned crds", async () => {
const csv = {
metadata: { name: "foo" },
spec: {
customresourcedefinitions: {},
},
};
Operators.getCSVs = jest.fn().mockReturnValue([csv]);
Operators.listResources = jest.fn();
const expectedActions = [
{
type: getType(operatorActions.requestCustomResources),
},
{
type: getType(operatorActions.requestCSVs),
},
{
type: getType(operatorActions.receiveCSVs),
payload: [csv],
},
{
type: getType(operatorActions.receiveCustomResources),
payload: [],
},
];
await store.dispatch(operatorActions.getResources("default", "default"));
expect(store.getActions()).toEqual(expectedActions);
expect(Operators.listResources).not.toHaveBeenCalled();
});
});

describe("getResources", () => {
Expand Down
12 changes: 10 additions & 2 deletions dashboard/src/actions/operators.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { get } from "lodash";
import { ThunkAction } from "redux-thunk";
import { ActionType, createAction } from "typesafe-actions";

import { Operators } from "../shared/Operators";
import { IClusterServiceVersion, IPackageManifest, IResource, IStoreState } from "../shared/types";
import {
IClusterServiceVersion,
IClusterServiceVersionCRD,
IPackageManifest,
IResource,
IStoreState,
} from "../shared/types";

export const checkingOLM = createAction("CHECKING_OLM");
export const OLMInstalled = createAction("OLM_INSTALLED");
Expand Down Expand Up @@ -307,7 +314,8 @@ export function getResources(
const csvs = await dispatch(getCSVs(cluster, namespace));
let resources: IResource[] = [];
const csvPromises = csvs.map(async csv => {
const crdPromises = csv.spec.customresourcedefinitions.owned.map(async crd => {
const crds = get(csv, "spec.customresourcedefinitions.owned", []);
const crdPromises = crds.map(async (crd: IClusterServiceVersionCRD) => {
const { plural, group } = parseCRD(crd.name);
try {
const csvResources = await Operators.listResources(
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/shared/Operators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ it("get csvs", async () => {
);
});

it("get global csvs", async () => {
it("get csvs in all namespaces", async () => {
const csv = { metadata: { name: "foo" } } as IClusterServiceVersion;
const ns = "_all";
axiosWithAuth.get = jest.fn().mockReturnValue({ data: { items: [csv] } });
expect(await Operators.getCSVs(cluster, ns)).toEqual([csv]);
expect(axiosWithAuth.get).toHaveBeenCalled();
expect((axiosWithAuth.get as jest.Mock).mock.calls[0][0]).toEqual(
"api/clusters/defaultc/apis/operators.coreos.com/v1alpha1/namespaces/operators/clusterserviceversions",
"api/clusters/defaultc/apis/operators.coreos.com/v1alpha1/clusterserviceversions",
);
});

Expand Down
3 changes: 1 addition & 2 deletions dashboard/src/shared/Operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ export class Operators {

public static async getCSVs(cluster: string, namespace: string) {
// Global operators are installed in the "operators" namespace
const reqNamespace = namespace === "_all" ? "operators" : namespace;
const { data } = await axiosWithAuth.get<IK8sList<IClusterServiceVersion, {}>>(
urls.api.k8s.operators.clusterServiceVersions(cluster, reqNamespace),
urls.api.k8s.operators.clusterServiceVersions(cluster, namespace),
);
return data.items;
}
Expand Down

0 comments on commit 4234dfa

Please sign in to comment.