Skip to content

Commit

Permalink
CCE: Custom cluster deletion (#2261)
Browse files Browse the repository at this point in the history
CCE: Custom cluster deletion

Summary of the Pull Request
Add custom cluster deletion for resource/opentelekomcloud_cce_cluster_v3.
PR Checklist

 Refers to: #2254
 Tests passed.
 Documentation updated.
 Schema updated.
 Release notes added.

Acceptance Steps Performed
=== RUN   TestAccCCEClusterV3_basic
=== PAUSE TestAccCCEClusterV3_basic
=== CONT  TestAccCCEClusterV3_basic
--- PASS: TestAccCCEClusterV3_basic (508.11s)
PASS

Process finished with the exit code 0

=== RUN   TestAccCCEClusterV3_turbo_basic
=== PAUSE TestAccCCEClusterV3_turbo_basic
=== CONT  TestAccCCEClusterV3_turbo_basic
--- PASS: TestAccCCEClusterV3_turbo_basic (476.45s)
PASS

Process finished with the exit code 0

Reviewed-by: Anton Sidelnikov
Reviewed-by: Rodion Gyrbu <fpsoff@outlook.com>
  • Loading branch information
artem-lifshits committed Aug 10, 2023
1 parent 56c0290 commit c4c5867
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 4 deletions.
27 changes: 27 additions & 0 deletions docs/resources/cce_cluster_v3.md
Expand Up @@ -214,6 +214,33 @@ The following arguments are supported:
This mode supports incremental updates and can keep connections uninterrupted during service updates.
It is suitable for large-sized clusters.

* `delete_evs` - (Optional) Specified whether to delete associated EVS disks when deleting the CCE cluster.
valid values are **true**, **try** and **false**. Default is **false**.

* `delete_obs` - (Optional) Specified whether to delete associated OBS buckets when deleting the CCE cluster.
valid values are **true**, **try** and **false**. Default is **false**.

* `delete_sfs` - (Optional) Specified whether to delete associated SFS file systems when deleting the CCE
cluster. valid values are **true**, **try** and **false**. Default is **false**.

* `delete_efs` - (Optional) Specified whether to unbind associated SFS Turbo file systems when deleting the CCE
cluster. valid values are **true**, **try** and **false**. Default is **false**.

* `delete_eni` - (Optional) Specified whether to delete ENI ports when deleting the CCE
cluster. valid values are **true**, **try** and **false**. Default is **false**.

* `delete_net` - (Optional) Specified whether to delete cluster Service/ingress-related resources, such as ELB when deleting the CCE
cluster. valid values are **true**, **try** and **false**. Default is **false**.

* `delete_all_storage` - (Optional) Specified whether to delete all associated storage resources when deleting the CCE
cluster. valid values are **true**, **try** and **false**. Default is **false**.

* `delete_all_network` - (Optional) Specified whether to delete all associated network resources when deleting the CCE
cluster. valid values are **true**, **try** and **false**. Default is **false**.

-> Note: Cluster custom deletion info and properties can be checked here:
[Deleting a Specified Cluster.](https://docs.otc.t-systems.com/cloud-container-engine/api-ref/apis/cluster_management/deleting_a_specified_cluster.html)

## Attributes Reference

All above argument parameters can be exported as attribute parameters along with attribute reference.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -14,7 +14,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4
github.com/mitchellh/go-homedir v1.1.0
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810080331-8e8065905220
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810152808-2b43da3080c2
github.com/unknwon/com v1.0.1
golang.org/x/crypto v0.1.0
golang.org/x/sync v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -154,8 +154,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810080331-8e8065905220 h1:VYLL/Jo2QGvtMLUIe7weHINUleQC0H4FUvrOUSy1aSw=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810080331-8e8065905220/go.mod h1:9Deb3q2gJvq5dExV+aX+iO+G+mD9Zr9uFt+YY9ONmq0=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810152808-2b43da3080c2 h1:zII8WprAPQiHqE6ZU7w8fNl05JLUvxJ4ZpQjsK7SRXU=
github.com/opentelekomcloud/gophertelekomcloud v0.7.1-0.20230810152808-2b43da3080c2/go.mod h1:9Deb3q2gJvq5dExV+aX+iO+G+mD9Zr9uFt+YY9ONmq0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
Expand Up @@ -355,6 +355,8 @@ resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
kubernetes_svc_ip_range = "10.247.0.0/16"
ignore_addons = true
kube_proxy_mode = "ipvs"
delete_all_storage = "true"
delete_all_network = "true"
}
`, common.DataSourceSubnet, clusterName)
}
Expand Down
Expand Up @@ -303,10 +303,39 @@ func ResourceCCEClusterV3() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"delete_efs": associateDeleteSchema,
"delete_eni": associateDeleteSchema,
"delete_evs": associateDeleteSchema,
"delete_net": associateDeleteSchema,
"delete_obs": associateDeleteSchema,
"delete_sfs": associateDeleteSchema,
"delete_all_storage": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"true", "try", "false",
}, true),
},
"delete_all_network": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"true", "try", "false",
}, true),
},
},
}
}

var associateDeleteSchema *schema.Schema = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
"true", "try", "false",
}, true),
ConflictsWith: []string{"delete_all_storage", "delete_all_network"},
}

func resourceClusterLabelsV3(d *schema.ResourceData) map[string]string {
m := make(map[string]string)
for key, val := range d.Get("labels").(map[string]interface{}) {
Expand Down Expand Up @@ -661,7 +690,33 @@ func resourceCCEClusterV3Delete(ctx context.Context, d *schema.ResourceData, met
return fmterr.Errorf(cceClientError, err)
}

err = clusters.Delete(client, d.Id()).ExtractErr()
deleteOpts := clusters.DeleteOpts{}
var deleteAll bool
if v, ok := d.GetOk("delete_all_storage"); ok && v.(string) != "false" {
deleteOpt := d.Get("delete_all_storage").(string)
deleteOpts.DeleteEfs = deleteOpt
deleteOpts.DeleteEvs = deleteOpt
deleteOpts.DeleteObs = deleteOpt
deleteOpts.DeleteSfs = deleteOpt
deleteAll = true
}
if v, ok := d.GetOk("delete_all_network"); ok && v.(string) != "false" {
deleteOpt := d.Get("delete_all_network").(string)
deleteOpts.DeleteENI = deleteOpt
deleteOpts.DeleteNet = deleteOpt
deleteAll = true
}

if !deleteAll {
deleteOpts.DeleteEfs = d.Get("delete_efs").(string)
deleteOpts.DeleteENI = d.Get("delete_eni").(string)
deleteOpts.DeleteEvs = d.Get("delete_evs").(string)
deleteOpts.DeleteNet = d.Get("delete_net").(string)
deleteOpts.DeleteObs = d.Get("delete_obs").(string)
deleteOpts.DeleteSfs = d.Get("delete_sfs").(string)
}

err = clusters.DeleteWithOpts(client, d.Id(), deleteOpts)
if err != nil {
return fmterr.Errorf("error deleting opentelekomcloud CCE Cluster: %w", err)
}
Expand Down
@@ -0,0 +1,4 @@
---
enhancements:
- |
**[CCE]** Add custom deletion for ``resource/opentelekomcloud_cce_cluster_v3`` (`#2261 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/2261>`_)

0 comments on commit c4c5867

Please sign in to comment.