Skip to content

Commit

Permalink
support extend_param in cce node, add two new param fixed_ip and hw_p…
Browse files Browse the repository at this point in the history
…assthrough
  • Loading branch information
Jason-Zhang9309 committed Feb 27, 2021
1 parent 355eabd commit 805fa0a
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 72 deletions.
14 changes: 14 additions & 0 deletions docs/resources/cce_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ The following arguments are supported:

* `subnet_id` - (Optional, String, ForceNew) The ID of the subnet to which the NIC belongs. Changing this parameter will create a new resource.

* `fixed_ip` - (Optional, String, ForceNew) The fixed IP of the NIC. Changing this parameter will create a new resource.

* `eip_id` - (Optional, String, ForceNew) The ID of the EIP. Changing this parameter will create a new resource.


Expand All @@ -157,6 +159,18 @@ The following arguments are supported:
* `postinstall` - (Optional, String, ForceNew) Script required after installation. The input value can be a Base64 encoded string or not.
Changing this parameter will create a new resource.

* `extend_param` - (Optional, Map, ForceNew) Extended parameter. Changing this parameter will create a new resource. Availiable keys :

* `alpha.cce/NodeImageID` - This parameter is required when a custom image is used to create a BMS node.
* `dockerBaseSize` - The available disk space of a single docker container on the node in device mapper mode.
* `DockerLVMConfigOverride` - Docker data disk configurations. The following is an example default configuration:

```hcl
extend_param = {
DockerLVMConfigOverride = "dockerThinpool=vgpaas/90%VG;kubernetesLV=vgpaas/10%VG;diskType=evs;lvType=linear"
}
```
* `labels` - (Optional, Map, ForceNew) Tags of a Kubernetes node, key/value pair format. Changing this parameter will create a new resource.
* `tags` - (Optional, Map) Tags of a VM node, key/value pair format.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/terraform-plugin-sdk v1.13.0
github.com/huaweicloud/golangsdk v0.0.0-20210223120349-95b96c64969c
github.com/huaweicloud/golangsdk v0.0.0-20210226030432-bcda8c57eb97
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a
github.com/mitchellh/go-homedir v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/huaweicloud/golangsdk v0.0.0-20210205071117-066cac2eec52 h1:+fuguE3AQsM8HRuT1dvcr1uO3eK0jXi3OXiUsb/kAF4=
github.com/huaweicloud/golangsdk v0.0.0-20210205071117-066cac2eec52/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210218092317-09c77d0b0be0 h1:n92GyvoN8wTBHZ16vvvEytIPJbQJ6yCkyYYWEVij2Os=
github.com/huaweicloud/golangsdk v0.0.0-20210218092317-09c77d0b0be0/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210223120349-95b96c64969c h1:OLgbcIr+6i9Qhex7ISLhDcssUPOXARq52Pye8LhBAPA=
github.com/huaweicloud/golangsdk v0.0.0-20210223120349-95b96c64969c/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210226030432-bcda8c57eb97 h1:r4e2CDPxWUvowRs0UgKIeQylw4Rwk6NsF55OqclN2LE=
github.com/huaweicloud/golangsdk v0.0.0-20210226030432-bcda8c57eb97/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
31 changes: 15 additions & 16 deletions huaweicloud/resource_huaweicloud_cce_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func ResourceCCENodePool() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"hw_passthrough": {
Type: schema.TypeBool,
Optional: true,
},
"extend_param": {
Type: schema.TypeMap,
Optional: true,
Expand All @@ -97,6 +101,10 @@ func ResourceCCENodePool() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"hw_passthrough": {
Type: schema.TypeBool,
Optional: true,
},
"extend_param": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -230,14 +238,6 @@ func resourceCCENodePoolCreate(d *schema.ResourceData, meta interface{}) error {
}
}

var base64PreInstall, base64PostInstall string
if v, ok := d.GetOk("preinstall"); ok {
base64PreInstall = installScriptEncode(v.(string))
}
if v, ok := d.GetOk("postinstall"); ok {
base64PostInstall = installScriptEncode(v.(string))
}

initialNodeCount := d.Get("initial_node_count").(int)

