Skip to content

Commit b736900

Browse files
sohan-oracleMeharwadeDivya
authored andcommitted
Added - Support for Native Pod Networking
1 parent 1d4c6bb commit b736900

13 files changed

+536
-13
lines changed
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {
5+
}
6+
7+
variable "user_ocid" {
8+
}
9+
10+
variable "fingerprint" {
11+
}
12+
13+
variable "private_key_path" {
14+
}
15+
16+
variable "compartment_ocid" {
17+
}
18+
19+
variable "region" {
20+
default = "us-ashburn-1"
21+
}
22+
23+
variable "cluster_cluster_pod_network_options_cni_type" {
24+
default = "OCI_VCN_IP_NATIVE"
25+
}
26+
27+
variable "node_pool_node_config_details_node_pool_pod_network_option_details_cni_type" {
28+
default = "OCI_VCN_IP_NATIVE"
29+
}
30+
31+
variable "node_pool_node_config_details_node_pool_pod_network_option_details_max_pods_per_node" {
32+
default = 10
33+
}
34+
35+
variable "node_pool_node_config_details_node_pool_pod_network_option_details_pod_nsg_ids" {
36+
default = []
37+
}
38+
39+
variable "node_pool_node_config_details_node_pool_pod_network_option_details_pod_subnet_ids" {
40+
default = []
41+
}
42+
43+
# Provide the SSH public key to be set on each node in the node pool on launch.
44+
variable "node_pool_ssh_public_key" {
45+
default = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOuBJgh6lTmQvQJ4BA3RCJdSmxRtmiXAQEEIP68/G4gF3XuZdKEYTFeputacmRq9yO5ZnNXgO9akdUgePpf8+CfFtveQxmN5xo3HVCDKxu/70lbMgeu7+wJzrMOlzj+a4zNq2j0Ww2VWMsisJ6eV3bJTnO/9VLGCOC8M9noaOlcKcLgIYy4aDM724MxFX2lgn7o6rVADHRxkvLEXPVqYT4syvYw+8OVSnNgE4MJLxaw8/2K0qp19YlQyiriIXfQpci3ThxwLjymYRPj+kjU1xIxv6qbFQzHR7ds0pSWp1U06cIoKPfCazU9hGWW8yIe/vzfTbWrt2DK6pLwBn/G0x3 sample"
46+
}
47+
48+
variable "node_pool_node_config_details_size" {
49+
default = 1
50+
}
51+
52+
provider "oci" {
53+
region = var.region
54+
tenancy_ocid = var.tenancy_ocid
55+
user_ocid = var.user_ocid
56+
fingerprint = var.fingerprint
57+
private_key_path = var.private_key_path
58+
}
59+
60+
data "oci_identity_availability_domain" "ad1" {
61+
compartment_id = var.tenancy_ocid
62+
ad_number = 1
63+
}
64+
65+
data "oci_identity_availability_domain" "ad2" {
66+
compartment_id = var.tenancy_ocid
67+
ad_number = 2
68+
}
69+
70+
resource "oci_core_vcn" "test_vcn" {
71+
cidr_block = "10.0.0.0/16"
72+
compartment_id = var.compartment_ocid
73+
display_name = "tfVcnForClusters"
74+
}
75+
76+
resource "oci_core_internet_gateway" "test_ig" {
77+
compartment_id = var.compartment_ocid
78+
display_name = "tfClusterInternetGateway"
79+
vcn_id = oci_core_vcn.test_vcn.id
80+
}
81+
82+
resource "oci_core_route_table" "test_route_table" {
83+
compartment_id = var.compartment_ocid
84+
vcn_id = oci_core_vcn.test_vcn.id
85+
display_name = "tfClustersRouteTable"
86+
87+
route_rules {
88+
destination = "0.0.0.0/0"
89+
destination_type = "CIDR_BLOCK"
90+
network_entity_id = oci_core_internet_gateway.test_ig.id
91+
}
92+
}
93+
94+
resource "oci_core_subnet" "nodePool_Subnet_1" {
95+
#Required
96+
cidr_block = "10.0.22.0/24"
97+
compartment_id = var.compartment_ocid
98+
vcn_id = oci_core_vcn.test_vcn.id
99+
100+
# Provider code tries to maintain compatibility with old versions.
101+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
102+
display_name = "tfSubNet1ForNodePool"
103+
route_table_id = oci_core_route_table.test_route_table.id
104+
}
105+
106+
resource "oci_core_subnet" "clusterSubnet_1" {
107+
#Required
108+
cidr_block = "10.0.21.0/24"
109+
compartment_id = var.compartment_ocid
110+
vcn_id = oci_core_vcn.test_vcn.id
111+
display_name = "tfSubNet1ForClusters"
112+
113+
# Provider code tries to maintain compatibility with old versions.
114+
security_list_ids = [oci_core_vcn.test_vcn.default_security_list_id]
115+
route_table_id = oci_core_route_table.test_route_table.id
116+
}
117+
118+
resource "oci_containerengine_cluster" "test_npn_cluster" {
119+
#Required
120+
compartment_id = var.compartment_ocid
121+
kubernetes_version = "v1.23.4"
122+
name = "tfTestCluster"
123+
vcn_id = oci_core_vcn.test_vcn.id
124+
125+
cluster_pod_network_options {
126+
#Required
127+
cni_type = var.cluster_cluster_pod_network_options_cni_type
128+
}
129+
130+
#Optional
131+
options {
132+
service_lb_subnet_ids = [oci_core_subnet.clusterSubnet_1.id]
133+
}
134+
135+
# required regional subnet for Native Pod Networking
136+
endpoint_config {
137+
subnet_id = oci_core_subnet.clusterSubnet_1.id
138+
}
139+
}
140+
141+
resource "oci_containerengine_node_pool" "test_node_pool" {
142+
#Required
143+
cluster_id = oci_containerengine_cluster.test_npn_cluster.id
144+
compartment_id = var.compartment_ocid
145+
kubernetes_version = "v1.23.4"
146+
name = "tfPool"
147+
node_shape = "VM.Standard2.1"
148+
149+
#Optional
150+
initial_node_labels {
151+
#Optional
152+
key = "key"
153+
value = "value"
154+
}
155+
156+
node_source_details {
157+
#Required
158+
image_id = local.image_id
159+
source_type = "IMAGE"
160+
}
161+
162+
node_config_details {
163+
#Required
164+
placement_configs {
165+
#Required
166+
availability_domain = data.oci_identity_availability_domain.ad1.name
167+
subnet_id = oci_core_subnet.nodePool_Subnet_1.id
168+
}
169+
size = var.node_pool_node_config_details_size
170+
171+
node_pool_pod_network_option_details {
172+
#Required
173+
cni_type = var.node_pool_node_config_details_node_pool_pod_network_option_details_cni_type
174+
175+
#Optional
176+
max_pods_per_node = var.node_pool_node_config_details_node_pool_pod_network_option_details_max_pods_per_node
177+
pod_nsg_ids = var.node_pool_node_config_details_node_pool_pod_network_option_details_pod_nsg_ids
178+
pod_subnet_ids = [oci_core_subnet.nodePool_Subnet_1.id]
179+
}
180+
}
181+
182+
ssh_public_key = var.node_pool_ssh_public_key
183+
}
184+
185+
data "oci_containerengine_cluster_kube_config" "test_cluster_kube_config" {
186+
#Required
187+
cluster_id = oci_containerengine_cluster.test_npn_cluster.id
188+
}
189+
190+
output "node_pool" {
191+
value = {
192+
id = oci_containerengine_node_pool.test_node_pool.id
193+
kubernetes_version = oci_containerengine_node_pool.test_node_pool.kubernetes_version
194+
name = oci_containerengine_node_pool.test_node_pool.name
195+
subnet_ids = oci_containerengine_node_pool.test_node_pool.subnet_ids
196+
}
197+
}
198+
199+
output "cluster" {
200+
value = {
201+
kubeconfig = data.oci_containerengine_cluster_kube_config.test_cluster_kube_config.content
202+
}
203+
}
204+
205+
data "oci_containerengine_node_pool_option" "test_node_pool_option" {
206+
node_pool_option_id = "all"
207+
}
208+
209+
data "oci_core_images" "shape_specific_images" {
210+
#Required
211+
compartment_id = var.tenancy_ocid
212+
shape = "VM.Standard2.1"
213+
}
214+
215+
216+
locals {
217+
all_images = "${data.oci_core_images.shape_specific_images.images}"
218+
all_sources = "${data.oci_containerengine_node_pool_option.test_node_pool_option.sources}"
219+
220+
compartment_images = [for image in local.all_images : image.id if length(regexall("Oracle-Linux-[0-9]*.[0-9]*-20[0-9]*",image.display_name)) > 0 ]
221+
222+
oracle_linux_images = [for source in local.all_sources : source.image_id if length(regexall("Oracle-Linux-[0-9]*.[0-9]*-20[0-9]*",source.source_name)) > 0]
223+
224+
image_id = tolist(setintersection( toset(local.compartment_images), toset(local.oracle_linux_images)))[0]
225+
}

