Skip to content

Commit 24ba784

Browse files
[Feat.] CCE: deletion protection for cce clusters (#3318)
[Feat.] CCE: deletion protection for cce clusters Summary of the Pull Request Add enable_deletion_protection parameter to opentelekomcloud_cce_cluster_v3 resource Add enable_deletion_protection attribute to CCE cluster data sources PR Checklist Refers to: #3300 Tests added/passed. Documentation updated. Schema updated. Release notes added. Acceptance Steps Performed Resource test is skipped by default: the test framework always destroys resources after execution, which is expected to fail when deletion protection is enabled. The cluster must be deleted manually after running the test. === RUN TestAccCCEClusterV3DataSource_basic === PAUSE TestAccCCEClusterV3DataSource_basic === CONT TestAccCCEClusterV3DataSource_basic --- PASS: TestAccCCEClusterV3DataSource_basic (446.07s) PASS Process finished with the exit code 0 Reviewed-by: Muneeb H. Jan <muneebhafeezjan@gmail.com> Reviewed-by: Artem Lifshits Reviewed-by: Anton Sidelnikov
1 parent 7a0017a commit 24ba784

File tree

12 files changed

+110
-29
lines changed

12 files changed

+110
-29
lines changed

docs/data-sources/cce_cluster_v3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ All above argument parameters can be exported as attribute parameters along with
6363

6464
* `authentication_mode` - (Optional) Authentication mode of the cluster, possible values are `rbac` and `authenticating_proxy`.
6565

66+
* `enable_deletion_protection` - Whether deletion protection is enabled for the cluster.
67+
6668
* `subnet_id` - The ID of the subnet used to create the node.
6769

6870
* `highway_subnet_id` - The ID of the high speed network used to create bare metal nodes.

docs/data-sources/cce_clusters_v3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ The `clusters` block supports:
8484

8585
* `authentication_mode` - The authentication mode of the cluster, possible values are `x509` and `rbac`. Defaults to `rbac`.
8686

87+
* `enable_deletion_protection` - Whether deletion protection is enabled for the cluster.
88+
8789
* `masters` - The advanced configuration of master nodes. Structure is documented below.
8890

8991
* `security_group_id` - The security group ID of the cluster.

docs/resources/cce_cluster_v3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ The following arguments are supported:
301301

302302
* `ignore_certificate_clusters_data` - (Optional, Boolean) Skip sensitive cluster data.
303303

304+
* `enable_deletion_protection` - (Optional, Boolean, ForceNew) Enable cluster deletion protection. Only effective during cluster creation. Changing this parameter will create a new cluster resource.
305+
304306
* `custom_san` - (Optional, List) Specifies the custom san to add to certificate (array of string).
305307

306308
* `component_configurations` - (Optional, List) Specifies the kubernetes component configurations.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/jmespath/go-jmespath v0.4.0
1818
github.com/keybase/go-crypto v0.0.0-20200123153347-de78d2cb44f4
1919
github.com/mitchellh/go-homedir v1.1.0
20-
github.com/opentelekomcloud/gophertelekomcloud v0.9.6-0.20260317095946-062973d490fd
20+
github.com/opentelekomcloud/gophertelekomcloud v0.9.6-0.20260323130726-5844a1acfb29
2121
github.com/unknwon/com v1.0.1
2222
golang.org/x/crypto v0.46.0
2323
golang.org/x/sync v0.19.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
167167
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
168168
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
169169
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
170-
github.com/opentelekomcloud/gophertelekomcloud v0.9.6-0.20260317095946-062973d490fd h1:txohhyLhho4bpcV8Sbyl6NX6ZLWYk7lVjVl2/H2e1/I=
171-
github.com/opentelekomcloud/gophertelekomcloud v0.9.6-0.20260317095946-062973d490fd/go.mod h1:la8cQVYopRoEbNe2L7HlGTdLxUQOwIqHp1VHtjE/5qA=
170+
github.com/opentelekomcloud/gophertelekomcloud v0.9.6-0.20260323130726-5844a1acfb29 h1:xvC7TWnoZM5o3s6NeZkswFwpLPMksGS6XRlmMqdJmHc=
171+
github.com/opentelekomcloud/gophertelekomcloud v0.9.6-0.20260323130726-5844a1acfb29/go.mod h1:la8cQVYopRoEbNe2L7HlGTdLxUQOwIqHp1VHtjE/5qA=
172172
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
173173
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
174174
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

opentelekomcloud/acceptance/cce/resource_opentelekomcloud_cce_cluster_v3_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,58 @@ resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
833833
`, common.DataSourceSubnet, clusterName)
834834
}
835835

836+
// TestAccCCEClusterV3_deletionProtection verifies that a cluster with enable_deletion_protection enabled
837+
// cannot be deleted. After running this test, the cluster must be deleted manually:
838+
// disable deletion protection via the console first, then delete the cluster.
839+
func TestAccCCEClusterV3_deletionProtection(t *testing.T) {
840+
t.Skip("this test requires manual cluster cleanup after execution")
841+
842+
var cluster clusters.Clusters
843+
rc := common.InitResourceCheck(
844+
resourceClusterName,
845+
&cluster,
846+
getCceClusterResourceFunc,
847+
)
848+
clusterName := randClusterName()
849+
t.Parallel()
850+
851+
quotas.BookOne(t, quotas.CCEClusterQuota)
852+
853+
resource.Test(t, resource.TestCase{
854+
PreCheck: func() { common.TestAccPreCheck(t) },
855+
ProviderFactories: common.TestAccProviderFactories,
856+
Steps: []resource.TestStep{
857+
{
858+
Config: testAccCCEClusterV3DeletionProtection(clusterName),
859+
Check: resource.ComposeTestCheckFunc(
860+
rc.CheckResourceExists(),
861+
resource.TestCheckResourceAttr(resourceClusterName, "name", clusterName),
862+
resource.TestCheckResourceAttr(resourceClusterName, "status", "Available"),
863+
resource.TestCheckResourceAttr(resourceClusterName, "enable_deletion_protection", "true"),
864+
),
865+
},
866+
},
867+
})
868+
}
869+
870+
func testAccCCEClusterV3DeletionProtection(clusterName string) string {
871+
return fmt.Sprintf(`
872+
%s
873+
874+
resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
875+
name = "%s"
876+
cluster_type = "VirtualMachine"
877+
flavor_id = "cce.s1.small"
878+
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
879+
subnet_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id
880+
container_network_type = "overlay_l2"
881+
kubernetes_svc_ip_range = "10.247.0.0/16"
882+
ignore_addons = true
883+
enable_deletion_protection = true
884+
}
885+
`, common.DataSourceSubnet, clusterName)
886+
}
887+
836888
func testAccCCEClusterV3ComponentConfigJSONString(clusterName string) string {
837889
return fmt.Sprintf(`
838890
%s

