Skip to content

Commit

Permalink
Fix OLM check for older k8s versions (#1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Apr 15, 2020
1 parent 1e49264 commit 17d1f42
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions dashboard/src/actions/operators.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("checkOLMInstalled", () => {
type: getType(operatorActions.OLMInstalled),
},
];
await store.dispatch(operatorActions.checkOLMInstalled());
await store.dispatch(operatorActions.checkOLMInstalled("ns"));
expect(store.getActions()).toEqual(expectedActions);
});

Expand All @@ -44,7 +44,7 @@ describe("checkOLMInstalled", () => {
payload: new Error("nope"),
},
];
await store.dispatch(operatorActions.checkOLMInstalled());
await store.dispatch(operatorActions.checkOLMInstalled("ns"));
expect(store.getActions()).toEqual(expectedActions);
});
});
Expand Down
11 changes: 4 additions & 7 deletions dashboard/src/actions/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,13 @@ const actions = [

export type OperatorAction = ActionType<typeof actions[number]>;

export function checkOLMInstalled(): ThunkAction<
Promise<boolean>,
IStoreState,
null,
OperatorAction
> {
export function checkOLMInstalled(
namespace: string,
): ThunkAction<Promise<boolean>, IStoreState, null, OperatorAction> {
return async dispatch => {
dispatch(checkingOLM());
try {
const installed = await Operators.isOLMInstalled();
const installed = await Operators.isOLMInstalled(namespace);
if (installed) {
dispatch(OLMInstalled());
}
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/components/OperatorList/OperatorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import "./OperatorList.css";

export interface IOperatorListProps {
isFetching: boolean;
checkOLMInstalled: () => Promise<boolean>;
checkOLMInstalled: (namespace: string) => Promise<boolean>;
isOLMInstalled: boolean;
namespace: string;
getOperators: (namespace: string) => Promise<void>;
Expand Down Expand Up @@ -78,7 +78,7 @@ class OperatorList extends React.Component<IOperatorListProps, IOperatorListStat
};

public componentDidMount() {
this.props.checkOLMInstalled();
this.props.checkOLMInstalled(this.props.namespace);
this.props.getOperators(this.props.namespace);
this.props.getCSVs(this.props.namespace);
this.setState({ filter: this.props.filter });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function mapStateToProps(

function mapDispatchToProps(dispatch: ThunkDispatch<IStoreState, null, Action>) {
return {
checkOLMInstalled: () => dispatch(actions.operators.checkOLMInstalled()),
checkOLMInstalled: (namespace: string) =>
dispatch(actions.operators.checkOLMInstalled(namespace)),
getOperators: (namespace: string) => dispatch(actions.operators.getOperators(namespace)),
getCSVs: (namespace: string) => dispatch(actions.operators.getCSVs(namespace)),
pushSearchFilter: (filter: string) => dispatch(actions.shared.pushSearchFilter(filter)),
Expand Down
8 changes: 4 additions & 4 deletions dashboard/src/shared/Operators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ it("check if the OLM has been installed", async () => {
axiosWithAuth.get = jest.fn(() => {
return { status: 200 };
});
expect(await Operators.isOLMInstalled()).toBe(true);
expect(await Operators.isOLMInstalled("ns")).toBe(true);
expect(axiosWithAuth.get).toHaveBeenCalled();
expect((axiosWithAuth.get as jest.Mock).mock.calls[0][0]).toEqual(
"api/kube/apis/apiextensions.k8s.io/v1/customresourcedefinitions/clusterserviceversions.operators.coreos.com",
"api/kube/apis/packages.operators.coreos.com/v1/namespaces/ns/packagemanifests",
);
});

it("OLM is not installed if the request fails", async () => {
axiosWithAuth.get = jest.fn(() => {
return { status: 404 };
});
expect(await Operators.isOLMInstalled()).toBe(false);
expect(await Operators.isOLMInstalled("ns")).toBe(false);
});

it("OLM is not installed if the request returns != 200", async () => {
axiosWithAuth.get = jest.fn(() => {
return { status: 404 };
});
expect(await Operators.isOLMInstalled()).toBe(false);
expect(await Operators.isOLMInstalled("ns")).toBe(false);
});

it("get operators", async () => {
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/shared/Operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { axiosWithAuth } from "./AxiosInstance";
import { IClusterServiceVersion, IK8sList, IPackageManifest, IResource } from "./types";

export class Operators {
public static async isOLMInstalled() {
const { status } = await axiosWithAuth.get(urls.api.operators.crd);
public static async isOLMInstalled(namespace: string) {
const { status } = await axiosWithAuth.get(urls.api.operators.operators(namespace));
return status === 200;
}

Expand Down
1 change: 0 additions & 1 deletion dashboard/src/shared/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export const api = {
},

operators: {
crd: `${APIBase}/apis/apiextensions.k8s.io/v1/customresourcedefinitions/clusterserviceversions.operators.coreos.com`,
operators: (namespace: string) =>
`${APIBase}/apis/packages.operators.coreos.com/v1/${withNS(namespace)}packagemanifests`,
operator: (namespace: string, name: string) =>
Expand Down

0 comments on commit 17d1f42

Please sign in to comment.