From bed1a02505cc2a35b16517dcd3355cb4e4ce5d74 Mon Sep 17 00:00:00 2001 From: ShiChangkuo Date: Wed, 31 Mar 2021 16:11:08 +0800 Subject: [PATCH] [cce] Add possibility to set runtime --- docs/resources/cce_node.md | 3 +++ .../resource_huaweicloud_cce_node_pool.go | 17 +++++++++++++++++ huaweicloud/resource_huaweicloud_cce_node_v3.go | 16 ++++++++++++++++ .../openstack/cce/v3/nodepools/requests.go | 2 +- .../golangsdk/openstack/cce/v3/nodes/results.go | 7 +++++++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/docs/resources/cce_node.md b/docs/resources/cce_node.md index 861356aaf0..da3f3910fc 100644 --- a/docs/resources/cce_node.md +++ b/docs/resources/cce_node.md @@ -191,6 +191,9 @@ The following arguments are supported: * `auto_renew` - (Optional, String, ForceNew) Specifies whether auto renew is enabled. Valid values are "true" and "false". Changing this creates a new resource. +* `runtime` - (Optional, String, ForceNew) Specifies the runtime of the CCE node. Valid values are *docker* and *containerd*. + Changing this creates a new resource. + * `extend_param` - (Optional, Map, ForceNew) Extended parameter. Changing this parameter will create a new resource. Availiable keys : * `agency_name` - Specifies the agency name to provide temporary credentials for CCE node to access other cloud services. diff --git a/huaweicloud/resource_huaweicloud_cce_node_pool.go b/huaweicloud/resource_huaweicloud_cce_node_pool.go index 1a70eb0a66..55fe275498 100644 --- a/huaweicloud/resource_huaweicloud_cce_node_pool.go +++ b/huaweicloud/resource_huaweicloud_cce_node_pool.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/huaweicloud/golangsdk" "github.com/huaweicloud/golangsdk/openstack/cce/v3/nodepools" "github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes" @@ -201,6 +202,15 @@ func ResourceCCENodePool() *schema.Resource { } }, }, + "runtime": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "docker", "containerd", + }, false), + }, "extend_param": { Type: schema.TypeMap, Optional: true, @@ -298,6 +308,12 @@ func resourceCCENodePoolCreate(d *schema.ResourceData, meta interface{}) error { }, } + if v, ok := d.GetOk("runtime"); ok { + createOpts.Spec.NodeTemplate.RunTime = &nodes.RunTimeSpec{ + Name: v.(string), + } + } + clusterid := d.Get("cluster_id").(string) stateCluster := &resource.StateChangeConf{ Target: []string{"Available"}, @@ -369,6 +385,7 @@ func resourceCCENodePoolRead(d *schema.ResourceData, meta interface{}) error { d.Set("os", s.Spec.NodeTemplate.Os) d.Set("billing_mode", s.Spec.NodeTemplate.BillingMode) d.Set("key_pair", s.Spec.NodeTemplate.Login.SshKey) + d.Set("runtime", s.Spec.NodeTemplate.RunTime.Name) d.Set("initial_node_count", s.Spec.InitialNodeCount) d.Set("scall_enable", s.Spec.Autoscaling.Enable) d.Set("min_node_count", s.Spec.Autoscaling.MinNodeCount) diff --git a/huaweicloud/resource_huaweicloud_cce_node_v3.go b/huaweicloud/resource_huaweicloud_cce_node_v3.go index 370e2d0652..c775214e60 100644 --- a/huaweicloud/resource_huaweicloud_cce_node_v3.go +++ b/huaweicloud/resource_huaweicloud_cce_node_v3.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/huaweicloud/golangsdk" "github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters" "github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes" @@ -196,6 +197,15 @@ func ResourceCCENodeV3() *schema.Resource { "iptype", "bandwidth_size", "sharetype", }, }, + "runtime": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + "docker", "containerd", + }, false), + }, "ecs_group_id": { Type: schema.TypeString, Optional: true, @@ -559,6 +569,11 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error { if v, ok := d.GetOk("fixed_ip"); ok { createOpts.Spec.NodeNicSpec.PrimaryNic.FixedIps = []string{v.(string)} } + if v, ok := d.GetOk("runtime"); ok { + createOpts.Spec.RunTime = &nodes.RunTimeSpec{ + Name: v.(string), + } + } clusterid := d.Get("cluster_id").(string) stateCluster := &resource.StateChangeConf{ @@ -632,6 +647,7 @@ func resourceCCENodeV3Read(d *schema.ResourceData, meta interface{}) error { d.Set("os", s.Spec.Os) d.Set("key_pair", s.Spec.Login.SshKey) d.Set("subnet_id", s.Spec.NodeNicSpec.PrimaryNic.SubnetId) + d.Set("runtime", s.Spec.RunTime.Name) d.Set("ecs_group_id", s.Spec.EcsGroupID) d.Set("billing_mode", s.Spec.BillingMode) if s.Spec.BillingMode != 0 { diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodepools/requests.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodepools/requests.go index 8ff594aa7e..0d68467a77 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodepools/requests.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodepools/requests.go @@ -181,7 +181,7 @@ type UpdateMetaData struct { // UpdateSpec describes Node pools update specification type UpdateSpec struct { // Node type. Currently, only VM nodes are supported. - Type string `json:"type"` + Type string `json:"type,omitempty"` // Node template NodeTemplate nodes.Spec `json:"nodeTemplate"` // Initial number of expected nodes diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes/results.go index 5a4667a0d5..63010ce063 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes/results.go @@ -73,6 +73,8 @@ type Spec struct { UserTags []tags.ResourceTag `json:"userTags,omitempty"` // Tag of a Kubernetes node, key value pair format K8sTags map[string]string `json:"k8sTags,omitempty"` + // The runtime spec + RunTime *RunTimeSpec `json:"runtime,omitempty"` // taints to created nodes to configure anti-affinity Taints []TaintSpec `json:"taints,omitempty"` } @@ -158,6 +160,11 @@ type EipSpec struct { Bandwidth BandwidthOpts `json:"bandwidth,omitempty"` } +type RunTimeSpec struct { + // the name of runtime: docker or containerd + Name string `json:"name,omitempty"` +} + type BandwidthOpts struct { ChargeMode string `json:"chargemode,omitempty"` Size int `json:"size,omitempty"`