Skip to content

Commit c267e2a

Browse files
authored
Merge pull request #2 from junior/zero-four-zero
Zero four zero
2 parents 34d8099 + 13b66cd commit c267e2a

File tree

12 files changed

+114
-94
lines changed

12 files changed

+114
-94
lines changed

.terraform.lock.hcl

Lines changed: 37 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
# Oracle Container Engine for Kubernetes ([OKE][oke]) Base stack
88

9-
![Stack Release](https://img.shields.io/github/v/release/oracle-quickstart/oke-base.svg)
10-
![Stack Build](https://img.shields.io/github/workflow/status/oracle-quickstart/oke-base/Generate%20stacks%20and%20publish%20release?label=stack&logo=oracle&logoColor=red)
9+
[![Stack Release](https://img.shields.io/github/v/release/oracle-quickstart/oke-base.svg)](https://github.com/oracle-quickstart/oke-base/releases)
10+
[![Stack Build](https://img.shields.io/github/workflow/status/oracle-quickstart/oke-base/Generate%20stacks%20and%20publish%20release?label=stack&logo=oracle&logoColor=red)][magic_oke_stack]
1111
![AquaSec TFSec](https://img.shields.io/github/workflow/status/oracle-quickstart/oke-base/tfsec?label=tfsec&logo=aqua)
1212
![Terraform](https://img.shields.io/badge/terraform->%3D%201.1-%235835CC.svg?logo=terraform)
1313
![Stack License](https://img.shields.io/github/license/oracle-quickstart/oke-base)
1414
![Stack Downloads](https://img.shields.io/github/downloads/oracle-quickstart/oke-base/total?logo=terraform)
15+
[![GitHub issues](https://img.shields.io/github/issues/oracle-quickstart/oke-base.svg)](https://github.com/oracle-quickstart/oke-base/issues)
1516

1617
This repo contains a Terraform Module for how to deploy Oracle Container Engine for [Kubernetes][kubernetes_101] ([OKE][oke]) cluster on Oracle Cloud Infrastructure ([OCI][oci]). This module is designed to be used with the [OCI Resource Manager][oci_rm] to deploy a cluster in a single step. The module can also be used with the [OCI Terraform Provider][oci_tf_provider] to deploy a cluster using local or CloudShell Terraform cli.
1718

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
0.4.0

module-oke.tf

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ module "oke_node_pool" {
9494
node_pool_node_shape_config_memory_in_gbs = each.value.node_pool_node_shape_config_memory_in_gbs
9595
existent_oke_nodepool_id_for_autoscaler = each.value.existent_oke_nodepool_id_for_autoscaler
9696
public_ssh_key = local.workers_public_ssh_key
97+
image_operating_system = each.value.image_operating_system
98+
image_operating_system_version = each.value.image_operating_system_version
9799

98100
# OKE Network Details
99101
oke_vcn_nodes_subnet_ocid = module.oke.oke_vcn_nodes_subnet_ocid
@@ -104,15 +106,17 @@ module "oke_node_pool" {
104106
locals {
105107
node_pools = [
106108
{
107-
node_pool_name = var.node_pool_name != "" ? var.node_pool_name : "pool1" # Must be unique
108-
node_pool_min_nodes = var.cluster_autoscaler_enabled ? var.cluster_autoscaler_min_nodes_1 : var.num_pool_workers
109+
node_pool_name = var.node_pool_name_1 != "" ? var.node_pool_name_1 : "pool1" # Must be unique
110+
node_pool_min_nodes = var.cluster_autoscaler_enabled ? var.cluster_autoscaler_min_nodes_1 : var.num_pool_workers_1
109111
node_pool_max_nodes = var.cluster_autoscaler_max_nodes_1
110112
node_k8s_version = var.k8s_version # TODO: Allow to set different version for each node pool
111-
node_pool_shape = var.node_pool_instance_shape.instanceShape
112-
node_pool_node_shape_config_ocpus = var.node_pool_instance_shape.ocpus
113-
node_pool_node_shape_config_memory_in_gbs = var.node_pool_instance_shape.memory
114-
node_pool_boot_volume_size_in_gbs = var.node_pool_boot_volume_size_in_gbs
113+
node_pool_shape = var.node_pool_instance_shape_1.instanceShape
114+
node_pool_node_shape_config_ocpus = var.node_pool_instance_shape_1.ocpus
115+
node_pool_node_shape_config_memory_in_gbs = var.node_pool_instance_shape_1.memory
116+
node_pool_boot_volume_size_in_gbs = var.node_pool_boot_volume_size_in_gbs_1
115117
existent_oke_nodepool_id_for_autoscaler = var.existent_oke_nodepool_id_for_autoscaler_1
118+
image_operating_system = var.image_operating_system_1
119+
image_operating_system_version = var.image_operating_system_version_1
116120
},
117121
]
118122
}
@@ -215,21 +219,22 @@ variable "existent_oke_nodepool_id_for_autoscaler_1" {
215219
}
216220

217221
## OKE Node Pool Details
218-
variable "node_pool_name" {
219-
default = "pool1"
220-
description = "Name of the node pool"
221-
}
222222
variable "k8s_version" {
223223
default = "Latest"
224224
description = "Kubernetes version installed on your Control Plane and worker nodes. If not version select, will use the latest available."
225225
}
226-
variable "num_pool_workers" {
226+
### Node Pool 1
227+
variable "node_pool_name_1" {
228+
default = "pool1"
229+
description = "Name of the node pool"
230+
}
231+
variable "num_pool_workers_1" {
227232
default = 3
228233
description = "The number of worker nodes in the node pool. If select Cluster Autoscaler, will assume the minimum number of nodes configured"
229234
}
230235

231-
# ocpus and memory are only used if flex shape is selected
232-
variable "node_pool_instance_shape" {
236+
#### ocpus and memory are only used if flex shape is selected
237+
variable "node_pool_instance_shape_1" {
233238
type = map(any)
234239
default = {
235240
"instanceShape" = "VM.Standard.E4.Flex"
@@ -238,15 +243,15 @@ variable "node_pool_instance_shape" {
238243
}
239244
description = "A shape is a template that determines the number of OCPUs, amount of memory, and other resources allocated to a newly created instance for the Worker Node. Select at least 2 OCPUs and 16GB of memory if using Flex shapes"
240245
}
241-
variable "node_pool_boot_volume_size_in_gbs" {
246+
variable "node_pool_boot_volume_size_in_gbs_1" {
242247
default = "60"
243248
description = "Specify a custom boot volume size (in GB)"
244249
}
245-
variable "image_operating_system" {
250+
variable "image_operating_system_1" {
246251
default = "Oracle Linux"
247252
description = "The OS/image installed on all nodes in the node pool."
248253
}
249-
variable "image_operating_system_version" {
254+
variable "image_operating_system_version_1" {
250255
default = "8"
251256
description = "The OS/image version installed on all nodes in the node pool."
252257
}

modules/new-subnet-from-oke-vcn/providers.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ terraform {
77
required_providers {
88
oci = {
99
source = "oracle/oci"
10-
version = ">= 4.88.1"
11-
# https://registry.terraform.io/providers/oracle/oci/4.88.1
10+
version = "~> 4"
11+
# https://registry.terraform.io/providers/oracle/oci/
1212
}
1313
}
1414
}

modules/new-subnet-from-oke-vcn/security-lists.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ resource "oci_core_security_list" "extra_subnet_security_list" {
3333
stateless = false
3434
}
3535

36-
count = var.create_new_oke_cluster ? 1 : 0
36+
count = var.create_new_subnet ? 1 : 0
3737
}
3838

3939
locals {

modules/new-subnet-from-oke-vcn/subnet.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ resource "oci_core_subnet" "extra_subnet" {
66
cidr_block = lookup(var.network_cidrs, "EXTRA-SUBNET-REGIONAL-CIDR")
77
compartment_id = var.oke_vcn_compartment_ocid
88
display_name = "${local.subnet_name_normalized}-subnet-${local.deploy_id}"
9-
dns_label = "${local.subnet_name_normalized}${local.deploy_id}"
9+
dns_label = "${local.subnet_name_for_dns}${local.deploy_id}"
1010
vcn_id = var.oke_vcn_ocid
1111
prohibit_public_ip_on_vnic = true
1212
route_table_id = oci_core_route_table.extra_subnet_route_table[0].id
13-
dhcp_options_id = var.oke_vcn_default_dhcp_id
13+
dhcp_options_id = var.oke_vcn_default_dhcp_ocid
1414
security_list_ids = [oci_core_security_list.extra_subnet_security_list[0].id]
1515
freeform_tags = var.freeform_deployment_tags
16+
17+
count = var.create_new_subnet ? 1 : 0
1618
}
1719

1820
resource "oci_core_route_table" "extra_subnet_route_table" {
@@ -25,6 +27,8 @@ resource "oci_core_route_table" "extra_subnet_route_table" {
2527
description = "Traffic to/from internet"
2628
destination = lookup(var.network_cidrs, "ALL-CIDR")
2729
destination_type = "CIDR_BLOCK"
28-
network_entity_id = oci_core_internet_gateway.oke_internet_gateway[0].id
30+
network_entity_id = var.oke_vcn_internet_gateway_ocid
2931
}
32+
33+
count = var.create_new_subnet ? 1 : 0
3034
}

modules/new-subnet-from-oke-vcn/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33
#
44

5+
variable "create_new_subnet" {
6+
default = false
7+
description = "Create a new node pool if true or use an existing one if false"
8+
}
9+
510
variable "network_cidrs" {
611
type = map(string)
712

@@ -35,7 +40,14 @@ variable "subnet_name" {
3540
description = "Subnet Name"
3641
}
3742

43+
# Deployment Details + Freeform Tags
44+
variable "freeform_deployment_tags" {
45+
description = "Tags to be added to the resources"
46+
}
47+
3848
# Subnet Name Locals
3949
locals {
50+
subnet_name_for_dns = substr(lower(replace(var.subnet_name, "/\\W|_|\\s/", "")), 0, 6)
4051
subnet_name_normalized = substr(replace(lower(var.subnet_name), " ", "-"), 0, 6)
52+
deploy_id = var.freeform_deployment_tags.DeploymentID
4153
}

modules/oke-cluster-autoscaler/main.tf

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,21 @@ resource "kubernetes_service_account" "cluster_autoscaler_sa" {
3333

3434
count = local.cluster_autoscaler_enabled ? 1 : 0
3535
}
36-
# resource "kubernetes_secret" "cluster_autoscaler_sa_secret" {
37-
# metadata {
38-
# name = "cluster-autoscaler-token-secret"
39-
# namespace = "kube-system"
40-
# annotations = {
41-
# "kubernetes.io/service-account.name" = "cluster-autoscaler"
42-
# "kubernetes.io/service-account.namespace" = "kube-system"
43-
# }
44-
# }
45-
# type = "kubernetes.io/service-account-token"
36+
resource "kubernetes_secret" "cluster_autoscaler_sa_secret" {
37+
metadata {
38+
name = "cluster-autoscaler-token-secret"
39+
namespace = "kube-system"
40+
annotations = {
41+
"kubernetes.io/service-account.name" = "cluster-autoscaler"
42+
"kubernetes.io/service-account.namespace" = "kube-system"
43+
}
44+
}
45+
type = "kubernetes.io/service-account-token"
4646

47-
# count = local.cluster_autoscaler_enabled ? 1 : 0
48-
# }
47+
depends_on = [kubernetes_service_account.cluster_autoscaler_sa]
48+
49+
count = local.cluster_autoscaler_enabled ? 1 : 0
50+
}
4951
resource "kubernetes_cluster_role" "cluster_autoscaler_cr" {
5052
metadata {
5153
name = "cluster-autoscaler"
@@ -103,7 +105,7 @@ resource "kubernetes_cluster_role" "cluster_autoscaler_cr" {
103105
}
104106
rule {
105107
api_groups = ["storage.k8s.io"]
106-
resources = ["storageclasses", "csinodes", "csidrivers"]
108+
resources = ["storageclasses", "csinodes", "csidrivers", "csistoragecapacities"]
107109
verbs = ["watch", "list", "get"]
108110
}
109111
rule {

modules/oke-cluster-autoscaler/variables.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ variable "oke_node_pools" {
2222
type = list(any)
2323

2424
default = []
25-
description = "Node pools (id, min_nodes, max_nodes) to use with Cluster Autoscaler"
25+
description = "Node pools (id, min_nodes, max_nodes, k8s_version) to use with Cluster Autoscaler"
2626
}
27-
# variable "k8s_version" {
28-
# default = "Latest"
29-
# description = "Kubernetes version installed on your worker nodes"
30-
# }
3127

3228
# OCI Provider
3329
variable "region" {}

0 commit comments

Comments
 (0)