@@ -729,3 +729,60 @@ func (o *oracleOps) GetDeviceID(vol interface{}) (string, error) {
729729 return "" , fmt .Errorf ("invalid type: %v given to GetDeviceID" , vol )
730730
731731}
732+
733+ func (o * oracleOps ) DeleteInstance (instanceID string , zone string , timeout time.Duration ) error {
734+
735+ pools , err := o .containerEngine .ListNodePools (context .Background (),
736+ containerengine.ListNodePoolsRequest {CompartmentId : & o .compartmentID , ClusterId : & o .clusterID })
737+ if err != nil {
738+ return err
739+ }
740+
741+ var nodePoolID * string
742+
743+ switch len (pools .Items ) {
744+ case 0 :
745+ return errors .New ("No node pool found " )
746+ case 1 :
747+ nodePoolID = pools .Items [0 ].Id
748+ default :
749+ for _ , pool := range pools .Items {
750+ poolResp , err := o .containerEngine .GetNodePool (context .Background (), containerengine.GetNodePoolRequest {NodePoolId : pool .Id })
751+ if err != nil {
752+ return err
753+ }
754+ if ok := nodePoolContainsNode (poolResp .Nodes , instanceID ); ok {
755+ logrus .Println ("Instance is in pool " , * pool .Name )
756+ nodePoolID = pool .Id
757+ break
758+ }
759+ }
760+ }
761+
762+ nodeDeleteReq := containerengine.DeleteNodeRequest {
763+ NodePoolId : nodePoolID ,
764+ NodeId : & instanceID ,
765+ IsDecrementSize : common .Bool (false ),
766+ }
767+ nodeDeleteResp , err := o .containerEngine .DeleteNode (context .Background (), nodeDeleteReq )
768+
769+ if err != nil {
770+ return err
771+ }
772+
773+ err = o .waitTillWorkStatusIsSucceeded (nodeDeleteResp .OpcRequestId , nodeDeleteResp .OpcWorkRequestId , timeout )
774+ if err != nil {
775+ return err
776+ }
777+
778+ return nil
779+ }
780+
781+ func nodePoolContainsNode (s []containerengine.Node , e string ) bool {
782+ for _ , v := range s {
783+ if * v .Id == e {
784+ return true
785+ }
786+ }
787+ return false
788+ }
0 commit comments