createOpts := nodepools.CreateOpts{
Expand All @@ -263,11 +263,8 @@ func resourceCCENodePoolCreate(d *schema.ResourceData, meta interface{}) error {
SubnetId: d.Get("subnet_id").(string),
},
},
ExtendParam: nodes.ExtendParam{
PreInstall: base64PreInstall,
PostInstall: base64PostInstall,
},
Taints: resourceCCETaint(d),
ExtendParam: resourceCCEExtendParam(d),
Taints: resourceCCETaint(d),
},
Autoscaling: nodepools.AutoscalingSpec{
Enable: d.Get("scall_enable").(bool),
Expand Down Expand Up @@ -372,6 +369,7 @@ func resourceCCENodePoolRead(d *schema.ResourceData, meta interface{}) error {
volume := make(map[string]interface{})
volume["size"] = pairObject.Size
volume["volumetype"] = pairObject.VolumeType
volume["hw_passthrough"] = pairObject.HwPassthrough
volume["extend_param"] = pairObject.ExtendParam
volumes = append(volumes, volume)
}
Expand All @@ -381,9 +379,10 @@ func resourceCCENodePoolRead(d *schema.ResourceData, meta interface{}) error {

rootVolume := []map[string]interface{}{
{
"size": s.Spec.NodeTemplate.RootVolume.Size,
"volumetype": s.Spec.NodeTemplate.RootVolume.VolumeType,
"extend_param": s.Spec.NodeTemplate.RootVolume.ExtendParam,
"size": s.Spec.NodeTemplate.RootVolume.Size,
"volumetype": s.Spec.NodeTemplate.RootVolume.VolumeType,
"hw_passthrough": s.Spec.NodeTemplate.RootVolume.HwPassthrough,
"extend_param": s.Spec.NodeTemplate.RootVolume.ExtendParam,
},
}
if err := d.Set("root_volume", rootVolume); err != nil {
Expand Down
109 changes: 81 additions & 28 deletions huaweicloud/resource_huaweicloud_cce_node_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"fmt"
"log"
"strconv"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -101,6 +102,10 @@ func ResourceCCENodeV3() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"hw_passthrough": {
Type: schema.TypeBool,
Optional: true,
},
"extend_param": {
Type: schema.TypeMap,
Optional: true,
Expand All @@ -122,6 +127,10 @@ func ResourceCCENodeV3() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"hw_passthrough": {
Type: schema.TypeBool,
Optional: true,
},
"extend_param": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -265,12 +274,23 @@ func ResourceCCENodeV3() *schema.Resource {
}
},
},
"extend_param": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"subnet_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"fixed_ip": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -323,9 +343,10 @@ func resourceCCEDataVolume(d *schema.ResourceData) []nodes.VolumeSpec {
for i, raw := range volumeRaw {
rawMap := raw.(map[string]interface{})
volumes[i] = nodes.VolumeSpec{
Size: rawMap["size"].(int),
VolumeType: rawMap["volumetype"].(string),
ExtendParam: rawMap["extend_param"].(map[string]interface{}),
Size: rawMap["size"].(int),
VolumeType: rawMap["volumetype"].(string),
HwPassthrough: rawMap["hw_passthrough"].(bool),
ExtendParam: rawMap["extend_param"].(map[string]interface{}),
}
}
return volumes
Expand All @@ -351,6 +372,7 @@ func resourceCCERootVolume(d *schema.ResourceData) nodes.VolumeSpec {
if len(nicsRaw) == 1 {
nics.Size = nicsRaw[0].(map[string]interface{})["size"].(int)
nics.VolumeType = nicsRaw[0].(map[string]interface{})["volumetype"].(string)
nics.HwPassthrough = nicsRaw[0].(map[string]interface{})["hw_passthrough"].(bool)
nics.ExtendParam = nicsRaw[0].(map[string]interface{})["extend_param"].(map[string]interface{})
}
return nics
Expand All @@ -368,6 +390,48 @@ func resourceCCEEipIDs(d *schema.ResourceData) []string {
return id
}

func resourceCCEExtendParam(d *schema.ResourceData) map[string]interface{} {
extendParam := make(map[string]interface{})
if v, ok := d.GetOk("extend_param"); ok {
for key, val := range v.(map[string]interface{}) {
extendParam[key] = val.(string)
}
if v, ok := extendParam["periodNum"]; ok {
periodNum, err := strconv.Atoi(v.(string))
if err != nil {
log.Printf("[WARNING] PeriodNum %s invalid, Type conversion error: %s", v.(string), err)
}
extendParam["periodNum"] = periodNum
}
}
if v, ok := d.GetOk("extend_param_charging_mode"); ok {
extendParam["chargingMode"] = v.(int)
}
if v, ok := d.GetOk("ecs_performance_type"); ok {
extendParam["ecs:performancetype"] = v.(string)
}
if v, ok := d.GetOk("max_pods"); ok {
extendParam["maxPods"] = v.(int)
}
if v, ok := d.GetOk("order_id"); ok {
extendParam["orderID"] = v.(string)
}
if v, ok := d.GetOk("product_id"); ok {
extendParam["productID"] = v.(string)
}
if v, ok := d.GetOk("public_key"); ok {
extendParam["publicKey"] = v.(string)
}
if v, ok := d.GetOk("preinstall"); ok {
extendParam["alpha.cce/preInstall"] = installScriptEncode(v.(string))
}
if v, ok := d.GetOk("postinstall"); ok {
extendParam["alpha.cce/postInstall"] = installScriptEncode(v.(string))
}

return extendParam
}

func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
nodeClient, err := config.CceV3Client(GetRegion(d, config))
Expand All @@ -387,14 +451,6 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error {
}
}

var base64PreInstall, base64PostInstall string
if v, ok := d.GetOk("preinstall"); ok {
base64PreInstall = installScriptEncode(v.(string))
}
if v, ok := d.GetOk("postinstall"); ok {
base64PostInstall = installScriptEncode(v.(string))
}

// eipCount must be specified when bandwidth_size parameters was set
eipCount := 0
if _, ok := d.GetOk("bandwidth_size"); ok {
Expand Down Expand Up @@ -434,23 +490,18 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error {
SubnetId: d.Get("subnet_id").(string),
},
},
EcsGroupID: d.Get("ecs_group_id").(string),
ExtendParam: nodes.ExtendParam{
ChargingMode: d.Get("extend_param_charging_mode").(int),
EcsPerformanceType: d.Get("ecs_performance_type").(string),
MaxPods: d.Get("max_pods").(int),
OrderID: d.Get("order_id").(string),
ProductID: d.Get("product_id").(string),
PublicKey: d.Get("public_key").(string),
PreInstall: base64PreInstall,
PostInstall: base64PostInstall,
},
Taints: resourceCCETaint(d),
K8sTags: resourceCCENodeK8sTags(d),
UserTags: resourceCCENodeTags(d),
EcsGroupID: d.Get("ecs_group_id").(string),
ExtendParam: resourceCCEExtendParam(d),
Taints: resourceCCETaint(d),
K8sTags: resourceCCENodeK8sTags(d),
UserTags: resourceCCENodeTags(d),
},
}

