Skip to content

Commit

Permalink
Merge pull request #170 from volcengine/Feat/vke-nodepool
Browse files Browse the repository at this point in the history
Feat/vke nodepool
  • Loading branch information
msq177 authored Jul 31, 2024
2 parents b40d332 + a45e13d commit 042db43
Show file tree
Hide file tree
Showing 12 changed files with 475 additions and 93 deletions.
2 changes: 1 addition & 1 deletion common/common_volcengine_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
TerraformProviderName = "terraform-provider-volcengine"
TerraformProviderVersion = "0.0.148"
TerraformProviderVersion = "0.0.149"
)
197 changes: 141 additions & 56 deletions example/vkeNodePool/main.tf
Original file line number Diff line number Diff line change
@@ -1,84 +1,169 @@
data "volcengine_zones" "foo"{
data "volcengine_zones" "foo" {
}

resource "volcengine_vpc" "foo" {
vpc_name = "acc-test-vpc"
cidr_block = "172.16.0.0/16"
vpc_name = "acc-test-vpc"
cidr_block = "172.16.0.0/16"
}

resource "volcengine_subnet" "foo" {
subnet_name = "acc-test-subnet"
cidr_block = "172.16.0.0/24"
zone_id = data.volcengine_zones.foo.zones[0].id
vpc_id = volcengine_vpc.foo.id
subnet_name = "acc-test-subnet"
cidr_block = "172.16.0.0/24"
zone_id = data.volcengine_zones.foo.zones[0].id
vpc_id = volcengine_vpc.foo.id
}

resource "volcengine_security_group" "foo" {
security_group_name = "acc-test-security-group"
vpc_id = volcengine_vpc.foo.id
security_group_name = "acc-test-security-group"
vpc_id = volcengine_vpc.foo.id
}

data "volcengine_images" "foo" {
name_regex = "veLinux 1.0 CentOS兼容版 64位"
name_regex = "veLinux 1.0 CentOS兼容版 64位"
}

resource "volcengine_vke_cluster" "foo" {
name = "acc-test-cluster"
description = "created by terraform"
delete_protection_enabled = false
cluster_config {
subnet_ids = [volcengine_subnet.foo.id]
api_server_public_access_enabled = true
api_server_public_access_config {
public_access_network_config {
billing_type = "PostPaidByBandwidth"
bandwidth = 1
}
}
resource_public_access_default_enabled = true
name = "acc-test-cluster"
description = "created by terraform"
delete_protection_enabled = false
cluster_config {
subnet_ids = [volcengine_subnet.foo.id]
api_server_public_access_enabled = true
api_server_public_access_config {
public_access_network_config {
billing_type = "PostPaidByBandwidth"
bandwidth = 1
}
}
pods_config {
pod_network_mode = "VpcCniShared"
vpc_cni_config {
subnet_ids = [volcengine_subnet.foo.id]
}
resource_public_access_default_enabled = true
}
pods_config {
pod_network_mode = "VpcCniShared"
vpc_cni_config {
subnet_ids = [volcengine_subnet.foo.id]
}
}
services_config {
service_cidrsv4 = ["172.30.0.0/18"]
}
tags {
key = "tf-k1"
value = "tf-v1"
}
}

resource "volcengine_vke_node_pool" "foo" {
cluster_id = volcengine_vke_cluster.foo.id
name = "acc-test-node-pool"
auto_scaling {
enabled = true
min_replicas = 0
max_replicas = 5
desired_replicas = 0
priority = 5
subnet_policy = "ZoneBalance"
}
node_config {
instance_type_ids = ["ecs.g1ie.xlarge"]
subnet_ids = [volcengine_subnet.foo.id]
image_id = [for image in data.volcengine_images.foo.images : image.image_id if image.image_name == "veLinux 1.0 CentOS兼容版 64位"][0]
system_volume {
type = "ESSD_PL0"
size = 80
}
data_volumes {
type = "ESSD_PL0"
size = 80
mount_point = "/tf1"
}
data_volumes {
type = "ESSD_PL0"
size = 60
mount_point = "/tf2"
}
initialize_script = "ZWNobyBoZWxsbyB0ZXJyYWZvcm0h"
security {
login {
password = "UHdkMTIzNDU2"
}
security_strategies = ["Hids"]
security_group_ids = [volcengine_security_group.foo.id]
}
additional_container_storage_enabled = false
instance_charge_type = "PostPaid"
name_prefix = "acc-test"
ecs_tags {
key = "ecs_k1"
value = "ecs_v1"
}
services_config {
service_cidrsv4 = ["172.30.0.0/18"]
}
kubernetes_config {
labels {
key = "label1"
value = "value1"
}
taints {
key = "taint-key/node-type"
value = "taint-value"
effect = "NoSchedule"
}
cordon = true
}
tags {
key = "node-pool-k1"
value = "node-pool-v1"
}
}

// add existing instances to a custom node pool
resource "volcengine_ecs_instance" "foo" {
instance_name = "acc-test-ecs-${count.index}"
host_name = "tf-acc-test"
image_id = [for image in data.volcengine_images.foo.images : image.image_id if image.image_name == "veLinux 1.0 CentOS兼容版 64位"][0]
instance_type = "ecs.g1ie.xlarge"
password = "93f0cb0614Aab12"
instance_charge_type = "PostPaid"
system_volume_type = "ESSD_PL0"
system_volume_size = 50
data_volumes {
volume_type = "ESSD_PL0"
size = 50
delete_with_instance = true
}
subnet_id = volcengine_subnet.foo.id
security_group_ids = [volcengine_security_group.foo.id]
project_name = "default"
tags {
key = "tf-k1"
value = "tf-v1"
key = "k1"
value = "v1"
}
lifecycle {
ignore_changes = [security_group_ids, tags]
}
count = 2
}

resource "volcengine_vke_node_pool" "foo" {
resource "volcengine_vke_node_pool" "foo1" {
cluster_id = volcengine_vke_cluster.foo.id
name = "acc-test-node-pool"
auto_scaling {
enabled = true
min_replicas = 0
max_replicas = 5
desired_replicas = 0
priority = 5
subnet_policy = "ZoneBalance"
}
name = "acc-test-node-pool"
instance_ids = volcengine_ecs_instance.foo[*].id
keep_instance_name = true
node_config {
instance_type_ids = ["ecs.g1ie.xlarge"]
subnet_ids = [volcengine_subnet.foo.id]
image_id = [for image in data.volcengine_images.foo.images : image.image_id if image.image_name == "veLinux 1.0 CentOS兼容版 64位"][0]
subnet_ids = [volcengine_subnet.foo.id]
image_id = [for image in data.volcengine_images.foo.images : image.image_id if image.image_name == "veLinux 1.0 CentOS兼容版 64位"][0]
system_volume {
type = "ESSD_PL0"
size = 80
}
data_volumes {
type = "ESSD_PL0"
size = 80
type = "ESSD_PL0"
size = 80
mount_point = "/tf1"
}
data_volumes {
type = "ESSD_PL0"
size = 60
type = "ESSD_PL0"
size = 60
mount_point = "/tf2"
}
initialize_script = "ZWNobyBoZWxsbyB0ZXJyYWZvcm0h"
Expand All @@ -87,13 +172,13 @@ resource "volcengine_vke_node_pool" "foo" {
password = "UHdkMTIzNDU2"
}
security_strategies = ["Hids"]
security_group_ids = [volcengine_security_group.foo.id]
security_group_ids = [volcengine_security_group.foo.id]
}
additional_container_storage_enabled = false
instance_charge_type = "PostPaid"
name_prefix = "acc-test"
instance_charge_type = "PostPaid"
name_prefix = "acc-test"
ecs_tags {
key = "ecs_k1"
key = "ecs_k1"
value = "ecs_v1"
}
}
Expand All @@ -103,14 +188,14 @@ resource "volcengine_vke_node_pool" "foo" {
value = "value1"
}
taints {
key = "taint-key/node-type"
value = "taint-value"
key = "taint-key/node-type"
value = "taint-value"
effect = "NoSchedule"
}
cordon = true
}
tags {
key = "node-pool-k1"
key = "node-pool-k1"
value = "node-pool-v1"
}
}
}
1 change: 0 additions & 1 deletion volcengine/ebs/volume/resource_volcengine_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func ResourceVolcengineVolume() *schema.Resource {
Default: "PostPaid",
Description: "The charge type of the Volume, the value is `PostPaid` or `PrePaid`. " +
"The `PrePaid` volume cannot be detached. " +
"Cannot convert `PrePaid` volume to `PostPaid`." +
"Please note that `PrePaid` type needs to ask the system administrator to apply for a whitelist.",
},
"status": {
Expand Down
18 changes: 7 additions & 11 deletions volcengine/ebs/volume/service_volcengine_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,17 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa
Action: "ModifyVolumeChargeType",
ConvertMode: ve.RequestConvertIgnore,
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
oldV, newV := resourceData.GetChange("volume_charge_type")
if oldV == "PrePaid" && newV == "PostPaid" {
return false, errors.New("cannot convert PrePaid volume to PostPaid")
}
if d.Get("instance_id").(string) == "" {
return false, errors.New("instance id cannot be empty")
}

chargeType := resourceData.Get("volume_charge_type")
(*call.SdkParam)["VolumeIds.1"] = d.Id()
(*call.SdkParam)["DiskChargeType"] = "PrePaid"
(*call.SdkParam)["AutoPay"] = true
(*call.SdkParam)["DiskChargeType"] = chargeType
(*call.SdkParam)["InstanceId"] = d.Get("instance_id")
if chargeType == "PrePaid" {
(*call.SdkParam)["AutoPay"] = true
}
return true, nil
},
ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) {
Expand All @@ -269,10 +268,7 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa
return resp, err
},
CallError: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall, baseErr error) error {
oldV, newV := resourceData.GetChange("volume_charge_type")
if oldV == "PrePaid" && newV == "PostPaid" {
return errors.New("cannot convert PrePaid volume to PostPaid")
}
chargeType := resourceData.Get("volume_charge_type")
if d.Get("instance_id").(string) == "" {
return errors.New("instance id cannot be empty")
}
Expand All @@ -283,7 +279,7 @@ func (s *VolcengineVolumeService) ModifyResource(resourceData *schema.ResourceDa
return re.NonRetryableError(fmt.Errorf("error on reading volume %q: %w", d.Id(), callErr))
}
// 计费方式已经转变成功
if data["PayType"] == "pre" {
if (chargeType == "PrePaid" && data["PayType"] == "pre") || (chargeType == "PostPaid" && data["PayType"] == "post") {
return nil
}
// 计费方式还没有转换成功,尝试重新转换
Expand Down
10 changes: 6 additions & 4 deletions volcengine/vke/cluster/resource_volcengine_vke_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func ResourceVolcengineVkeCluster() *schema.Resource {
}
return false
},
Description: "The version of Kubernetes specified when creating a VKE cluster (specified to patch version), with an example value of `v1.24`. If not specified, the latest Kubernetes version supported by VKE is used by default, which is a 3-segment version format starting with a lowercase v, that is, KubernetesVersion with IsLatestVersion=True in the return value of ListSupportedVersions.",
Description: "The version of Kubernetes specified when creating a VKE cluster (specified to patch version), with an example value of `1.24`. If not specified, the latest Kubernetes version supported by VKE is used by default, which is a 3-segment version format starting with a lowercase v, that is, KubernetesVersion with IsLatestVersion=True in the return value of ListSupportedVersions.",
},
"tags": ve.TagsSchema(),
"cluster_config": {
Expand All @@ -81,12 +81,14 @@ func ResourceVolcengineVkeCluster() *schema.Resource {
"subnet_ids": {
Type: schema.TypeSet,
Required: true,
ForceNew: true,
MaxItems: 6,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
Description: "The subnet ID for the cluster control plane to communicate within the private network.",
Set: schema.HashString,
Description: "The subnet ID for the cluster control plane to communicate within the private network.\n" +
"Up to 3 subnets can be selected from each available zone, and a maximum of 2 subnets can be added to each available zone.\n" +
"Cannot support deleting configured subnets.",
},
"api_server_public_access_enabled": {
Type: schema.TypeBool,
Expand Down
12 changes: 6 additions & 6 deletions volcengine/vke/node/resource_volcengine_vke_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,29 @@ func ResourceVolcengineVkeNode() *schema.Resource {
Optional: true,
Default: false,
ForceNew: true,
Description: "The flag of additional container storage enable, the value is `true` or `false`.",
Description: "The flag of additional container storage enable, the value is `true` or `false`. This field is valid only when adding an existing instance to the default node pool.",
},
"image_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The ImageId of NodeConfig.",
Description: "The ImageId of NodeConfig. This field is valid only when adding an existing instance to the default node pool.",
},
"initialize_script": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The initializeScript of Node.",
Description: "The initializeScript of Node. This field is valid only when adding an existing instance to the default node pool.",
},
"kubernetes_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The KubernetesConfig of Node.",
Description: "The KubernetesConfig of Node. This field is valid only when adding an existing instance to the default node pool.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"labels": {
Expand Down Expand Up @@ -161,14 +161,14 @@ func ResourceVolcengineVkeNode() *schema.Resource {
flag := d.Get("additional_container_storage_enabled")
return flag == nil || !flag.(bool)
},
Description: "The container storage path.",
Description: "The container storage path. This field is valid only when adding an existing instance to the default node pool.",
},
"node_pool_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: "The node pool id.",
Description: "The node pool id. This field is used to specify the custom node pool to which you want to add nodes. If not filled in, it means added to the default node pool.",
},
},
}
Expand Down
Loading

0 comments on commit 042db43

Please sign in to comment.