Skip to content

feat(tke): [118298202] tencentcloud_kubernetes_cluster support cdc_id and pre_start_user_script parameter #2835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/2835.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
resource/tencentcloud_kubernetes_cluster: support `cdc_id` and `pre_start_user_script` parameter
datasource/tencentcloud_kubernetes_clusters: support `cdc_id` parameter
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.955
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.912
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.1001
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.1008
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.947
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.857
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tsf v1.0.674
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.912 h1:XGOKd5u
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo v1.0.912/go.mod h1:iqTDU0pVTQ8RCeMJPk/PAWl9HeI1DFMd1h07yMH7RGU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/thpc v1.0.998 h1:f4/n0dVKQTD06xJ84B5asHViNJHrZmGojdAWEPIsITM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/thpc v1.0.998/go.mod h1:fyi/HUwCwVe2NCCCjz8k/C5GwPu3QazCZO+OBJ3MhLk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.1001 h1:qj+pw5MJFuOvA+a+yAA2JR8B4TmfX5H5D8jy3L0YKH0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.1001/go.mod h1:FVJUGrfLPiJWiKrH+62h38Iyo9mA2O1wuaPLMlbeDBI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.1008 h1:Cz7JSuS2zxIBzAuZ2bKk3EmrZ1QgS2QAHmCDTDPWBz0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.1008/go.mod h1:71PkDdVPT2Pd8yiuX6QFUDReTji39R/03dg1JwcjHWo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.947 h1:iZfuU8S86kfqFsAVT/LUApP8L5cpT90hl2wSKiUDVvw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/trocket v1.0.947/go.mod h1:eAgJ+XUEhffMq79zjpgHoR3PBVcciSg+LuPDC8hLWsE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tse v1.0.857 h1:TkJnvSeRSXsRCwOwcwXSvruSK9s/kw8LC3FLeccw+A0=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions tencentcloud/services/tke/resource_tc_kubernetes_cluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 30 additions & 2 deletions tencentcloud/services/tke/resource_tc_kubernetes_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,18 +767,46 @@ resource "tencentcloud_kubernetes_cluster" "managed_cluster" {

event_persistence {
enabled = true
log_set_id = "" # optional
log_set_id = "" # optional
topic_id = "" # optional
}

cluster_audit {
enabled = true
log_set_id = "" # optional
log_set_id = "" # optional
topic_id = "" # optional
}
}
```

Create a CDC scenario cluster
```
resource "tencentcloud_kubernetes_cluster" "cdc_cluster" {
cdc_id = "cluster-xxxxx"
vpc_id = "vpc-xxxxx"
cluster_cidr = "192.168.0.0/16"
cluster_max_pod_num = 64
cluster_name = "test-cdc"
cluster_desc = "test cluster desc"
cluster_max_service_num = 1024
cluster_version = "1.30.0"

cluster_os = "tlinux3.1x86_64"
cluster_level = "L20"
cluster_deploy_type = "INDEPENDENT_CLUSTER"

container_runtime = "containerd"
runtime_version = "1.6.9"
pre_start_user_script = "aXB0YWJsZXMgLUEgSU5QVVQgLXAgdGNwIC1zIDE2OS4yNTQuMC4wLzE5IC0tdGNwLWZsYWdzIFNZTixSU1QgU1lOIC1qIFRDUE1TUyAtLXNldC1tc3MgMTE2MAppcHRhYmxlcyAtQSBPVVRQVVQgLXAgdGNwIC1kIDE2OS4yNTQuMC4wLzE5IC0tdGNwLWZsYWdzIFNZTixSU1QgU1lOIC1qIFRDUE1TUyAtLXNldC1tc3MgMTE2MAoKZWNobyAnCmlwdGFibGVzIC1BIElOUFVUIC1wIHRjcCAtcyAxNjkuMjU0LjAuMC8xOSAtLXRjcC1mbGFncyBTWU4sUlNUIFNZTiAtaiBUQ1BNU1MgLS1zZXQtbXNzIDExNjAKaXB0YWJsZXMgLUEgT1VUUFVUIC1wIHRjcCAtZCAxNjkuMjU0LjAuMC8xOSAtLXRjcC1mbGFncyBTWU4sUlNUIFNZTiAtaiBUQ1BNU1MgLS1zZXQtbXNzIDExNjAKJyA+PiAvZXRjL3JjLmQvcmMubG9jYWw="
exist_instance {
node_role = "MASTER_ETCD"
instances_para {
instance_ids = ["ins-eeijdk16", "ins-84ku5rba", "ins-8oa3im2s"]
}
}
}
```

Import

tke cluster can be imported, e.g.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,34 +149,39 @@ func resourceTencentCloudKubernetesClusterCreatePostFillRequest0(ctx context.Con
Master: make([]tke.InstanceAdvancedSettings, 0),
Work: make([]tke.InstanceAdvancedSettings, 0),
}
if masters, ok := d.GetOk("master_config"); ok {
if clusterDeployType == TKE_DEPLOY_TYPE_MANAGED {
return fmt.Errorf("if `cluster_deploy_type` is `MANAGED_CLUSTER` , You don't need define the master yourself")
}
var masterCount int64 = 0
masterList := masters.([]interface{})
for index := range masterList {
master := masterList[index].(map[string]interface{})
paraJson, count, err := tkeGetCvmRunInstancesPara(master, meta, vpcId, basic.ProjectId)
if err != nil {
return err

cdc_id := d.Get("cdc_id").(string)

if cdc_id == "" {
if masters, ok := d.GetOk("master_config"); ok {
if clusterDeployType == TKE_DEPLOY_TYPE_MANAGED {
return fmt.Errorf("if `cluster_deploy_type` is `MANAGED_CLUSTER` , You don't need define the master yourself")
}
var masterCount int64 = 0
masterList := masters.([]interface{})
for index := range masterList {
master := masterList[index].(map[string]interface{})
paraJson, count, err := tkeGetCvmRunInstancesPara(master, meta, vpcId, basic.ProjectId)
if err != nil {
return err
}

cvms.Master = append(cvms.Master, paraJson)
masterCount += count
cvms.Master = append(cvms.Master, paraJson)
masterCount += count

if v, ok := master["desired_pod_num"]; ok {
dpNum := int64(v.(int))
if dpNum != DefaultDesiredPodNum {
overrideSettings.Master = append(overrideSettings.Master, tke.InstanceAdvancedSettings{DesiredPodNumber: helper.Int64(dpNum)})
if v, ok := master["desired_pod_num"]; ok {
dpNum := int64(v.(int))
if dpNum != DefaultDesiredPodNum {
overrideSettings.Master = append(overrideSettings.Master, tke.InstanceAdvancedSettings{DesiredPodNumber: helper.Int64(dpNum)})
}
}
}
if masterCount < 3 {
return fmt.Errorf("if `cluster_deploy_type` is `TKE_DEPLOY_TYPE_INDEPENDENT` len(master_config) should >=3")
}
} else if clusterDeployType == TKE_DEPLOY_TYPE_INDEPENDENT {
return fmt.Errorf("if `cluster_deploy_type` is `TKE_DEPLOY_TYPE_INDEPENDENT` , You need define the master yourself")
}
if masterCount < 3 {
return fmt.Errorf("if `cluster_deploy_type` is `TKE_DEPLOY_TYPE_INDEPENDENT` len(master_config) should >=3")
}
} else if clusterDeployType == TKE_DEPLOY_TYPE_INDEPENDENT {
return fmt.Errorf("if `cluster_deploy_type` is `TKE_DEPLOY_TYPE_INDEPENDENT` , You need define the master yourself")
}

if workers, ok := d.GetOk("worker_config"); ok {
Expand Down Expand Up @@ -261,6 +266,10 @@ func resourceTencentCloudKubernetesClusterCreatePostFillRequest0(ctx context.Con
iAdvanced.DockerGraphPath = "/var/lib/docker"
}

if preStartUserScript, ok := d.GetOk("pre_start_user_script"); ok {
iAdvanced.PreStartUserScript = preStartUserScript.(string)
}

// ExistedInstancesForNode
existInstances := make([]*tke.ExistedInstancesForNode, 0)
if instances, ok := d.GetOk("exist_instance"); ok {
Expand Down Expand Up @@ -296,6 +305,7 @@ func resourceTencentCloudKubernetesClusterCreatePostFillRequest0(ctx context.Con
req.ClusterAdvancedSettings.VpcCniType = &advanced.VpcCniType

req.InstanceAdvancedSettings.DockerGraphPath = &iAdvanced.DockerGraphPath
req.InstanceAdvancedSettings.PreStartUserScript = &iAdvanced.PreStartUserScript
req.InstanceAdvancedSettings.UserScript = &iAdvanced.UserScript

if len(iAdvanced.DataDisks) > 0 {
Expand All @@ -311,7 +321,9 @@ func resourceTencentCloudKubernetesClusterCreatePostFillRequest0(ctx context.Con

req.RunInstancesForNode = []*tke.RunInstancesForNode{}

if len(cvms.Master) != 0 {
if cdc_id != "" {
req.ClusterType = helper.String(clusterDeployType)
} else if len(cvms.Master) != 0 {

var node tke.RunInstancesForNode
node.NodeRole = helper.String(TKE_ROLE_MASTER_ETCD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ resource "tencentcloud_kubernetes_health_check_policy" "kubernetes_health_check_
`

// const testAccKubernetesHealthCheckPolicyUpdate = testAccTkeCluster + `
const testAccKubernetesHealthCheckPolicyCreate = `
const testAccKubernetesHealthCheckPolicyUpdate = `

resource "tencentcloud_kubernetes_health_check_policy" "kubernetes_health_check_policy" {
cluster_id = "cls-eh0da110"
Expand Down
17 changes: 9 additions & 8 deletions tencentcloud/services/tke/service_tencentcloud_tke.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ type RunInstancesForNode struct {
}

type InstanceAdvancedSettings struct {
MountTarget string
DockerGraphPath string
UserScript string
Unschedulable int64
DesiredPodNum int64
Labels []*tke.Label
DataDisks []*tke.DataDisk
ExtraArgs tke.InstanceExtraArgs
MountTarget string
DockerGraphPath string
PreStartUserScript string
UserScript string
Unschedulable int64
DesiredPodNum int64
Labels []*tke.Label
DataDisks []*tke.DataDisk
ExtraArgs tke.InstanceExtraArgs
}

type ClusterCidrSettings struct {
Expand Down
Loading
Loading