Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1942 app repos use cluster #1997

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions dashboard/src/actions/catalog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ beforeEach(() => {
config: {
kubeappsCluster: testArgs.kubeappsCluster,
},
clusters: {
currentCluster: testArgs.kubeappsCluster,
},
});

ServiceInstance.create = jest.fn().mockImplementationOnce(() => {
Expand Down Expand Up @@ -149,6 +152,7 @@ describe("provision", () => {

expect(store.getActions().length).toBe(0);
expect(ServiceInstance.create).toHaveBeenCalledWith(
testArgs.kubeappsCluster,
testArgs.releaseName,
testArgs.namespace,
testArgs.className,
Expand Down Expand Up @@ -197,6 +201,7 @@ describe("provision", () => {
);
await store.dispatch(cmd);
expect(ServiceInstance.create).toHaveBeenCalledWith(
testArgs.kubeappsCluster,
testArgs.releaseName,
testArgs.namespace,
testArgs.className,
Expand All @@ -214,7 +219,10 @@ describe("deprovision", () => {
expect(res).toBe(true);

expect(store.getActions().length).toBe(0);
expect(ServiceCatalog.deprovisionInstance).toHaveBeenCalledWith(serviceInstance);
expect(ServiceCatalog.deprovisionInstance).toHaveBeenCalledWith(
testArgs.kubeappsCluster,
serviceInstance,
);
});

it("dispatches errorCatalog if error", async () => {
Expand Down Expand Up @@ -248,6 +256,7 @@ describe("addBinding", () => {
expect(ServiceBinding.create).toHaveBeenCalledWith(
testArgs.bindingName,
testArgs.instanceName,
testArgs.kubeappsCluster,
testArgs.namespace,
testArgs.params,
);
Expand Down Expand Up @@ -297,6 +306,7 @@ describe("addBinding", () => {
expect(ServiceBinding.create).toHaveBeenCalledWith(
testArgs.bindingName,
testArgs.instanceName,
testArgs.kubeappsCluster,
testArgs.namespace,
expectedParams,
);
Expand All @@ -311,7 +321,11 @@ describe("removeBinding", () => {
expect(res).toBe(true);

expect(store.getActions().length).toBe(0);
expect(ServiceBinding.delete).toHaveBeenCalledWith(testArgs.bindingName, testArgs.namespace);
expect(ServiceBinding.delete).toHaveBeenCalledWith(
testArgs.kubeappsCluster,
testArgs.bindingName,
testArgs.namespace,
);
});

it("dispatches errorCatalog if error", async () => {
Expand Down Expand Up @@ -480,7 +494,7 @@ describe("getInstances", () => {

await store.dispatch(provisionCMD);
expect(store.getActions()).toEqual(expectedActions);
expect(ServiceInstance.list).toHaveBeenCalledWith(testArgs.namespace);
expect(ServiceInstance.list).toHaveBeenCalledWith(testArgs.kubeappsCluster, testArgs.namespace);
});

it("dispatches requestInstances and errorCatalog if error", async () => {
Expand Down
76 changes: 58 additions & 18 deletions dashboard/src/actions/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,20 @@ export function provision(
planName: string,
parameters: {},
): ThunkAction<Promise<boolean>, IStoreState, null, ServiceCatalogAction> {
return async dispatch => {
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
try {
const filteredParams = helpers.object.removeEmptyFields(parameters);
await ServiceInstance.create(releaseName, namespace, className, planName, filteredParams);
await ServiceInstance.create(
currentCluster,
releaseName,
namespace,
className,
planName,
filteredParams,
);
return true;
} catch (e) {
dispatch(errorCatalog(e, "create"));
Expand All @@ -86,10 +96,19 @@ export function addBinding(
namespace: string,
parameters: {},
): ThunkAction<Promise<boolean>, IStoreState, null, ServiceCatalogAction> {
return async dispatch => {
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
try {
const filteredParams = helpers.object.removeEmptyFields(parameters);
await ServiceBinding.create(bindingName, instanceName, namespace, filteredParams);
await ServiceBinding.create(
bindingName,
instanceName,
currentCluster,
namespace,
filteredParams,
);
return true;
} catch (e) {
dispatch(errorCatalog(e, "create"));
Expand All @@ -102,9 +121,12 @@ export function removeBinding(
name: string,
namespace: string,
): ThunkAction<Promise<boolean>, IStoreState, null, ServiceCatalogAction> {
return async dispatch => {
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
try {
await ServiceBinding.delete(name, namespace);
await ServiceBinding.delete(currentCluster, name, namespace);
return true;
} catch (e) {
dispatch(errorCatalog(e, "delete"));
Expand All @@ -116,9 +138,12 @@ export function removeBinding(
export function deprovision(
instance: IServiceInstance,
): ThunkAction<Promise<boolean>, IStoreState, null, ServiceCatalogAction> {
return async dispatch => {
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
try {
await ServiceCatalog.deprovisionInstance(instance);
await ServiceCatalog.deprovisionInstance(currentCluster, instance);
return true;
} catch (e) {
dispatch(errorCatalog(e, "deprovision"));
Expand Down Expand Up @@ -163,10 +188,13 @@ export function getBindings(
}

export function getBrokers(): ThunkAction<Promise<void>, IStoreState, null, ServiceCatalogAction> {
return async dispatch => {
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
dispatch(requestBrokers());
try {
const brokers = await ServiceCatalog.getServiceBrokers();
const brokers = await ServiceCatalog.getServiceBrokers(currentCluster);
dispatch(receiveBrokers(brokers));
} catch (e) {
dispatch(errorCatalog(e, "fetch"));
Expand All @@ -175,10 +203,13 @@ export function getBrokers(): ThunkAction<Promise<void>, IStoreState, null, Serv
}

export function getClasses(): ThunkAction<Promise<void>, IStoreState, null, ServiceCatalogAction> {
return async dispatch => {
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
dispatch(requestClasses());
try {
const classes = await ServiceCatalog.getServiceClasses();
const classes = await ServiceCatalog.getServiceClasses(currentCluster);
dispatch(receiveClasses(classes));
} catch (e) {
dispatch(errorCatalog(e, "fetch"));
Expand All @@ -189,13 +220,16 @@ export function getClasses(): ThunkAction<Promise<void>, IStoreState, null, Serv
export function getInstances(
ns?: string,
): ThunkAction<Promise<void>, IStoreState, null, ServiceCatalogAction> {
return async dispatch => {
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
if (ns && ns === definedNamespaces.all) {
ns = undefined;
}
dispatch(requestInstances());
try {
const instances = await ServiceInstance.list(ns);
const instances = await ServiceInstance.list(currentCluster, ns);
dispatch(receiveInstances(instances));
} catch (e) {
dispatch(errorCatalog(e, "fetch"));
Expand All @@ -204,10 +238,13 @@ export function getInstances(
}

export function getPlans(): ThunkAction<Promise<void>, IStoreState, null, ServiceCatalogAction> {
return async dispatch => {
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
dispatch(requestPlans());
try {
const plans = await ServiceCatalog.getServicePlans();
const plans = await ServiceCatalog.getServicePlans(currentCluster);
dispatch(receivePlans(plans));
} catch (e) {
dispatch(errorCatalog(e, "fetch"));
Expand All @@ -221,8 +258,11 @@ export function checkCatalogInstalled(): ThunkAction<
null,
ServiceCatalogAction
> {
return async dispatch => {
const isServiceCatalogInstalled = await ServiceCatalog.isCatalogInstalled();
return async (dispatch, getState) => {
const {
clusters: { currentCluster },
} = getState();
const isServiceCatalogInstalled = await ServiceCatalog.isCatalogInstalled(currentCluster);
isServiceCatalogInstalled ? dispatch(installed()) : dispatch(notInstalled());
return isServiceCatalogInstalled;
};
Expand Down
12 changes: 10 additions & 2 deletions dashboard/src/actions/repos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ describe("resyncAllRepos", () => {
);

expect(appRepoGetMock).toHaveBeenCalledTimes(2);
expect(appRepoGetMock.mock.calls[0]).toEqual(["foo", "namespace-1"]);
expect(appRepoGetMock.mock.calls[1]).toEqual(["bar", "namespace-2"]);
expect(appRepoGetMock.mock.calls[0]).toEqual(["default", "foo", "namespace-1"]);
expect(appRepoGetMock.mock.calls[1]).toEqual(["default", "bar", "namespace-2"]);
});
});

Expand Down Expand Up @@ -349,6 +349,7 @@ describe("installRepo", () => {
it("calls AppRepository create including a auth struct", async () => {
await store.dispatch(installRepoCMDAuth);
expect(AppRepository.create).toHaveBeenCalledWith(
"default",
"my-repo",
"my-namespace",
"http://foo.bar",
Expand Down Expand Up @@ -379,6 +380,7 @@ describe("installRepo", () => {
it("calls AppRepository create including a auth struct", async () => {
await store.dispatch(installRepoCMDAuth);
expect(AppRepository.create).toHaveBeenCalledWith(
"default",
"my-repo",
"my-namespace",
"http://foo.bar",
Expand Down Expand Up @@ -409,6 +411,7 @@ describe("installRepo", () => {
);

expect(AppRepository.create).toHaveBeenCalledWith(
"default",
"my-repo",
"my-namespace",
"http://foo.bar",
Expand Down Expand Up @@ -446,6 +449,7 @@ describe("installRepo", () => {
it("calls AppRepository create without a auth struct", async () => {
await store.dispatch(installRepoCMD);
expect(AppRepository.create).toHaveBeenCalledWith(
"default",
"my-repo",
"my-namespace",
"http://foo.bar",
Expand Down Expand Up @@ -511,6 +515,7 @@ describe("installRepo", () => {
);

expect(AppRepository.create).toHaveBeenCalledWith(
"default",
"my-repo",
"kubeapps-namespace",
"http://foo.bar",
Expand All @@ -527,6 +532,7 @@ describe("installRepo", () => {
);

expect(AppRepository.create).toHaveBeenCalledWith(
"default",
"my-repo",
"kubeapps-namespace",
"http://foo.bar",
Expand Down Expand Up @@ -576,6 +582,7 @@ describe("updateRepo", () => {
);
expect(store.getActions()).toEqual(expectedActions);
expect(AppRepository.update).toHaveBeenCalledWith(
"default",
"my-repo",
"my-namespace",
"http://foo.bar",
Expand Down Expand Up @@ -623,6 +630,7 @@ describe("updateRepo", () => {
);
expect(store.getActions()).toEqual(expectedActions);
expect(AppRepository.update).toHaveBeenCalledWith(
"default",
"my-repo",
"my-namespace",
"http://foo.bar",
Expand Down
Loading