Skip to content

Commit 203376f

Browse files
robo-caphyder
authored andcommitted
Add support for Ubuntu images
1 parent 73dbabb commit 203376f

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

modules/cluster/cluster.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ resource "oci_containerengine_cluster" "k8s_cluster" {
6969
}
7070
}
7171

72-
open_id_connect_discovery {
73-
is_open_id_connect_discovery_enabled = var.oidc_discovery_enabled
72+
dynamic "open_id_connect_discovery" {
73+
for_each = var.oidc_discovery_enabled ? [1] : []
74+
content {
75+
is_open_id_connect_discovery_enabled = var.oidc_discovery_enabled
76+
}
7477
}
7578

7679

modules/workers/cloudinit.tf

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ locals {
99
default_cloud_init_merge_type = "list(append)+dict(no_replace,recurse_list)+str(append)"
1010
}
1111

12+
data "oci_core_image" "workers" {
13+
for_each = { # Skip generation for mode = virtual-node-pool
14+
for k, v in local.enabled_worker_pools : k => v
15+
if lookup(v, "mode", var.worker_pool_mode) != "virtual-node-pool"
16+
}
17+
image_id = each.value.image_id
18+
}
19+
1220
# https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/cloudinit_config.html
1321
data "cloudinit_config" "workers" {
1422
for_each = { # Skip generation for mode = virtual-node-pool
@@ -88,9 +96,38 @@ data "cloudinit_config" "workers" {
8896
}
8997
}
9098

99+
# OKE setup and initialization for Ubuntu images
100+
dynamic "part" {
101+
for_each = !each.value.disable_default_cloud_init && lookup(local.ubuntu_worker_pools, each.key, null) != null ? [1] : []
102+
content {
103+
content_type = "text/cloud-config"
104+
content = jsonencode({
105+
# https://cloudinit.readthedocs.io/en/latest/reference/modules.html#apt-configure
106+
apt = {
107+
sources = {
108+
oke-node = {
109+
source = format("deb [trusted=yes] https://objectstorage.us-sanjose-1.oraclecloud.com/p/45eOeErEDZqPGiymXZwpeebCNb5lnwzkcQIhtVf6iOF44eet_efdePaF7T8agNYq/n/odx-oke/b/okn-repositories-private/o/prod/ubuntu-%s/kubernetes-%s stable main",
110+
lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "ubuntu_release", "22.04") == "22.04" ? "jammy" : "noble",
111+
lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "kubernetes_major_version", ""))
112+
}
113+
}
114+
}
115+
package_update = true
116+
packages = [{
117+
apt = [format("oci-oke-node-all-%s", lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "kubernetes_minor_version", ""))]
118+
}]
119+
runcmd = [
120+
"oke bootstrap"
121+
]
122+
})
123+
filename = "50-oke-ubuntu.yml"
124+
merge_type = local.default_cloud_init_merge_type
125+
}
126+
}
127+
91128
# OKE startup initialization
92129
dynamic "part" {
93-
for_each = each.value.disable_default_cloud_init ? [] : [1]
130+
for_each = !each.value.disable_default_cloud_init && lookup(local.ubuntu_worker_pools, each.key, null) == null ? [1] : []
94131
content {
95132
content_type = "text/x-shellscript"
96133
content = file("${path.module}/cloudinit-oke.sh")
@@ -143,5 +180,17 @@ data "cloudinit_config" "workers" {
143180
${each.key}["cloud_init"]: ${try(jsonencode(each.value.cloud_init), "invalid")}
144181
EOT
145182
}
183+
184+
precondition {
185+
condition = lookup(local.ubuntu_worker_pools, each.key, null) == null || (
186+
lookup(local.ubuntu_worker_pools, each.key, null) != null &&
187+
contains(["22.04", "24.04"], lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "ubuntu_release", ""))
188+
)
189+
error_message = <<-EOT
190+
Supported Ubuntu versions are "22.04" and "24.04".
191+
See https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengcreatingubuntubasedworkernodes.htm#contengcreatingubuntubasedworkernodes_availabilitycompatibility.
192+
${each.key}: ${jsonencode(lookup(local.ubuntu_worker_pools, each.key, {}))}
193+
EOT
194+
}
146195
}
147196
}

modules/workers/locals.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,15 @@ locals {
270270

271271
# Yields {<pool name> = {<instance id> = <instance ip>}} for modes: 'node-pool', 'instance'
272272
worker_pool_ips = merge(local.worker_instance_ips, local.worker_nodepool_ips)
273+
274+
# Map of nodepools using Ubuntu images.
275+
ubuntu_worker_pools = {
276+
for k, v in local.enabled_worker_pools : k => {
277+
kubernetes_major_version = substr(lookup(v, "kubernetes_version", ""), 1, 4)
278+
kubernetes_minor_version = substr(lookup(v, "kubernetes_version", ""), 1, -1)
279+
ubuntu_release = lookup(data.oci_core_image.workers[k], "operating_system_version", null) != null ? lookup(data.oci_core_image.workers[k], "operating_system_version") : lookup(v, "os_version", null)
280+
}
281+
if lookup(v, "mode", var.worker_pool_mode) != "virtual-node-pool" &&
282+
contains(coalescelist(split(" ", lookup(data.oci_core_image.workers[k], "operating_system", "")), [lookup(v, "os", "")]), "Ubuntu")
283+
}
273284
}

0 commit comments

Comments
 (0)