diff --git a/src/actions/catalog.ts b/src/actions/catalog.ts index 7cb4dc7affb..3e09c2e8f10 100644 --- a/src/actions/catalog.ts +++ b/src/actions/catalog.ts @@ -74,6 +74,12 @@ export function provision( }; } +export function deprovision(instance: IServiceInstance) { + return async (dispatch: Dispatch) => { + return ServiceCatalog.deprovisionInstance(instance); + }; +} + export function sync(broker: IServiceBroker) { return async (dispatch: Dispatch) => { return ServiceCatalog.syncBroker(broker); diff --git a/src/components/BrokerView/index.tsx b/src/components/BrokerView/index.tsx index af8c8edce28..101371b2bec 100644 --- a/src/components/BrokerView/index.tsx +++ b/src/components/BrokerView/index.tsx @@ -9,6 +9,7 @@ import { IServicePlan, } from "../../shared/ServiceCatalog"; import { Card, CardContainer } from "../Card"; +import DeprovisionButton from "../DeprovisionButton"; import SyncButton from "../SyncButton"; export interface IBrokerViewProps { @@ -19,6 +20,7 @@ export interface IBrokerViewProps { instances: IServiceInstance[]; plans: IServicePlan[]; sync: (broker: IServiceBroker) => Promise; + deprovision: (instance: IServiceInstance) => Promise; } export class BrokerView extends React.PureComponent { @@ -27,7 +29,7 @@ export class BrokerView extends React.PureComponent { } public render() { - const { bindings, broker, instances } = this.props; + const { bindings, broker, instances, deprovision } = this.props; return (
@@ -76,6 +78,9 @@ export class BrokerView extends React.PureComponent { {message} + + + ); })} diff --git a/src/components/DeprovisionButton/index.tsx b/src/components/DeprovisionButton/index.tsx new file mode 100644 index 00000000000..7a20d8d6706 --- /dev/null +++ b/src/components/DeprovisionButton/index.tsx @@ -0,0 +1,50 @@ +import * as React from "react"; +import { IServiceInstance } from "../../shared/ServiceCatalog"; + +interface IDeprovisionButtonProps { + instance: IServiceInstance; + deprovision: (instance: IServiceInstance) => Promise<{}>; +} + +interface IDeprovisionButtonState { + error: string | undefined; + instance: IServiceInstance | undefined; + isDeprovisioning: boolean; +} + +class DeprovisionButton extends React.Component { + public state: IDeprovisionButtonState = { + error: undefined, + instance: this.props.instance, + isDeprovisioning: false, + }; + + public handleDeprovision = async () => { + const { deprovision, instance } = this.props; + this.setState({ isDeprovisioning: true }); + + try { + await deprovision(instance); + this.setState({ isDeprovisioning: false }); + } catch (err) { + this.setState({ isDeprovisioning: false, error: err.toString() }); + } + }; + + public render() { + return ( +
+ {this.state.isDeprovisioning &&
Deprovisioning...
} + +
+ ); + } +} + +export default DeprovisionButton; diff --git a/src/containers/BrokerView.ts b/src/containers/BrokerView.ts index ed90d72ac2b..f1e867b87f6 100644 --- a/src/containers/BrokerView.ts +++ b/src/containers/BrokerView.ts @@ -3,7 +3,7 @@ import { Dispatch } from "redux"; import actions from "../actions"; import { BrokerView } from "../components/BrokerView"; -import { IServiceBroker } from "../shared/ServiceCatalog"; +import { IServiceBroker, IServiceInstance } from "../shared/ServiceCatalog"; import { IStoreState } from "../shared/types"; interface IRouteProps { @@ -43,6 +43,9 @@ function mapStateToProps({ catalog }: IStoreState, { match: { params } }: IRoute function mapDispatchToProps(dispatch: Dispatch) { return { + deprovision: async (instance: IServiceInstance) => { + await dispatch(actions.catalog.deprovision(instance)); + }, getCatalog: async () => { dispatch(actions.catalog.getCatalog()); }, diff --git a/src/shared/ServiceCatalog.ts b/src/shared/ServiceCatalog.ts index 3f47fbea489..5c3459e2e78 100644 --- a/src/shared/ServiceCatalog.ts +++ b/src/shared/ServiceCatalog.ts @@ -109,6 +109,16 @@ export class ServiceCatalog { return data; } + public static async deprovisionInstance(instance: IServiceInstance) { + const { data } = await axios.delete("/api/kube" + instance.metadata.selfLink); + + if (data.status === "Failure") { + throw new Error(data.message); + } + + return data; + } + public static async syncBroker(broker: IServiceBroker) { const { data } = await axios.patch( urls.api.clusterservicebrokers.sync(broker),