Skip to content
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

[CCE] Support eni network for turbo cluster opentelekomcloud_cce_cluster_v3 #1698

Merged
merged 6 commits into from Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/data-sources/cce_cluster_v3.md
Expand Up @@ -49,6 +49,10 @@ All above argument parameters can be exported as attribute parameters along with

* `container_network_type` - The container network type: overlay_l2 , underlay_ipvlan or vpc-router.

* `eni_subnet_id` - ENI subnet ID. Specified when creating a CCE Turbo cluster.

* `eni_subnet_cidr` - ENI network segment. Specified when creating a CCE Turbo cluster.
outcatcher marked this conversation as resolved.
Show resolved Hide resolved

* `authentication_mode` - (Optional) Authentication mode of the cluster, possible values are `rbac` and `authenticating_proxy`.

* `subnet_id` - The ID of the subnet used to create the node.
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/cce_cluster_v3.md
Expand Up @@ -120,6 +120,10 @@ The following arguments are supported:

* `container_network_cidr` - (Optional) Container network segment. Changing this parameter will create a new cluster resource.

* `eni_subnet_id` - The ENI subnet ID.

* `eni_subnet_cidr` - The ENI network segment.
outcatcher marked this conversation as resolved.
Show resolved Hide resolved

* `authentication_mode` - (Optional) Authentication mode of the cluster, possible values are `rbac` and `authenticating_proxy`.
Defaults to `rbac`. Changing this parameter will create a new cluster resource.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -14,7 +14,7 @@ require (
github.com/jen20/awspolicyequivalence v1.1.0
github.com/jinzhu/copier v0.2.3
github.com/mitchellh/go-homedir v1.1.0
github.com/opentelekomcloud/gophertelekomcloud v0.5.9-0.20220401102507-1f027860f666
github.com/opentelekomcloud/gophertelekomcloud v0.5.9
github.com/unknwon/com v1.0.1
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -297,8 +297,8 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/opentelekomcloud/gophertelekomcloud v0.5.9-0.20220401102507-1f027860f666 h1:2vbqkGtLZV0j2b5k9zi0nuyOV39sC3kdAj3TgE+cECk=
github.com/opentelekomcloud/gophertelekomcloud v0.5.9-0.20220401102507-1f027860f666/go.mod h1:pzEP1kduNwv+hrI9R6/DFU/NiX7Kr9NiFjpQ7kJQTsM=
github.com/opentelekomcloud/gophertelekomcloud v0.5.9 h1:cuSfJNGwYl99LNgHdMcRCoDaeuiSMHKgBviNfx4JcJ0=
github.com/opentelekomcloud/gophertelekomcloud v0.5.9/go.mod h1:pzEP1kduNwv+hrI9R6/DFU/NiX7Kr9NiFjpQ7kJQTsM=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
Expand Up @@ -55,6 +55,43 @@ func TestAccCCEClusterV3_basic(t *testing.T) {
})
}

func TestAccCCEClusterV3_turbo_basic(t *testing.T) {
var cluster clusters.Clusters
clusterName := randClusterName()
t.Parallel()
quotas.BookOne(t, quotas.CCEClusterQuota)

resource.Test(t, resource.TestCase{
PreCheck: func() { common.TestAccPreCheck(t) },
ProviderFactories: common.TestAccProviderFactories,
CheckDestroy: testAccCheckCCEClusterV3Destroy,
Steps: []resource.TestStep{
{
Config: testAccCCEClusterTurboV3Basic(clusterName),
Check: resource.ComposeTestCheckFunc(
testAccCheckCCEClusterV3Exists(resourceClusterName, &cluster),
resource.TestCheckResourceAttr(resourceClusterName, "name", clusterName),
resource.TestCheckResourceAttr(resourceClusterName, "status", "Available"),
resource.TestCheckResourceAttr(resourceClusterName, "cluster_type", "VirtualMachine"),
resource.TestCheckResourceAttr(resourceClusterName, "flavor_id", "cce.s1.small"),
resource.TestCheckResourceAttr(resourceClusterName, "container_network_type", "eni"),
resource.TestCheckResourceAttr(resourceClusterName, "authentication_mode", "rbac"),
resource.TestCheckResourceAttr(resourceClusterName, "kube_proxy_mode", "ipvs"),
resource.TestCheckResourceAttr(resourceClusterName, "kubernetes_svc_ip_range", "10.247.0.0/16"),
resource.TestCheckResourceAttrSet(resourceClusterName, "security_group_control"),
resource.TestCheckResourceAttrSet(resourceClusterName, "security_group_node"),
),
},
{
Config: testAccCCEClusterV3Update(clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceClusterName, "description", "new description"),
),
},
},
})
}

