Skip to content

Commit 25cd102

Browse files
authored
feat: added support for OKE images for faster worker node provisioning (#529)
* feat: added supported for OKE images for faster worker node provisioning Signed-off-by: Ali Mukadam <ali.mukadam@oracle.com> * fix: added default freeform tags for cluster and nodepools Signed-off-by: Ali Mukadam <ali.mukadam@oracle.com> * fix: removed `node_source_details` from lifecycle Signed-off-by: Ali Mukadam <ali.mukadam@oracle.com> * added separate dynamic blocks for platform, custom and oke images Signed-off-by: Ali Mukadam <ali.mukadam@oracle.com>
1 parent d6e4b99 commit 25cd102

File tree

7 files changed

+68
-8
lines changed

7 files changed

+68
-8
lines changed

docs/terraformoptions.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,11 @@ node_pools = {
688688
|
689689
|"none"
690690

691+
|node_pool_image_type
692+
|Whether to use a Platform, OKE or custom image. When custom is set, the node_pool_image_id *must* be specified. Using an OKE image minimizes the time it takes to provision worker nodes at runtime when compared to platform images and custom images. OKE images are optimized for use as worker node base images, with all the necessary configurations and required software. The use of OKE images reduces worker node provisioning time by more than half when compared to platform images. OKE images are provided by Oracle and built on top of platform images.
693+
| "custom","oke","platform"
694+
|"oke"
695+
691696
|node_pool_os
692697
|The name of the Operating System image to use to provision the worker nodes.
693698
|

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ module "oke" {
236236
node_pools = var.node_pools
237237
node_pool_name_prefix = var.node_pool_name_prefix
238238
node_pool_image_id = var.node_pool_image_id
239+
node_pool_image_type = var.node_pool_image_type
239240
node_pool_os = var.node_pool_os
240241
node_pool_os_version = var.node_pool_os_version
241242
node_pool_timezone = var.node_pool_timezone

modules/oke/locals.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ locals {
2828
# 3. if more than 1 image found for this version, pick the latest
2929
node_pool_image_ids = data.oci_containerengine_node_pool_option.node_pool_options.sources
3030

31+
# kubernetes string version length
32+
k8s_version_length = length(var.cluster_kubernetes_version)
33+
k8s_version_only = substr(var.cluster_kubernetes_version,1,local.k8s_version_length)
34+
3135
}

modules/oke/nodepools.tf

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ resource "oci_containerengine_node_pool" "nodepools" {
1111
name = var.label_prefix == "none" ? each.key : "${var.label_prefix}-${each.key}"
1212

1313
freeform_tags = var.freeform_tags["node_pool"]
14-
15-
node_config_details {
1614

15+
node_config_details {
16+
17+
# iterating over ADs
1718
dynamic "placement_configs" {
1819
iterator = ad_iterator
1920
for_each = local.ad_names
@@ -25,10 +26,12 @@ resource "oci_containerengine_node_pool" "nodepools" {
2526
nsg_ids = var.worker_nsgs
2627
is_pv_encryption_in_transit_enabled = var.enable_pv_encryption_in_transit
2728
kms_key_id = var.node_pool_volume_kms_key_id
29+
2830
# allow zero-sized node pools
2931
size = max(0, lookup(each.value, "node_pool_size", 0))
3032
}
3133

34+
# setting shape
3235
dynamic "node_shape_config" {
3336
for_each = length(regexall("Flex", lookup(each.value, "shape", "VM.Standard.E4.Flex"))) > 0 ? [1] : []
3437
content {
@@ -37,25 +40,55 @@ resource "oci_containerengine_node_pool" "nodepools" {
3740
}
3841
}
3942

43+
# cloud-init
4044
node_metadata = {
4145
user_data = var.cloudinit_nodepool_common == "" && lookup(var.cloudinit_nodepool, each.key, null) == null ? data.cloudinit_config.worker.rendered : lookup(var.cloudinit_nodepool, each.key, null) != null ? filebase64(lookup(var.cloudinit_nodepool, each.key, null)) : filebase64(var.cloudinit_nodepool_common)
4246
}
4347

44-
node_source_details {
45-
boot_volume_size_in_gbs = lookup(each.value, "boot_volume_size", 50)
46-
# check is done for GPU,A1 and other shapes.In future if some other shapes or images added we need to modify
47-
image_id = (var.node_pool_image_id == "none" && length(regexall("GPU|A1", lookup(each.value, "shape"))) == 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("Oracle-Linux-${var.node_pool_os_version}-20[0-9]*.*", source.source_name)) > 0], 0)) : (var.node_pool_image_id == "none" && length(regexall("GPU", lookup(each.value, "shape"))) > 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("Oracle-Linux-${var.node_pool_os_version}-Gen[0-9]-GPU-20[0-9]*.*", source.source_name)) > 0], 0)) : (var.node_pool_image_id == "none" && length(regexall("A1", lookup(each.value, "shape"))) > 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("Oracle-Linux-${var.node_pool_os_version}-aarch64-20[0-9]*.*", source.source_name)) > 0], 0)) : var.node_pool_image_id
48-
source_type = data.oci_containerengine_node_pool_option.node_pool_options.sources[0].source_type
48+
# optimized OKE images
49+
dynamic "node_source_details" {
50+
for_each = var.node_pool_image_type == "oke" ? [1] : []
51+
content {
52+
boot_volume_size_in_gbs = lookup(each.value, "boot_volume_size", 50)
53+
# check for GPU,A1 and other shapes. In future, if some other shapes or images are added, we need to modify
54+
image_id = (var.node_pool_image_type == "oke" && length(regexall("GPU|A1", lookup(each.value, "shape"))) == 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("Oracle-Linux-${var.node_pool_os_version}-20[0-9]*.*-OKE-${local.k8s_version_only}", source.source_name)) > 0], 0)) : (var.node_pool_image_type == "oke" && length(regexall("GPU", lookup(each.value, "shape"))) > 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("Oracle-Linux-${var.node_pool_os_version}-Gen[0-9]-GPU-20[0-9]*.*-OKE-${local.k8s_version_only}", source.source_name)) > 0], 0)) : (var.node_pool_image_type == "oke" && length(regexall("A1", lookup(each.value, "shape"))) > 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("Oracle-Linux-${var.node_pool_os_version}-aarch64-20[0-9]*.*-OKE-${local.k8s_version_only}", source.source_name)) > 0], 0)) : null
55+
56+
source_type = data.oci_containerengine_node_pool_option.node_pool_options.sources[0].source_type
57+
}
58+
}
59+
60+
# OCI platform images
61+
dynamic "node_source_details" {
62+
for_each = var.node_pool_image_type == "platform" ? [1] : []
63+
content {
64+
boot_volume_size_in_gbs = lookup(each.value, "boot_volume_size", 50)
65+
# check for GPU,A1 and other shapes. In future, if some other shapes or images are added, we need to modify
66+
image_id = (var.node_pool_image_type == "platform" && length(regexall("GPU|A1", lookup(each.value, "shape"))) == 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("^(Oracle-Linux-${var.node_pool_os_version}-\\d{4}.\\d{2}.\\d{2}-[0-9]*)$", source.source_name)) > 0], 0)) : (var.node_pool_image_type == "platform" && length(regexall("GPU", lookup(each.value, "shape"))) > 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("^(Oracle-Linux-${var.node_pool_os_version}-Gen[0-9]-GPU-\\d{4}.\\d{2}.\\d{2}-[0-9]*)$", source.source_name)) > 0], 0)) : (var.node_pool_image_type == "platform" && length(regexall("A1", lookup(each.value, "shape"))) > 0) ? (element([for source in local.node_pool_image_ids : source.image_id if length(regexall("^(Oracle-Linux-${var.node_pool_os_version}-aarch64-\\d{4}.\\d{2}.\\d{2}-[0-9]*)$", source.source_name)) > 0], 0)) : null
67+
68+
source_type = data.oci_containerengine_node_pool_option.node_pool_options.sources[0].source_type
69+
}
4970
}
5071

