From 3ee0538c38cd5d4d20565f91b808aa79309e97a0 Mon Sep 17 00:00:00 2001 From: yangshuai Date: Tue, 28 Jul 2020 16:45:17 +0800 Subject: [PATCH] Add kubeProxyMode and taints params --- .../resource_huaweicloud_cce_cluster_v3.go | 13 ++++- .../resource_huaweicloud_cce_node_v3.go | 47 ++++++++++++++++++- website/docs/r/cce_cluster_v3.html.md | 7 ++- website/docs/r/cce_node_v3.html.md | 15 ++++++ 4 files changed, 78 insertions(+), 4 deletions(-) diff --git a/huaweicloud/resource_huaweicloud_cce_cluster_v3.go b/huaweicloud/resource_huaweicloud_cce_cluster_v3.go index a2cbb82250..4e88d29025 100644 --- a/huaweicloud/resource_huaweicloud_cce_cluster_v3.go +++ b/huaweicloud/resource_huaweicloud_cce_cluster_v3.go @@ -130,6 +130,10 @@ func resourceCCEClusterV3() *schema.Resource { ForceNew: true, ValidateFunc: validateIP, }, + "kube_proxy_mode": { + Type: schema.TypeString, + Optional: true, + }, "status": { Type: schema.TypeString, Computed: true, @@ -200,6 +204,9 @@ func resourceClusterExtendParamV3(d *schema.ResourceData) map[string]string { if multi_az, ok := d.GetOk("multi_az"); ok && multi_az == true { m["clusterAZ"] = "multi_az" } + if kube_proxy_mode, ok := d.GetOk("kube_proxy_mode"); ok{ + m["kubeProxyMode"] = kube_proxy_mode.(string) + } if eip, ok := d.GetOk("eip"); ok { m["clusterExternalIP"] = eip.(string) } @@ -214,6 +221,7 @@ func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("Unable to create HuaweiCloud CCE client : %s", err) } + authenticating_proxy := make(map[string]string) if hasFilledOpt(d, "authenticating_proxy_ca") { authenticating_proxy["ca"] = d.Get("authenticating_proxy_ca").(string) @@ -236,8 +244,9 @@ func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error Cidr: d.Get("container_network_cidr").(string)}, Authentication: clusters.AuthenticationSpec{Mode: d.Get("authentication_mode").(string), AuthenticatingProxy: authenticating_proxy}, - BillingMode: d.Get("billing_mode").(int), - ExtendParam: resourceClusterExtendParamV3(d), + BillingMode: d.Get("billing_mode").(int), + ExtendParam: resourceClusterExtendParamV3(d), + //KubeProxyMode: d.Get("kube_proxy_mode").(string), }, } diff --git a/huaweicloud/resource_huaweicloud_cce_node_v3.go b/huaweicloud/resource_huaweicloud_cce_node_v3.go index 8a27a06a47..2b7f7f205a 100644 --- a/huaweicloud/resource_huaweicloud_cce_node_v3.go +++ b/huaweicloud/resource_huaweicloud_cce_node_v3.go @@ -123,6 +123,26 @@ func resourceCCENodeV3() *schema.Resource { }, }}, }, + "taints": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key": { + Type: schema.TypeString, + Required: true, + }, + "value": { + Type: schema.TypeString, + Required: true, + }, + "effect": { + Type: schema.TypeString, + Required: true, + }, + }}, + }, "eip_ids": { Type: schema.TypeSet, Optional: true, @@ -277,6 +297,19 @@ func resourceCCEDataVolume(d *schema.ResourceData) []nodes.VolumeSpec { } return volumes } +func resourceCCETaint(d *schema.ResourceData) []nodes.TaintSpec { + taintRaw := d.Get("taints").([]interface{}) + taints := make([]nodes.TaintSpec, len(taintRaw)) + for i, raw := range taintRaw { + rawMap := raw.(map[string]interface{}) + taints[i] = nodes.TaintSpec{ + Key: rawMap["key"].(string), + Value: rawMap["value"].(string), + Effect: rawMap["effect"].(string), + } + } + return taints +} func resourceCCERootVolume(d *schema.ResourceData) nodes.VolumeSpec { var nics nodes.VolumeSpec nicsRaw := d.Get("root_volume").([]interface{}) @@ -378,6 +411,7 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error { PreInstall: base64PreInstall, PostInstall: base64PostInstall, }, + Taints: resourceCCETaint(d), }, } @@ -490,11 +524,22 @@ func resourceCCENodeV3Read(d *schema.ResourceData, meta interface{}) error { "extend_param": s.Spec.RootVolume.ExtendParam, }, } - d.Set("root_volume", rootVolume) if err := d.Set("root_volume", rootVolume); err != nil { return fmt.Errorf("[DEBUG] Error saving root Volume to state for HuaweiCloud Node (%s): %s", d.Id(), err) } + var tains []map[string]interface{} + for _, pairObject := range s.Spec.Taints { + tain := make(map[string]interface{}) + tain["key"] = pairObject.Key + tain["value"] = pairObject.Value + tain["effect"] = pairObject.Effect + tains = append(tains, tain) + } + if err := d.Set("tains", tains); err != nil { + return fmt.Errorf("[DEBUG] Error saving root Volume to state for HuaweiCloud Node (%s): %s", d.Id(), err) + } + // set computed attributes d.Set("private_ip", s.Status.PrivateIP) d.Set("public_ip", s.Status.PublicIP) diff --git a/website/docs/r/cce_cluster_v3.html.md b/website/docs/r/cce_cluster_v3.html.md index 468a3ffd1d..8080f06379 100644 --- a/website/docs/r/cce_cluster_v3.html.md +++ b/website/docs/r/cce_cluster_v3.html.md @@ -64,7 +64,7 @@ versions are available, choose Dashboard > Buy Cluster on the CCE console. Chang * `subnet_id` - (Required) The ID of the subnet used to create the node. Changing this parameter will create a new cluster resource. -* `highway_subnet_id` - (Optional) The ID of the high speed network used to create bare metal nodes. Changing this parameter will create a new cluster resource. +* `highway_subnet_id` - (Optional) The ID of the high speed network used to create bare metal nodes. Changing this parameter will create a new cluster resource. * `container_network_type` - (Required) Container network parameters. Possible values: @@ -84,6 +84,11 @@ versions are available, choose Dashboard > Buy Cluster on the CCE console. Chang * `eip` - (Optional) EIP address of the cluster. Changing this parameter will create a new cluster resource. +* `kube_proxy_mode` - (Optional) Service forwarding mode. Two modes are available: + + - iptables: Traditional kube-proxy uses iptables rules to implement service load balancing. In this mode, too many iptables rules will be generated when many services are deployed. In addition, non-incremental updates will cause a latency and even obvious performance issues in the case of heavy service traffic. + - ipvs: Optimized kube-proxy mode with higher throughput and faster speed. This mode supports incremental updates and can keep connections uninterrupted during service updates. It is suitable for large-sized clusters. + ## Attributes Reference All above argument parameters can be exported as attribute parameters along with attribute reference. diff --git a/website/docs/r/cce_node_v3.html.md b/website/docs/r/cce_node_v3.html.md index e7fbb3b056..20076206d6 100644 --- a/website/docs/r/cce_node_v3.html.md +++ b/website/docs/r/cce_node_v3.html.md @@ -31,6 +31,11 @@ resource "huaweicloud_cce_node_v3" "node_1" { size = 100 volumetype = "SATA" } + taints { + key = "looks" + value = "bad" + effect = "NoSchedule" + } iptype = "5_bgp" sharetype = "PER" @@ -99,6 +104,16 @@ If the eip_id parameter is configured, you do not need to configure the bandwidt * `volumetype` - (Required) Disk type. * `extend_param` - (Optional) Disk expansion parameters. + +**taints** **- (Optional)** Represents the data disk to be created. Changing this parameter will create a new resource. + +* `key` - (Required) A key must contain 1 to 63 characters starting with a letter or digit. Only letters, digits, hyphens (-), + underscores (_), and periods (.) are allowed. A DNS subdomain name can be used as the prefix of a key. + +* `value` - (Required) A value must start with a letter or digit and can contain a maximum of 63 characters, including letters, + digits, hyphens (-), underscores (_), and periods (.). + +* `effect` - (Required) Available options are NoSchedule, PreferNoSchedule, and NoExecute. ## Attributes Reference