Skip to content

Commit 7bb8b80

Browse files
XinruXiao-9sagarp337
authored andcommitted
Added - Support for IPv6 on OKE
1 parent dbccb47 commit 7bb8b80

File tree

6 files changed

+212
-3
lines changed

6 files changed

+212
-3
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {}
5+
variable "region" {
6+
default = "us-ashburn-1"
7+
}
8+
variable "compartment_ocid" {}
9+
10+
provider "oci" {
11+
tenancy_ocid = var.tenancy_ocid
12+
auth = "SecurityToken"
13+
config_file_profile = "terraform-federation-test"
14+
region = var.region
15+
}
16+
17+
data "oci_identity_availability_domain" "ad1" {
18+
compartment_id = var.tenancy_ocid
19+
ad_number = 1
20+
}
21+
22+
data "oci_identity_availability_domain" "ad2" {
23+
compartment_id = var.tenancy_ocid
24+
ad_number = 2
25+
}
26+
27+
data "oci_containerengine_cluster_option" "test_cluster_option" {
28+
cluster_option_id = "all"
29+
}
30+
31+
resource "oci_core_vcn" "test_vcn" {
32+
cidr_block = "10.0.0.0/16"
33+
compartment_id = var.compartment_ocid
34+
display_name = "tfDualStackVcnForClusters"
35+
is_ipv6enabled = true
36+
is_oracle_gua_allocation_enabled = true
37+
}
38+
39+
40+
resource "oci_core_internet_gateway" "test_ig" {
41+
compartment_id = var.compartment_ocid
42+
display_name = "tfClusterInternetGateway"
43+
vcn_id = oci_core_vcn.test_vcn.id
44+
}
45+
resource "oci_core_route_table" "test_route_table" {
46+
compartment_id = var.compartment_ocid
47+
vcn_id = oci_core_vcn.test_vcn.id
48+
display_name = "tfClustersRouteTable"
49+
route_rules {
50+
destination = "0.0.0.0/0"
51+
destination_type = "CIDR_BLOCK"
52+
network_entity_id = oci_core_internet_gateway.test_ig.id
53+
}
54+
}
55+
resource "oci_core_subnet" "test_subnet" {
56+
#Required
57+
cidr_block = "10.0.20.0/24"
58+
compartment_id = var.compartment_ocid
59+
vcn_id = oci_core_vcn.test_vcn.id
60+
# Provider code tries to maintain compatibility with old versions.
61+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
62+
display_name = "tfSubNet1ForNodePool"
63+
route_table_id = oci_core_route_table.test_route_table.id
64+
ipv6cidr_block = cidrsubnet(oci_core_vcn.test_vcn.ipv6cidr_blocks[0], 8, 1) # Creating a /64 subnet from /56
65+
}
66+
resource "oci_core_security_list" "test_security_list" {
67+
compartment_id = var.compartment_ocid
68+
vcn_id = oci_core_vcn.test_vcn.id
69+
display_name = "Default Security List for virtual node pool"
70+
egress_security_rules {
71+
destination = "0.0.0.0/0"
72+
destination_type = "CIDR_BLOCK"
73+
protocol = "all"
74+
stateless = false
75+
description = "Allowing egress to all via all protocols."
76+
}
77+
ingress_security_rules {
78+
source = "10.0.0.0/16"
79+
source_type = "CIDR_BLOCK"
80+
protocol = "all"
81+
stateless = false
82+
}
83+
ingress_security_rules {
84+
protocol = 6 # local.TCP
85+
source = "0.0.0.0/0"
86+
source_type = "CIDR_BLOCK"
87+
stateless = false
88+
description = "Allowing ingress to all via TCP"
89+
# Optional
90+
tcp_options {
91+
max = "6443"
92+
min = "6443"
93+
source_port_range {
94+
max = "1521"
95+
min = "1521"
96+
}
97+
}
98+
}
99+
ingress_security_rules {
100+
# Optional
101+
icmp_options {
102+
code = "4"
103+
type = "3"
104+
}
105+
protocol = 1 # local.ICMP
106+
source = "0.0.0.0/0"
107+
source_type = "CIDR_BLOCK"
108+
stateless = false
109+
description = "Allowing ingress to all via ICMP"
110+
}
111+
ingress_security_rules {
112+
# Optional
113+
icmp_options {
114+
code = "-1"
115+
type = "3"
116+
}
117+
protocol = 1 # local.ICMP
118+
source = "10.0.0.0/16"
119+
source_type = "CIDR_BLOCK"
120+
stateless = false
121+
}
122+
}
123+
124+
# Create a dual stack cluster
125+
resource "oci_containerengine_cluster" "test_cluster" {
126+
#Required
127+
compartment_id = var.compartment_ocid
128+
kubernetes_version = reverse(data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions)[0]
129+
name = "tfTestClusterDualStack"
130+
vcn_id = oci_core_vcn.test_vcn.id
131+
type = "ENHANCED_CLUSTER"
132+
cluster_pod_network_options {
133+
# VNPs require cni_type as OCI_VCN_IP_NATIVE
134+
cni_type = "OCI_VCN_IP_NATIVE"
135+
}
136+
options {
137+
ip_families = ["IPv4", "IPv6"]
138+
}
139+
endpoint_config {
140+
#Optional
141+
is_public_ip_enabled = true
142+
nsg_ids = ["${oci_core_network_security_group.network_security_group_rd.id}"]
143+
subnet_id = oci_core_subnet.test_subnet.id
144+
}
145+
}
146+
resource "oci_core_network_security_group" "network_security_group_rd" {
147+
compartment_id = var.compartment_ocid
148+
vcn_id = oci_core_vcn.test_vcn.id
149+
display_name = "displayName"
150+
}