72+
# custom images
73+
dynamic "node_source_details" {
74+
for_each = var.node_pool_image_type == "custom" ? [1] : []
75+
content {
76+
boot_volume_size_in_gbs = lookup(each.value, "boot_volume_size", 50)
77+
image_id = var.node_pool_image_id
78+
source_type = data.oci_containerengine_node_pool_option.node_pool_options.sources[0].source_type
79+
}
80+
}
5181
node_shape = lookup(each.value, "shape", "VM.Standard.E4.Flex")
5282

5383
ssh_public_key = (var.ssh_public_key != "") ? var.ssh_public_key : (var.ssh_public_key_path != "none") ? file(var.ssh_public_key_path) : ""
5484

5585
# do not destroy the node pool if the kubernetes version has changed as part of the upgrade
86+
5687
lifecycle {
5788
ignore_changes = [kubernetes_version]
5889
}
90+
91+
# initial node labels for the different node pools
5992
dynamic "initial_node_labels" {
6093
for_each = lookup(each.value, "label", "") != "" ? each.value.label : {}
6194
content {

modules/oke/variables.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ variable "node_pool_name_prefix" {}
9191

9292
variable "node_pool_image_id" {}
9393

94+
variable "node_pool_image_type" {}
95+
9496
variable "node_pool_os" {}
9597

9698
variable "node_pool_os_version" {}

terraform.tfvars.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pods_cidr = "10.244.0.0/16"
149149
services_cidr = "10.96.0.0/16"
150150

151151
## oke cluster kms integration
152-
use_encryption = false
152+
use_cluster_encryption = false
153153
cluster_kms_key_id = ""
154154
create_policies = true
155155

@@ -177,6 +177,7 @@ node_pools = {
177177
# np10 = {shape="BM.HPC2.36 ", node_pool_size=5}
178178
}
179179
node_pool_image_id = "none"
180+
node_pool_image_type = "oke"
180181
node_pool_name_prefix = "np"
181182
node_pool_os = "Oracle Linux"
182183
node_pool_os_version = "7.9"

variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,16 @@ variable "node_pool_image_id" {
612612
type = string
613613
}
614614

615+
variable "node_pool_image_type" {
616+
default = "oke"
617+
description = "Whether to use a Platform, OKE or custom image. When custom is set, the node_pool_image_id must be specified."
618+
type = string
619+
validation {
620+
condition = contains(["custom", "oke", "platform"], var.node_pool_image_type)
621+
error_message = "Accepted values are custom, oke, platform."
622+
}
623+
}
624+
615625
variable "node_pool_name_prefix" {
616626
default = "np"
617627
description = "The prefix of the node pool name."
@@ -899,6 +909,10 @@ variable "freeform_tags" {
899909
environment = "dev"
900910
role = "load balancer"
901911
}
912+
cluster = {
913+
environment = "dev"
914+
}
915+
node_pool = {}
902916
}
903917
}
904918
description = "Tags to apply to different resources."

0 commit comments

Comments
 (0)