if v, ok := d.GetOk("fixed_ip"); ok {
createOpts.Spec.NodeNicSpec.PrimaryNic.FixedIps = []string{v.(string)}
}

clusterid := d.Get("cluster_id").(string)
stateCluster := &resource.StateChangeConf{
Target: []string{"Available"},
Expand Down Expand Up @@ -548,6 +599,7 @@ func resourceCCENodeV3Read(d *schema.ResourceData, meta interface{}) error {
volume := make(map[string]interface{})
volume["size"] = pairObject.Size
volume["volumetype"] = pairObject.VolumeType
volume["hw_passthrough"] = pairObject.HwPassthrough
volume["extend_param"] = pairObject.ExtendParam
volumes = append(volumes, volume)
}
Expand All @@ -557,9 +609,10 @@ func resourceCCENodeV3Read(d *schema.ResourceData, meta interface{}) error {

rootVolume := []map[string]interface{}{
{
"size": s.Spec.RootVolume.Size,
"volumetype": s.Spec.RootVolume.VolumeType,
"extend_param": s.Spec.RootVolume.ExtendParam,
"size": s.Spec.RootVolume.Size,
"volumetype": s.Spec.RootVolume.VolumeType,
"hw_passthrough": s.Spec.RootVolume.HwPassthrough,
"extend_param": s.Spec.RootVolume.ExtendParam,
},
}
if err := d.Set("root_volume", rootVolume); err != nil {
Expand Down

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

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ github.com/hashicorp/terraform-svchost/auth
github.com/hashicorp/terraform-svchost/disco
# github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/hashicorp/yamux
# github.com/huaweicloud/golangsdk v0.0.0-20210223120349-95b96c64969c
# github.com/huaweicloud/golangsdk v0.0.0-20210226030432-bcda8c57eb97
## explicit
github.com/huaweicloud/golangsdk
github.com/huaweicloud/golangsdk/internal
Expand Down

0 comments on commit 805fa0a

Please sign in to comment.