internal/integrationtest/containerengine_cluster_option_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestContainerengineClusterOptionResource_basic(t *testing.T) {
5858
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
5959
resource.TestCheckResourceAttrSet(singularDatasourceName, "cluster_option_id"),
6060
resource.TestCheckResourceAttr(singularDatasourceName, "compartment_id", compartmentId),
61-
61+
resource.TestCheckResourceAttr(singularDatasourceName, "cluster_pod_network_options.#", "2"),
6262
resource.TestMatchResourceAttr(singularDatasourceName, "kubernetes_versions.#", regexp.MustCompile("[1-9][0-9]*")),
6363
),
6464
},

internal/integrationtest/containerengine_cluster_test.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,21 @@ var (
3838
"name": acctest.Representation{RepType: acctest.Required, Create: `id`},
3939
"values": acctest.Representation{RepType: acctest.Required, Create: []string{`${oci_containerengine_cluster.test_cluster.id}`}},
4040
}
41-
4241
ContainerengineClusterRepresentation = map[string]interface{}{
43-
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
44-
"kubernetes_version": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions[length(data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions)-2]}`, Update: `${data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions[length(data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions)-1]}`},
45-
"name": acctest.Representation{RepType: acctest.Required, Create: `name`, Update: `name2`},
46-
"vcn_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_vcn.test_vcn.id}`},
47-
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
48-
"endpoint_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterEndpointConfigRepresentation},
49-
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
50-
"image_policy_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterImagePolicyConfigRepresentation},
51-
"kms_key_id": acctest.Representation{RepType: acctest.Optional, Create: `${lookup(data.oci_kms_keys.test_keys_dependency.keys[0], "id")}`},
52-
"options": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsRepresentation},
42+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
43+
"kubernetes_version": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions[length(data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions)-2]}`, Update: `${data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions[length(data.oci_containerengine_cluster_option.test_cluster_option.kubernetes_versions)-1]}`},
44+
"name": acctest.Representation{RepType: acctest.Required, Create: `name`, Update: `name2`},
45+
"vcn_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_vcn.test_vcn.id}`},
46+
"cluster_pod_network_options": acctest.RepresentationGroup{RepType: acctest.Optional, Group: clusterClusterPodNetworkOptionsRepresentation},
47+
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
48+
"endpoint_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterEndpointConfigRepresentation},
49+
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"Department": "Finance"}, Update: map[string]string{"Department": "Accounting"}},
50+
"image_policy_config": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterImagePolicyConfigRepresentation},
51+
"kms_key_id": acctest.Representation{RepType: acctest.Optional, Create: `${lookup(data.oci_kms_keys.test_keys_dependency.keys[0], "id")}`},
52+
"options": acctest.RepresentationGroup{RepType: acctest.Optional, Group: ContainerengineClusterOptionsRepresentation},
53+
}
54+
clusterClusterPodNetworkOptionsRepresentation = map[string]interface{}{
55+
"cni_type": acctest.Representation{RepType: acctest.Required, Create: `OCI_VCN_IP_NATIVE`},
5356
}
5457
ContainerengineClusterEndpointConfigRepresentation = map[string]interface{}{
5558
"is_public_ip_enabled": acctest.Representation{RepType: acctest.Optional, Create: `true`, Update: `false`},
@@ -149,6 +152,8 @@ func TestContainerengineClusterResource_basic(t *testing.T) {
149152
Config: config + compartmentIdVariableStr + ContainerengineClusterResourceDependencies +
150153
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Create, ContainerengineClusterRepresentation),
151154
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
155+
resource.TestCheckResourceAttr(resourceName, "cluster_pod_network_options.#", "1"),
156+
resource.TestCheckResourceAttr(resourceName, "cluster_pod_network_options.0.cni_type", "OCI_VCN_IP_NATIVE"),
152157
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
153158
resource.TestCheckResourceAttr(resourceName, "endpoint_config.#", "1"),
154159
resource.TestCheckResourceAttr(resourceName, "endpoint_config.0.is_public_ip_enabled", "true"),
@@ -193,6 +198,8 @@ func TestContainerengineClusterResource_basic(t *testing.T) {
193198
Config: config + compartmentIdVariableStr + ContainerengineClusterResourceDependencies +
194199
acctest.GenerateResourceFromRepresentationMap("oci_containerengine_cluster", "test_cluster", acctest.Optional, acctest.Update, ContainerengineClusterRepresentation),
195200
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
201+
resource.TestCheckResourceAttr(resourceName, "cluster_pod_network_options.#", "1"),
202+
resource.TestCheckResourceAttr(resourceName, "cluster_pod_network_options.0.cni_type", "OCI_VCN_IP_NATIVE"),
196203
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
197204
resource.TestCheckResourceAttr(resourceName, "endpoint_config.#", "1"),
198205
resource.TestCheckResourceAttr(resourceName, "endpoint_config.0.is_public_ip_enabled", "false"),
@@ -243,8 +250,9 @@ func TestContainerengineClusterResource_basic(t *testing.T) {
243250
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
244251
resource.TestCheckResourceAttr(datasourceName, "name", "name2"),
245252
resource.TestCheckResourceAttr(datasourceName, "state.#", "6"),
246-
247253
resource.TestCheckResourceAttr(datasourceName, "clusters.#", "1"),
254+
resource.TestCheckResourceAttr(datasourceName, "clusters.0.cluster_pod_network_options.#", "1"),
255+
resource.TestCheckResourceAttr(datasourceName, "clusters.0.cluster_pod_network_options.0.cni_type", "OCI_VCN_IP_NATIVE"),
248256
resource.TestCheckResourceAttr(datasourceName, "clusters.0.available_kubernetes_upgrades.#", "0"),
249257
resource.TestCheckResourceAttr(datasourceName, "clusters.0.compartment_id", compartmentId),
250258
resource.TestCheckResourceAttr(datasourceName, "clusters.0.endpoint_config.#", "1"),

internal/service/containerengine/containerengine_cluster_option_data_source.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ func ContainerengineClusterOptionDataSource() *schema.Resource {
2626
Optional: true,
2727
},
2828
// Computed
29+
"cluster_pod_network_options": {
30+
Type: schema.TypeList,
31+
Computed: true,
32+
Elem: &schema.Resource{
33+
Schema: map[string]*schema.Schema{
34+
// Required
35+
36+
// Optional
37+
38+
// Computed
39+
"cni_type": {
40+
Type: schema.TypeString,
41+
Computed: true,
42+
},
43+
},
44+
},
45+
},
2946
"kubernetes_versions": {
3047
Type: schema.TypeList,
3148
Computed: true,
@@ -86,6 +103,12 @@ func (s *ContainerengineClusterOptionDataSourceCrud) SetData() error {
86103

87104
s.D.SetId(tfresource.GenerateDataSourceHashID("ContainerengineClusterOptionDataSource-", ContainerengineClusterOptionDataSource(), s.D))
88105

106+
clusterPodNetworkOptions := []interface{}{}
107+
for _, item := range s.Res.ClusterPodNetworkOptions {
108+
clusterPodNetworkOptions = append(clusterPodNetworkOptions, ClusterPodNetworkOptionDetailsToMap(item))
109+
}
110+
s.D.Set("cluster_pod_network_options", clusterPodNetworkOptions)
111+
89112
s.D.Set("kubernetes_versions", s.Res.KubernetesVersions)
90113

91114
return nil

0 commit comments

Comments
 (0)