Browse Source

destroy infra + on project deletion

jusrhee 5 năm trước cách đây
mục cha
commit
c136cdb692

+ 18 - 0
dashboard/src/main/home/modals/UpdateClusterModal.tsx

@@ -30,6 +30,7 @@ export default class UpdateClusterModal extends Component<PropsType, StateType>
   handleDelete = () => {
     let { currentProject, currentCluster } = this.context;
     this.setState({ status: 'loading' });
+
     api.deleteCluster('<token>', {}, { 
       project_id: currentProject.id,
       cluster_id: currentCluster.id,
@@ -38,6 +39,23 @@ export default class UpdateClusterModal extends Component<PropsType, StateType>
         this.setState({ status: 'error' });
         console.log(err)
       } else {
+
+        // Handle destroying infra we've provisioned
+        if (currentCluster.infra_id) {
+          console.log('destroying provisioned infra...');
+          api.destroyCluster('<token>', {}, { 
+            project_id: currentProject.id,
+            infra_id: currentCluster.infra_id,
+          }, (err: any, res: any) => {
+            if (err) {
+              this.setState({ status: 'error' });
+              console.log(err)
+            } else {
+              console.log('destroyed provisioned infra.');
+            }
+          });
+        }
+
         this.props.setRefreshClusters(true);
         this.setState({ status: 'successful', showDeleteOverlay: false });
         this.context.setCurrentModal(null, null);

+ 27 - 0
dashboard/src/main/home/modals/UpdateProjectModal.tsx

@@ -5,6 +5,7 @@ import gradient from '../../../assets/gradient.jpg';
 
 import api from '../../../shared/api';
 import { Context } from '../../../shared/Context';
+import { ClusterType } from '../../../shared/types';
 
 import SaveButton from '../../../components/SaveButton';
 import InputRow from '../../../components/values-form/InputRow';
@@ -57,6 +58,32 @@ export default class UpdateProjectModal extends Component<PropsType, StateType>
         this.setState({ status: 'successful', showDeleteOverlay: false });
       }
     });
+
+    // Loop through and delete infra of all clusters we've provisioned
+    api.getClusters('<token>', {}, { id: currentProject.id }, (err: any, res: any) => {
+      if (err) {
+        console.log(err);
+      } else {
+        res.data.forEach((cluster: ClusterType) => {
+
+          // Handle destroying infra we've provisioned
+          if (cluster.infra_id) {
+            console.log('destroying provisioned infra...', cluster.infra_id);
+            api.destroyCluster('<token>', {}, { 
+              project_id: currentProject.id,
+              infra_id: cluster.infra_id,
+            }, (err: any, res: any) => {
+              if (err) {
+                this.setState({ status: 'error' });
+                console.log(err)
+              } else {
+                console.log('destroyed provisioned infra:', cluster.infra_id);
+              }
+            });
+          }
+        });
+      }
+    });
   }
 
   render() {

+ 1 - 0
dashboard/src/shared/types.tsx

@@ -3,6 +3,7 @@ export interface ClusterType {
   name: string,
   server: string,
   service_account_id: number
+  infra_id?: number
 }
 
 export interface ChartType {