opentelekomcloud/acceptance/common/quotas/quotas.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,6 @@ func (q MultipleQuotas) X(multiplier int64) MultipleQuotas {
185185
return newOne
186186
}
187187

188-
// AcquireMultipleQuotas tries to acquire all given quotas, reverting on failure
189-
// Deprecated: use BookMany in tests instead
190-
func AcquireMultipleQuotas(e []*ExpectedQuota, interval time.Duration) error {
191-
return acquireMultipleQuotas(e, interval)
192-
}
193-
194188
func acquireMultipleQuotas(e []*ExpectedQuota, interval time.Duration) error {
195189
// validate if all Count values of ExpectQuota are correct
196190
var mErr *multierror.Error

opentelekomcloud/acceptance/ecs/utils.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ func TestAccCheckComputeV2InstanceDestroy(s *terraform.State) error {
3838
}
3939

4040
func getFlavors() (map[string][]*quotas.ExpectedQuota, error) {
41-
config := common.TestAccProvider.Meta().(*cfg.Config)
41+
meta := common.TestAccProvider.Meta()
42+
if meta == nil {
43+
return nil, fmt.Errorf("provider meta is nil — ensure provider environment variables are set")
44+
}
45+
config := meta.(*cfg.Config)
4246
client, err := config.ComputeV2Client(env.OS_REGION_NAME)
4347
if err != nil {
4448
return nil, fmt.Errorf("error creating OpenTelekomCloud ComputeV2 client: %s", err)
@@ -74,7 +78,8 @@ func init() {
7478
if os.Getenv("TF_ACC") != "" { // this can be done only in acceptance
7579
qs, err := getFlavors()
7680
if err != nil {
77-
panic("failed to get server flavors")
81+
fmt.Printf("[WARN] failed to get server flavors: %s\n", err)
82+
return
7883
}
7984
flavorsQuota = qs
8085
}

opentelekomcloud/services/cce/data_source_opentelekomcloud_cce_cluster_v3.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func DataSourceCCEClusterV3() *schema.Resource {
8585
Type: schema.TypeString,
8686
Computed: true,
8787
},
88+
"enable_deletion_protection": {
89+
Type: schema.TypeBool,
90+
Computed: true,
91+
},
8892
"status": {
8993
Type: schema.TypeString,
9094
Optional: true,
@@ -197,6 +201,7 @@ func dataSourceCCEClusterV3Read(_ context.Context, d *schema.ResourceData, meta
197201
d.Set("eni_subnet_id", cluster.Spec.EniNetwork.SubnetId),
198202
d.Set("eni_subnet_cidr", cluster.Spec.EniNetwork.Cidr),
199203
d.Set("authentication_mode", cluster.Spec.Authentication.Mode),
204+
d.Set("enable_deletion_protection", cluster.Spec.DeletionProtection),
200205
d.Set("status", cluster.Status.Phase),
201206
d.Set("internal", cluster.Status.Endpoints[0].Internal),
202207
d.Set("external", cluster.Status.Endpoints[0].External),

opentelekomcloud/services/cce/data_source_opentelekomcloud_cce_clusters_v3.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func DataSourceCCEClustersV3() *schema.Resource {
113113
Type: schema.TypeString,
114114
Computed: true,
115115
},
116+
"enable_deletion_protection": {
117+
Type: schema.TypeBool,
118+
Computed: true,
119+
},
116120
"security_group_id": {
117121
Type: schema.TypeString,
118122
Computed: true,
@@ -236,24 +240,25 @@ func dataSourceCCEClustersV3Read(_ context.Context, d *schema.ResourceData, meta
236240
ids = append(ids, v.Metadata.Id)
237241

238242
cluster := map[string]interface{}{
239-
"name": v.Metadata.Name,
240-
"id": v.Metadata.Id,
241-
"status": v.Status.Phase,
242-
"flavor_id": v.Spec.Flavor,
243-
"cluster_version": v.Spec.Version,
244-
"cluster_type": v.Spec.Type,
245-
"description": v.Spec.Description,
246-
"billing_mode": v.Spec.BillingMode,
247-
"vpc_id": v.Spec.HostNetwork.VpcId,
248-
"subnet_id": v.Spec.HostNetwork.SubnetId,
249-
"container_network_cidr": v.Spec.ContainerNetwork.Cidr,
250-
"container_network_type": v.Spec.ContainerNetwork.Mode,
251-
"eni_subnet_id": v.Spec.EniNetwork.SubnetId,
252-
"eni_subnet_cidr": v.Spec.EniNetwork.Cidr,
253-
"authentication_mode": v.Spec.Authentication.Mode,
254-
"security_group_id": v.Spec.HostNetwork.SecurityGroupId,
255-
"enterprise_project_id": v.Spec.ExtendParam["enterpriseProjectId"],
256-
"service_network_cidr": v.Spec.KubernetesSvcIpRange,
243+
"name": v.Metadata.Name,
244+
"id": v.Metadata.Id,
245+
"status": v.Status.Phase,
246+
"flavor_id": v.Spec.Flavor,
247+
"cluster_version": v.Spec.Version,
248+
"cluster_type": v.Spec.Type,
249+
"description": v.Spec.Description,
250+
"billing_mode": v.Spec.BillingMode,
251+
"vpc_id": v.Spec.HostNetwork.VpcId,
252+
"subnet_id": v.Spec.HostNetwork.SubnetId,
253+
"container_network_cidr": v.Spec.ContainerNetwork.Cidr,
254+
"container_network_type": v.Spec.ContainerNetwork.Mode,
255+
"eni_subnet_id": v.Spec.EniNetwork.SubnetId,
256+
"eni_subnet_cidr": v.Spec.EniNetwork.Cidr,
257+
"authentication_mode": v.Spec.Authentication.Mode,
258+
"enable_deletion_protection": v.Spec.DeletionProtection,
259+
"security_group_id": v.Spec.HostNetwork.SecurityGroupId,
260+
"enterprise_project_id": v.Spec.ExtendParam["enterpriseProjectId"],
261+
"service_network_cidr": v.Spec.KubernetesSvcIpRange,
257262
}
258263

259264
var endpoints []map[string]interface{}

0 commit comments

Comments
 (0)