internal/integrationtest/containerengine_cluster_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ var (
8484
"key_details": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterImagePolicyConfigKeyDetailsRepresentation},
8585
}
8686
ContainerengineClusterOptionsRepresentation = map[string]interface{}{
87-
"add_ons": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsAddOnsRepresentation},
88-
"admission_controller_options": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsAdmissionControllerOptionsRepresentation},
89-
"kubernetes_network_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsKubernetesNetworkConfigRepresentation},
87+
"add_ons": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsAddOnsRepresentation},
88+
"admission_controller_options": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsAdmissionControllerOptionsRepresentation},
89+
"ip_families": acctest.Representation{RepType: acctest.Optional, Create: []string{`IPv4`}},
90+
"kubernetes_network_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsKubernetesNetworkConfigRepresentation},
9091
"open_id_connect_token_authentication_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsOpenIdConnectTokenAuthenticationConfigRepresentation},
9192
"open_id_connect_discovery": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsOpenIdConnectDiscoveryRepresentation},
9293
"persistent_volume_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsPersistentVolumeConfigRepresentation},
@@ -209,6 +210,9 @@ func TestContainerengineClusterResource_basic(t *testing.T) {
209210
resource.TestCheckResourceAttr(resourceName, "options.0.add_ons.#", "1"),
210211
resource.TestCheckResourceAttr(resourceName, "options.0.add_ons.0.is_kubernetes_dashboard_enabled", "true"),
211212
resource.TestCheckResourceAttr(resourceName, "options.0.add_ons.0.is_tiller_enabled", "true"),
213+
resource.TestCheckResourceAttr(resourceName, "options.0.admission_controller_options.#", "1"),
214+
resource.TestCheckResourceAttr(resourceName, "options.0.admission_controller_options.0.is_pod_security_policy_enabled", "false"),
215+
resource.TestCheckResourceAttr(resourceName, "options.0.ip_families.#", "1"),
212216
resource.TestCheckResourceAttr(resourceName, "options.0.kubernetes_network_config.#", "1"),
213217
resource.TestCheckResourceAttr(resourceName, "options.0.kubernetes_network_config.0.pods_cidr", "10.1.0.0/16"),
214218
resource.TestCheckResourceAttr(resourceName, "options.0.kubernetes_network_config.0.services_cidr", "10.2.0.0/16"),
@@ -272,6 +276,9 @@ func TestContainerengineClusterResource_basic(t *testing.T) {
272276
resource.TestCheckResourceAttr(resourceName, "options.0.add_ons.#", "1"),
273277
resource.TestCheckResourceAttr(resourceName, "options.0.add_ons.0.is_kubernetes_dashboard_enabled", "true"),
274278
resource.TestCheckResourceAttr(resourceName, "options.0.add_ons.0.is_tiller_enabled", "true"),
279+
resource.TestCheckResourceAttr(resourceName, "options.0.admission_controller_options.#", "1"),
280+
resource.TestCheckResourceAttr(resourceName, "options.0.admission_controller_options.0.is_pod_security_policy_enabled", "false"),
281+
resource.TestCheckResourceAttr(resourceName, "options.0.ip_families.#", "1"),
275282
resource.TestCheckResourceAttr(resourceName, "options.0.kubernetes_network_config.#", "1"),
276283
resource.TestCheckResourceAttr(resourceName, "options.0.kubernetes_network_config.0.pods_cidr", "10.1.0.0/16"),
277284
resource.TestCheckResourceAttr(resourceName, "options.0.kubernetes_network_config.0.services_cidr", "10.2.0.0/16"),
@@ -327,6 +334,8 @@ func TestContainerengineClusterResource_basic(t *testing.T) {
327334
resource.TestCheckResourceAttr(datasourceName, "clusters.0.options.0.add_ons.#", "1"),
328335
resource.TestCheckResourceAttr(datasourceName, "clusters.0.options.0.add_ons.0.is_kubernetes_dashboard_enabled", "true"),
329336
resource.TestCheckResourceAttr(datasourceName, "clusters.0.options.0.add_ons.0.is_tiller_enabled", "true"),
337+
resource.TestCheckResourceAttr(datasourceName, "clusters.0.options.0.admission_controller_options.#", "1"),
338+
resource.TestCheckResourceAttr(datasourceName, "clusters.0.options.0.ip_families.#", "1"),
330339
resource.TestCheckResourceAttr(datasourceName, "clusters.0.options.0.kubernetes_network_config.#", "1"),
331340
resource.TestCheckResourceAttr(datasourceName, "clusters.0.options.0.kubernetes_network_config.0.pods_cidr", "10.1.0.0/16"),
332341
resource.TestCheckResourceAttr(datasourceName, "clusters.0.options.0.kubernetes_network_config.0.services_cidr", "10.2.0.0/16"),
@@ -384,6 +393,7 @@ func TestContainerengineClusterResource_basic(t *testing.T) {
384393
resource.TestCheckResourceAttr(singularDatasourceName, "options.0.add_ons.0.is_kubernetes_dashboard_enabled", "true"),
385394
resource.TestCheckResourceAttr(singularDatasourceName, "options.0.add_ons.0.is_tiller_enabled", "true"),
386395
resource.TestCheckResourceAttr(singularDatasourceName, "options.0.admission_controller_options.#", "1"),
396+
resource.TestCheckResourceAttr(singularDatasourceName, "options.0.ip_families.#", "1"),
387397
resource.TestCheckResourceAttr(singularDatasourceName, "options.0.admission_controller_options.0.is_pod_security_policy_enabled", "false"),
388398
resource.TestCheckResourceAttr(singularDatasourceName, "options.0.kubernetes_network_config.#", "1"),
389399
resource.TestCheckResourceAttr(singularDatasourceName, "options.0.kubernetes_network_config.0.pods_cidr", "10.1.0.0/16"),

internal/service/containerengine/containerengine_cluster_resource.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ func ContainerengineClusterResource() *schema.Resource {
230230
},
231231
},
232232
},
233+
"ip_families": {
234+
Type: schema.TypeList,
235+
Optional: true,
236+
Computed: true,
237+
ForceNew: true,
238+
Elem: &schema.Schema{
239+
Type: schema.TypeString,
240+
},
241+
},
233242
"kubernetes_network_config": {
234243
Type: schema.TypeList,
235244
Optional: true,
@@ -463,6 +472,10 @@ func ContainerengineClusterResource() *schema.Resource {
463472
// Optional
464473

465474
// Computed
475+
"ipv6endpoint": {
476+
Type: schema.TypeString,
477+
Computed: true,
478+
},
466479
"kubernetes": {
467480
Type: schema.TypeString,
468481
Computed: true,
@@ -1194,6 +1207,15 @@ func (s *ContainerengineClusterResourceCrud) mapToAddOnOptions(fieldKeyFormat st
11941207
return result, nil
11951208
}
11961209

1210+
// Helper function to convert []string to []containerengine.ClusterCreateOptionsIpFamiliesEnum
1211+
func convertToClusterCreateOptionsIpFamiliesEnum(input []string) []oci_containerengine.ClusterCreateOptionsIpFamiliesEnum {
1212+
output := make([]oci_containerengine.ClusterCreateOptionsIpFamiliesEnum, len(input))
1213+
for i, v := range input {
1214+
output[i] = oci_containerengine.ClusterCreateOptionsIpFamiliesEnum(v)
1215+
}
1216+
return output
1217+
}
1218+
11971219
func AddOnOptionsToMap(obj *oci_containerengine.AddOnOptions) map[string]interface{} {
11981220
result := map[string]interface{}{}
11991221

@@ -1254,6 +1276,19 @@ func (s *ContainerengineClusterResourceCrud) mapToClusterCreateOptions(fieldKeyF
12541276
}
12551277
}
12561278

1279+
if ipFamilies, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "ip_families")); ok {
1280+
interfaces := ipFamilies.([]interface{})
1281+
tmp := make([]string, len(interfaces))
1282+
for i := range interfaces {
1283+
if interfaces[i] != nil {
1284+
tmp[i] = interfaces[i].(string)
1285+
}
1286+
}
1287+
if len(tmp) != 0 || s.D.HasChange(fmt.Sprintf(fieldKeyFormat, "ip_families")) {
1288+
result.IpFamilies = convertToClusterCreateOptionsIpFamiliesEnum(tmp)
1289+
}
1290+
}
1291+
12571292
if kubernetesNetworkConfig, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "kubernetes_network_config")); ok {
12581293
if tmpList := kubernetesNetworkConfig.([]interface{}); len(tmpList) > 0 {
12591294
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "kubernetes_network_config"), 0)
@@ -1397,6 +1432,8 @@ func ClusterCreateOptionsToMap(obj *oci_containerengine.ClusterCreateOptions) ma
13971432
result["admission_controller_options"] = []interface{}{AdmissionControllerOptionsToMap(obj.AdmissionControllerOptions)}
13981433
}
13991434

