Skip to content

Commit

Permalink
Fix operator code landed between #1974 proposed and landed. (#1989)
Browse files Browse the repository at this point in the history
* Fix operator code landed between #1974 proposed and landed.

* Moar lint
  • Loading branch information
absoludity authored Sep 1, 2020
1 parent c0aa913 commit edd06a0
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ it("retrieves CSV when mounted", () => {
const getCSV = jest.fn();
actions.operators.getCSV = getCSV;
mountWrapper(defaultStore, <OperatorInstanceForm {...defaultProps} />);
expect(getCSV).toHaveBeenCalledWith(defaultProps.namespace, defaultProps.csvName);
expect(getCSV).toHaveBeenCalledWith(
defaultProps.cluster,
defaultProps.namespace,
defaultProps.csvName,
);
});

it("retrieves the example values and the target CRD from the given CSV", () => {
Expand Down Expand Up @@ -144,6 +148,7 @@ it("should submit the form", () => {
},
};
expect(createResource).toHaveBeenCalledWith(
defaultProps.cluster,
defaultProps.namespace,
resource.apiVersion,
defaultCRD.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export default function DeploymentFormBody({
const [icon, setIcon] = useState(placeholder);

useEffect(() => {
dispatch(actions.operators.getCSV(namespace, csvName));
}, [dispatch, namespace, csvName]);
dispatch(actions.operators.getCSV(cluster, namespace, csvName));
}, [cluster, dispatch, namespace, csvName]);

const {
operators: {
Expand Down Expand Up @@ -119,7 +119,13 @@ export default function DeploymentFormBody({
}
const resourceType = crd.name.split(".")[0];
const created = await dispatch(
actions.operators.createResource(namespace, resource.apiVersion, resourceType, resource),
actions.operators.createResource(
cluster,
namespace,
resource.apiVersion,
resourceType,
resource,
),
);
if (created) {
dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ it("gets resource and CSV", () => {
actions.operators.getResource = getResource;
actions.operators.getCSV = getCSV;
mountWrapper(defaultStore, <OperatorInstanceUpdateForm {...defaultProps} />);
expect(getCSV).toHaveBeenCalledWith(defaultProps.namespace, defaultProps.csvName);
expect(getCSV).toHaveBeenCalledWith(
defaultProps.cluster,
defaultProps.namespace,
defaultProps.csvName,
);
expect(getResource).toHaveBeenCalledWith(
defaultProps.cluster,
defaultProps.namespace,
defaultProps.csvName,
defaultProps.crdName,
Expand Down Expand Up @@ -119,6 +124,7 @@ it("should submit the form", () => {
form.simulate("submit", { preventDefault: jest.fn() });

expect(updateResource).toHaveBeenCalledWith(
defaultProps.cluster,
defaultProps.namespace,
defaultResource.apiVersion,
defaultProps.crdName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function OperatorInstanceUpdateForm({
const [icon, setIcon] = useState(placeholder);

useEffect(() => {
dispatch(actions.operators.getResource(namespace, csvName, crdName, resourceName));
dispatch(actions.operators.getCSV(namespace, csvName));
}, [dispatch, namespace, csvName, crdName, resourceName]);
dispatch(actions.operators.getResource(cluster, namespace, csvName, crdName, resourceName));
dispatch(actions.operators.getCSV(cluster, namespace, csvName));
}, [dispatch, cluster, namespace, csvName, crdName, resourceName]);

const {
operators: {
Expand Down Expand Up @@ -79,6 +79,7 @@ function OperatorInstanceUpdateForm({
const handleDeploy = async (updatedResource: IResource) => {
const created = await dispatch(
actions.operators.updateResource(
cluster,
namespace,
updatedResource.apiVersion,
crdName.split(".")[0],
Expand Down
15 changes: 13 additions & 2 deletions dashboard/src/components/OperatorNew/OperatorNew.v2.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ it("calls getOperator when mounting the component", () => {
const getOperator = jest.fn();
actions.operators.getOperator = getOperator;
mountWrapper(defaultStore, <OperatorNew {...defaultProps} />);
expect(getOperator).toHaveBeenCalledWith(defaultProps.namespace, defaultProps.operatorName);
expect(getOperator).toHaveBeenCalledWith(
defaultProps.cluster,
defaultProps.namespace,
defaultProps.operatorName,
);
});

it("parses the default channel when receiving the operator", () => {
Expand Down Expand Up @@ -139,5 +143,12 @@ it("deploys an operator", async () => {
const onSubmit = wrapper.find("form").prop("onSubmit") as () => Promise<void>;
await onSubmit();

expect(createOperator).toHaveBeenCalledWith("kubeapps", "foo", "beta", "Automatic", "foo.1.0.0");
expect(createOperator).toHaveBeenCalledWith(
defaultProps.cluster,
"kubeapps",
"foo",
"beta",
"Automatic",
"foo.1.0.0",
);
});
8 changes: 5 additions & 3 deletions dashboard/src/components/OperatorNew/OperatorNew.v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import "./OperatorNew.v2.css";
interface IOperatorNewProps {
operatorName: string;
operator?: IPackageManifest;
getOperator: (namespace: string, name: string) => Promise<void>;
getOperator: (cluster: string, namespace: string, name: string) => Promise<void>;
isFetching: boolean;
cluster: string;
namespace: string;
errors: IOperatorsStateError;
createOperator: (
cluster: string,
namespace: string,
name: string,
channel: string,
Expand All @@ -50,8 +51,8 @@ export default function OperatorNew({ namespace, operatorName, cluster }: IOpera
const [approvalStrategyAutomatic, setApprovalStrategyAutomatic] = useState(true);

useEffect(() => {
dispatch(actions.operators.getOperator(namespace, operatorName));
}, [dispatch, namespace, operatorName]);
dispatch(actions.operators.getOperator(cluster, namespace, operatorName));
}, [dispatch, cluster, namespace, operatorName]);

const {
operators: {
Expand Down Expand Up @@ -127,6 +128,7 @@ export default function OperatorNew({ namespace, operatorName, cluster }: IOpera
const approvalStrategy = approvalStrategyAutomatic ? "Automatic" : "Manual";
const deployed = await dispatch(
actions.operators.createOperator(
cluster,
targetNS,
operator!.metadata.name,
updateChannel!.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ it("calls getOperator when mounting the component", () => {
const getOperator = jest.fn();
actions.operators.getOperator = getOperator;
mountWrapper(defaultStore, <OperatorView {...defaultProps} />);
expect(getOperator).toHaveBeenCalledWith(defaultProps.namespace, defaultProps.operatorName);
expect(getOperator).toHaveBeenCalledWith(
defaultProps.cluster,
defaultProps.namespace,
defaultProps.operatorName,
);
});

it("tries to get the CSV for the current operator", () => {
Expand All @@ -84,6 +88,7 @@ it("tries to get the CSV for the current operator", () => {
);

expect(getCSV).toHaveBeenCalledWith(
defaultProps.cluster,
defaultOperator.metadata.namespace,
defaultOperator.status.channels[0].currentCSV,
);
Expand Down
8 changes: 4 additions & 4 deletions dashboard/src/components/OperatorView/OperatorView.v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ interface IOperatorViewProps {
export default function OperatorView({ operatorName, cluster, namespace }: IOperatorViewProps) {
const dispatch = useDispatch();
useEffect(() => {
dispatch(actions.operators.getOperator(namespace, operatorName));
}, [dispatch, namespace, operatorName]);
dispatch(actions.operators.getOperator(cluster, namespace, operatorName));
}, [dispatch, cluster, namespace, operatorName]);

const {
operators: {
Expand All @@ -44,10 +44,10 @@ export default function OperatorView({ operatorName, cluster, namespace }: IOper
if (operator) {
const defaultChannel = Operators.getDefaultChannel(operator);
if (defaultChannel) {
dispatch(actions.operators.getCSV(namespace, defaultChannel.currentCSV));
dispatch(actions.operators.getCSV(cluster, namespace, defaultChannel.currentCSV));
}
}
}, [dispatch, operator, namespace]);
}, [dispatch, operator, cluster, namespace]);

const redirect = () => dispatch(push(app.operators.new(cluster, namespace, operatorName)));

Expand Down

0 comments on commit edd06a0

Please sign in to comment.