func TestAccCCEClusterV3_importBasic(t *testing.T) {
clusterName := randClusterName()
t.Parallel()
Expand Down Expand Up @@ -261,6 +298,25 @@ resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
`, common.DataSourceSubnet, clusterName)
}

func testAccCCEClusterTurboV3Basic(clusterName string) string {
return fmt.Sprintf(`
%s

resource "opentelekomcloud_cce_cluster_v3" "cluster_1" {
name = "%s"
cluster_type = "VirtualMachine"
flavor_id = "cce.s1.small"
vpc_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.vpc_id
subnet_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id
container_network_type = "eni"
kubernetes_svc_ip_range = "10.247.0.0/16"
ignore_addons = true
eni_subnet_id = data.opentelekomcloud_vpc_subnet_v1.shared_subnet.network_id
eni_subnet_cidr = "192.168.0.0/24"
}
`, common.DataSourceSubnet, clusterName)
}

func testAccCCEClusterV3Update(clusterName string) string {
return fmt.Sprintf(`
%s
Expand Down
Expand Up @@ -68,6 +68,14 @@ func DataSourceCCEClusterV3() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"eni_subnet_id": {
Type: schema.TypeString,
Computed: true,
},
"eni_subnet_cidr": {
Type: schema.TypeString,
Computed: true,
},
"authentication_mode": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -182,6 +190,8 @@ func dataSourceCCEClusterV3Read(_ context.Context, d *schema.ResourceData, meta
d.Set("highway_subnet_id", cluster.Spec.HostNetwork.HighwaySubnet),
d.Set("container_network_cidr", cluster.Spec.ContainerNetwork.Cidr),
d.Set("container_network_type", cluster.Spec.ContainerNetwork.Mode),
d.Set("eni_subnet_id", cluster.Spec.EniNetwork.SubnetId),
d.Set("eni_subnet_cidr", cluster.Spec.EniNetwork.Cidr),
d.Set("authentication_mode", cluster.Spec.Authentication.Mode),
d.Set("status", cluster.Status.Phase),
d.Set("internal", cluster.Status.Endpoints[0].Internal),
Expand Down
Expand Up @@ -140,6 +140,20 @@ func ResourceCCEClusterV3() *schema.Resource {
Computed: true,
ForceNew: true,
},
"eni_subnet_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
RequiredWith: []string{"eni_subnet_cidr"},
},
"eni_subnet_cidr": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
RequiredWith: []string{"eni_subnet_id"},
},
"authentication_mode": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -368,6 +382,14 @@ func resourceCCEClusterV3Create(ctx context.Context, d *schema.ResourceData, met
},
}

if _, ok := d.GetOk("eni_subnet_id"); ok {
eniNetwork := clusters.EniNetworkSpec{
SubnetId: d.Get("eni_subnet_id").(string),
Cidr: d.Get("eni_subnet_cidr").(string),
}
createOpts.Spec.EniNetwork = &eniNetwork
}

create, err := clusters.Create(cceClient, createOpts).Extract()

if err != nil {
Expand Down Expand Up @@ -446,6 +468,8 @@ func resourceCCEClusterV3Read(_ context.Context, d *schema.ResourceData, meta in
d.Set("highway_subnet_id", cluster.Spec.HostNetwork.HighwaySubnet),
d.Set("container_network_type", cluster.Spec.ContainerNetwork.Mode),
d.Set("container_network_cidr", cluster.Spec.ContainerNetwork.Cidr),
d.Set("eni_subnet_id", cluster.Spec.EniNetwork.SubnetId),
d.Set("eni_subnet_cidr", cluster.Spec.EniNetwork.Cidr),
d.Set("authentication_mode", cluster.Spec.Authentication.Mode),
d.Set("kubernetes_svc_ip_range", cluster.Spec.KubernetesSvcIpRange),
d.Set("kube_proxy_mode", cluster.Spec.KubeProxyMode),
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/cce-eni-turbo-26ff5dd4de1ab99f.yaml
@@ -0,0 +1,6 @@
---
enhancements:
- |
**[CCE]** Support eni network for turbo cluster ``resource/opentelekomcloud_cce_cluster_v3``
and ``data_source/opentelekomcloud_cce_cluster_v3``.
(`#1698 <https://github.com/opentelekomcloud/terraform-provider-opentelekomcloud/pull/1698>`_)