Skip to content

Commit

Permalink
Show operators and instances in all namespaces (#1607)
Browse files Browse the repository at this point in the history
* Show operators and instances in all namespaces

* Avoid double slash
  • Loading branch information
Andres Martinez Gotor authored Mar 26, 2020
1 parent d322fb1 commit 0316f74
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import itBehavesLike from "../../shared/specs";
import { ConflictError, IClusterServiceVersion } from "../../shared/types";
import { ErrorSelector } from "../ErrorAlert";
import NotFoundErrorPage from "../ErrorAlert/NotFoundErrorAlert";
import UnexpectedErrorPage from "../ErrorAlert/UnexpectedErrorAlert";
import { IOperatorInstanceFormProps } from "./OperatorInstanceForm";

const defaultProps: IOperatorInstanceFormProps = {
Expand Down Expand Up @@ -83,6 +84,11 @@ it("renders an error if there is some error fetching", () => {
expect(wrapper.find(ErrorSelector)).toExist();
});

it("renders an error if the namespace is _all", () => {
const wrapper = shallow(<OperatorInstanceForm {...defaultProps} namespace="_all" />);
expect(wrapper.find(UnexpectedErrorPage)).toExist();
});

it("renders an error if the CRD is not populated", () => {
const wrapper = shallow(<OperatorInstanceForm {...defaultProps} />);
expect(wrapper.find(NotFoundErrorPage)).toExist();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Moniker from "moniker-native";
import * as React from "react";
import { Tab, TabList, TabPanel, Tabs } from "react-tabs";

import { definedNamespaces } from "../../shared/Namespace";
import {
IClusterServiceVersion,
IClusterServiceVersionCRD,
Expand All @@ -16,6 +17,7 @@ import AdvancedDeploymentForm from "../DeploymentFormBody/AdvancedDeploymentForm
import Differential from "../DeploymentFormBody/Differential";
import { ErrorSelector } from "../ErrorAlert";
import NotFoundErrorPage from "../ErrorAlert/NotFoundErrorAlert";
import UnexpectedErrorPage from "../ErrorAlert/UnexpectedErrorAlert";
import LoadingWrapper from "../LoadingWrapper";
import PageHeader from "../PageHeader";

Expand Down Expand Up @@ -93,7 +95,7 @@ class DeploymentFormBody extends React.Component<
}

public render() {
const { isFetching, errors, csvName, crdName } = this.props;
const { isFetching, errors, csvName, crdName, namespace } = this.props;
const { crd, submittedResourceName, error } = this.state;

if (errors.fetch) {
Expand All @@ -104,6 +106,9 @@ class DeploymentFormBody extends React.Component<
/>
);
}
if (namespace === definedNamespaces.all) {
return <UnexpectedErrorPage title="Select a namespace before creating a new instance." />;
}
if (isFetching) {
return <LoadingWrapper />;
}
Expand Down
13 changes: 13 additions & 0 deletions dashboard/src/shared/Operators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ it("get csvs", async () => {
);
});

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

it("get csv", async () => {
const csv = { metadata: { name: "foo" } } as IClusterServiceVersion;
const ns = "default";
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/shared/Operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export class Operators {
}

public static async getCSVs(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.operators.clusterServiceVersions(namespace),
urls.api.operators.clusterServiceVersions(reqNamespace),
);
return data.items;
}
Expand Down
10 changes: 7 additions & 3 deletions dashboard/src/shared/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const app = {
},
};

function withNS(namespace: string) {
return namespace === "_all" ? "" : `namespaces/${namespace}/`;
}

export const backend = {
apprepositories: {
base: (namespace: string) => `api/v1/namespaces/${namespace}/apprepositories`,
Expand Down Expand Up @@ -67,17 +71,17 @@ 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/namespaces/${namespace}/packagemanifests`,
`${APIBase}/apis/packages.operators.coreos.com/v1/${withNS(namespace)}packagemanifests`,
operator: (namespace: string, name: string) =>
`${APIBase}/apis/packages.operators.coreos.com/v1/namespaces/${namespace}/packagemanifests/${name}`,
clusterServiceVersions: (namespace: string) =>
`${APIBase}/apis/operators.coreos.com/v1alpha1/namespaces/${namespace}/clusterserviceversions`,
`${APIBase}/apis/operators.coreos.com/v1alpha1/${withNS(namespace)}clusterserviceversions`,
clusterServiceVersion: (namespace: string, name: string) =>
`${APIBase}/apis/operators.coreos.com/v1alpha1/namespaces/${namespace}/clusterserviceversions/${name}`,
operatorIcon: (namespace: string, name: string) =>
`api/v1/namespaces/${namespace}/operator/${name}/logo`,
resources: (namespace: string, apiVersion: string, resource: string) =>
`${APIBase}/apis/${apiVersion}/namespaces/${namespace}/${resource}`,
`${APIBase}/apis/${apiVersion}/${withNS(namespace)}${resource}`,
resource: (namespace: string, apiVersion: string, resource: string, name: string) =>
`${APIBase}/apis/${apiVersion}/namespaces/${namespace}/${resource}/${name}`,
},
Expand Down

0 comments on commit 0316f74

Please sign in to comment.