Skip to content

Commit f524636

Browse files
author
Esteban G
committed
adding optimizations
1 parent eb28f9d commit f524636

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

docs/Table of Contents.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ This lists all of the available OCI resources and/or data sources.
4949
* [Volume Group Backups](https://github.com/oracle/terraform-provider-oci/tree/master/docs/core/volume_group_backups.md)
5050
* [Volume Groups](https://github.com/oracle/terraform-provider-oci/tree/master/docs/core/volume_groups.md)
5151
* [Volumes](https://github.com/oracle/terraform-provider-oci/tree/master/docs/core/volumes.md)
52+
* **Container Engine**
53+
* [Clusters](https://github.com/oracle/terraform-provider-oci/tree/master/docs/containerengine/clusters.md)
54+
* [Node Pools](https://github.com/oracle/terraform-provider-oci/tree/master/docs/containerengine/node_pools.md)
5255
* **Database**
5356
* [Databases](https://github.com/oracle/terraform-provider-oci/tree/master/docs/database/databases.md)
5457
* [DB Homes](https://github.com/oracle/terraform-provider-oci/tree/master/docs/database/db_homes.md)

provider/containerengine_cluster_resource.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
var (
22-
clusterOperationMaxTime = 20 * time.Minute
22+
clusterOperationMaxTime = 60 * time.Minute
2323
)
2424

2525
func ClusterResource() *schema.Resource {
@@ -324,7 +324,7 @@ func containerEngineWorkRequestShouldRetryFunc(timeout time.Duration) func(respo
324324
}
325325
}
326326

327-
//containerEngineWaitForWorkRequest custom logic to extract clusterId from a workRequest
327+
//containerEngineWaitForWorkRequest custom logic to extract an identifier from a workRequest
328328
func containerEngineWaitForWorkRequest(wId *string, entityType string, action oci_containerengine.WorkRequestResourceActionTypeEnum,
329329
timeout time.Duration, disableFoundRetries bool, client *oci_containerengine.ContainerEngineClient) (*string, error) {
330330
retryPolicy := getRetryPolicy(disableFoundRetries, "containerengine")
@@ -341,17 +341,20 @@ func containerEngineWaitForWorkRequest(wId *string, entityType string, action oc
341341
return nil, err
342342
}
343343

344+
var identifier *string
344345
//The work request response contains an array of objects that finished the operation
345346
for _, res := range response.Resources {
346-
if strings.Contains(strings.ToLower(*res.EntityType), entityType) &&
347-
res.ActionType == action {
348-
return res.Identifier, nil
347+
if strings.Contains(strings.ToLower(*res.EntityType), entityType) {
348+
identifier = res.Identifier
349+
if res.ActionType == action {
350+
return res.Identifier, nil
351+
}
349352
}
350353
}
351354

352355
//Otherwise the operation ended unsucessfully
353356
errorMessage, _ := getErrorFromWorkRequest(wId, response.CompartmentId, client, disableFoundRetries)
354-
return nil, fmt.Errorf("work request did not succeed, workId: %s, entity: %s, action: %s. Message: %s", *wId, entityType, action, errorMessage)
357+
return identifier, fmt.Errorf("work request did not succeed, workId: %s, entity: %s, action: %s. Message: %s", *wId, entityType, action, errorMessage)
355358
}
356359

357360
func (s *ClusterResourceCrud) Create() error {
@@ -394,7 +397,25 @@ func (s *ClusterResourceCrud) Create() error {
394397
//Wait until it finishes
395398
clusterID, err := containerEngineWaitForWorkRequest(workId, "cluster",
396399
oci_containerengine.WorkRequestResourceActionTypeCreated, clusterOperationMaxTime, s.DisableNotFoundRetries, s.Client)
400+
397401
if err != nil {
402+
if clusterID != nil {
403+
//Try to clean up
404+
delReq := oci_containerengine.DeleteClusterRequest{}
405+
delReq.ClusterId = clusterID
406+
delReq.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "containerengine")
407+
408+
//Issue the delete delReq
409+
delRes, delErr := s.Client.DeleteCluster(context.Background(), delReq)
410+
if delErr != nil {
411+
return err
412+
}
413+
delWorkRequest := delRes.OpcWorkRequestId
414+
415+
//Wait until request finishes
416+
_, _ = containerEngineWaitForWorkRequest(delWorkRequest, "cluster",
417+
oci_containerengine.WorkRequestResourceActionTypeDeleted, clusterOperationMaxTime, s.DisableNotFoundRetries, s.Client)
418+
}
398419
return err
399420
}
400421

provider/containerengine_node_pool_resource.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
oci_containerengine "github.com/oracle/oci-go-sdk/containerengine"
1515
)
1616

17-
var nodePoolOperationMaxTime = 5 * time.Minute
17+
var nodePoolOperationMaxTime = 20 * time.Minute
1818

1919
func NodePoolResource() *schema.Resource {
2020
return &schema.Resource{
@@ -304,6 +304,24 @@ func (s *NodePoolResourceCrud) Create() error {
304304
oci_containerengine.WorkRequestResourceActionTypeCreated, nodePoolOperationMaxTime, s.DisableNotFoundRetries,
305305
s.Client)
306306
if err != nil {
307+
if nodePoolID != nil {
308+
//Try to clean up
309+
delReq := oci_containerengine.DeleteNodePoolRequest{}
310+
delReq.NodePoolId = nodePoolID
311+
delReq.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "containerengine")
312+
313+
//Issues delete delRequest
314+
delRes, delErr := s.Client.DeleteNodePool(context.Background(), delReq)
315+
if delErr != nil {
316+
return err
317+
}
318+
delWorkRequest := delRes.OpcWorkRequestId
319+
320+
//Wait until delRequest finishes
321+
_, _ = containerEngineWaitForWorkRequest(delWorkRequest, "nodepool",
322+
oci_containerengine.WorkRequestResourceActionTypeDeleted,
323+
nodePoolOperationMaxTime, s.DisableNotFoundRetries, s.Client)
324+
}
307325
return err
308326
}
309327

0 commit comments

Comments
 (0)