1435+
result["ip_families"] = obj.IpFamilies
1436+
14001437
if obj.KubernetesNetworkConfig != nil {
14011438
result["kubernetes_network_config"] = []interface{}{KubernetesNetworkConfigToMap(obj.KubernetesNetworkConfig)}
14021439
}
@@ -1425,6 +1462,10 @@ func ClusterCreateOptionsToMap(obj *oci_containerengine.ClusterCreateOptions) ma
14251462
func ClusterEndpointsToMap(obj *oci_containerengine.ClusterEndpoints) map[string]interface{} {
14261463
result := map[string]interface{}{}
14271464

1465+
if obj.Ipv6Endpoint != nil {
1466+
result["ipv6endpoint"] = string(*obj.Ipv6Endpoint)
1467+
}
1468+
14281469
if obj.Kubernetes != nil {
14291470
result["kubernetes"] = string(*obj.Kubernetes)
14301471
}

website/docs/d/containerengine_cluster.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The following attributes are exported:
4242
* `nsg_ids` - A list of the OCIDs of the network security groups (NSGs) to apply to the cluster endpoint. For more information about NSGs, see [NetworkSecurityGroup](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/NetworkSecurityGroup/).
4343
* `subnet_id` - The OCID of the regional subnet in which to place the Cluster endpoint.
4444
* `endpoints` - Endpoints served up by the cluster masters.
45+
* `ipv6endpoint` - The IPv6 networking Kubernetes API server endpoint.
4546
* `kubernetes` - The non-native networking Kubernetes API server endpoint.
4647
* `private_endpoint` - The private native networking Kubernetes API server endpoint.
4748
* `public_endpoint` - The public native networking Kubernetes API server endpoint, if one was requested.
@@ -73,6 +74,7 @@ The following attributes are exported:
7374
* `is_tiller_enabled` - Whether or not to enable the Tiller add-on.
7475
* `admission_controller_options` - Configurable cluster admission controllers
7576
* `is_pod_security_policy_enabled` - Whether or not to enable the Pod Security Policy admission controller.
77+
* `ip_families` - IP family to use for single stack or define the order of IP families for dual-stack
7678
* `kubernetes_network_config` - Network configuration for Kubernetes.
7779
* `pods_cidr` - The CIDR block for Kubernetes pods. Optional, defaults to 10.244.0.0/16.
7880
* `services_cidr` - The CIDR block for Kubernetes services. Optional, defaults to 10.96.0.0/16.

website/docs/d/containerengine_clusters.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The following attributes are exported:
5454
* `nsg_ids` - A list of the OCIDs of the network security groups (NSGs) to apply to the cluster endpoint. For more information about NSGs, see [NetworkSecurityGroup](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/NetworkSecurityGroup/).
5555
* `subnet_id` - The OCID of the regional subnet in which to place the Cluster endpoint.
5656
* `endpoints` - Endpoints served up by the cluster masters.
57+
* `ipv6endpoint` - The IPv6 networking Kubernetes API server endpoint.
5758
* `kubernetes` - The non-native networking Kubernetes API server endpoint.
5859
* `private_endpoint` - The private native networking Kubernetes API server endpoint.
5960
* `public_endpoint` - The public native networking Kubernetes API server endpoint, if one was requested.
@@ -86,6 +87,7 @@ The following attributes are exported:
8687
* `is_tiller_enabled` - Whether or not to enable the Tiller add-on.
8788
* `admission_controller_options` - Configurable cluster admission controllers
8889
* `is_pod_security_policy_enabled` - Whether or not to enable the Pod Security Policy admission controller.
90+
* `ip_families` - IP family to use for single stack or define the order of IP families for dual-stack
8991
* `kubernetes_network_config` - Network configuration for Kubernetes.
9092
* `pods_cidr` - The CIDR block for Kubernetes pods. Optional, defaults to 10.244.0.0/16.
9193
* `services_cidr` - The CIDR block for Kubernetes services. Optional, defaults to 10.96.0.0/16.

website/docs/r/containerengine_cluster.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ resource "oci_containerengine_cluster" "test_cluster" {
6161
#Optional
6262
is_pod_security_policy_enabled = var.cluster_options_admission_controller_options_is_pod_security_policy_enabled
6363
}
64+
ip_families = var.cluster_options_ip_families
6465
kubernetes_network_config {
6566
6667
#Optional
@@ -136,6 +137,7 @@ The following arguments are supported:
136137
* `is_tiller_enabled` - (Optional) Whether or not to enable the Tiller add-on.
137138
* `admission_controller_options` - (Optional) (Updatable) Configurable cluster admission controllers
138139
* `is_pod_security_policy_enabled` - (Optional) (Updatable) Whether or not to enable the Pod Security Policy admission controller.
140+
* `ip_families` - (Optional) IP family to use for single stack or define the order of IP families for dual-stack
139141
* `kubernetes_network_config` - (Optional) Network configuration for Kubernetes.
140142
* `pods_cidr` - (Optional) The CIDR block for Kubernetes pods. Optional, defaults to 10.244.0.0/16.
141143
* `services_cidr` - (Optional) The CIDR block for Kubernetes services. Optional, defaults to 10.96.0.0/16.
@@ -182,6 +184,7 @@ The following attributes are exported:
182184
* `nsg_ids` - A list of the OCIDs of the network security groups (NSGs) to apply to the cluster endpoint. For more information about NSGs, see [NetworkSecurityGroup](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/NetworkSecurityGroup/).
183185
* `subnet_id` - The OCID of the regional subnet in which to place the Cluster endpoint.
184186
* `endpoints` - Endpoints served up by the cluster masters.
187+
* `ipv6endpoint` - The IPv6 networking Kubernetes API server endpoint.
185188
* `kubernetes` - The non-native networking Kubernetes API server endpoint.
186189
* `private_endpoint` - The private native networking Kubernetes API server endpoint.
187190
* `public_endpoint` - The public native networking Kubernetes API server endpoint, if one was requested.
@@ -214,6 +217,7 @@ The following attributes are exported:
214217
* `is_tiller_enabled` - Whether or not to enable the Tiller add-on.
215218
* `admission_controller_options` - Configurable cluster admission controllers
216219
* `is_pod_security_policy_enabled` - Whether or not to enable the Pod Security Policy admission controller.
220+
* `ip_families` - IP family to use for single stack or define the order of IP families for dual-stack
217221
* `kubernetes_network_config` - Network configuration for Kubernetes.
218222
* `pods_cidr` - The CIDR block for Kubernetes pods. Optional, defaults to 10.244.0.0/16.
219223
* `services_cidr` - The CIDR block for Kubernetes services. Optional, defaults to 10.96.0.0/16.

0 commit comments

Comments
 (0)