Skip to content

Commit 3510dec

Browse files
robo-caphyder
authored andcommitted
Improve ubuntu worker nodes bootstrapping logic
1 parent 524f677 commit 3510dec

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -x
3+
4+
source /etc/os-release
5+
6+
oke_package_name="oci-oke-node-all-${oke_minor_version}"
7+
8+
# Add OKE Ubuntu package repo
9+
tee /etc/apt/sources.list.d/oke-node-client.sources <<EOF
10+
Enabled: yes
11+
Types: deb
12+
URIs: https://odx-oke.objectstorage.us-sanjose-1.oci.customer-oci.com/n/odx-oke/b/okn-repositories/o/prod/ubuntu-${version_codename}/kubernetes-${oke_major_version}
13+
Suites: stable
14+
Components: main
15+
Trusted: yes
16+
EOF
17+
18+
# Wait for apt lock and install the package
19+
while fuser /var/{lib/{dpkg/{lock,lock-frontend},apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do
20+
echo "Waiting for dpkg/apt lock"
21+
sleep 1
22+
done
23+
24+
apt-get -y update && apt-get -y install $oke_package_name
25+
26+
# OKE bootstrap
27+
oke bootstrap

modules/workers/cloudinit.tf

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,17 @@ data "cloudinit_config" "workers" {
100100
dynamic "part" {
101101
for_each = !each.value.disable_default_cloud_init && lookup(local.ubuntu_worker_pools, each.key, null) != null ? [1] : []
102102
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://odx-oke.objectstorage.us-sanjose-1.oci.customer-oci.com/n/odx-oke/b/okn-repositories/o/prod/ubuntu-%s/kubernetes-%s stable main",
110-
length(regexall( "22\\.04", lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "ubuntu_release", "22.04"))) > 0 ? "jammy" : "noble",
111-
lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "kubernetes_major_version", ""))
112-
}
113-
}
103+
content_type = "text/x-shellscript"
104+
content = templatefile(
105+
"${path.module}/cloudinit-ubuntu.sh.tftpl",
106+
{
107+
version_codename = lookup(local.ubuntu_supported_versions, lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "ubuntu_release", lookup(each.value, "os_version")), "unsupported_ubuntu_version"),
108+
oke_major_version = lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "kubernetes_major_version", "")
109+
oke_minor_version = lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "kubernetes_minor_version", "")
114110
}
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
111+
)
112+
filename = "50-oke-ubuntu.sh"
113+
merge_type = local.default_cloud_init_merge_type
125114
}
126115
}
127116

@@ -184,7 +173,7 @@ data "cloudinit_config" "workers" {
184173
precondition {
185174
condition = lookup(local.ubuntu_worker_pools, each.key, null) == null || (
186175
lookup(local.ubuntu_worker_pools, each.key, null) != null &&
187-
contains(local.ubuntu_supported_versions, lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "ubuntu_release", ""))
176+
contains(keys(local.ubuntu_supported_versions), lookup(lookup(local.ubuntu_worker_pools, each.key, {}), "ubuntu_release", ""))
188177
)
189178
error_message = <<-EOT
190179
Supported Ubuntu versions are "22.04" and "24.04".

modules/workers/locals.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,12 @@ locals {
293293

294294
# Map of nodepools using Ubuntu images.
295295

296-
ubuntu_supported_versions = ["22.04", "24.04", "22.04 Minimal", "24.04 Minimal"]
296+
ubuntu_supported_versions = {
297+
"22.04" = "jammy"
298+
"24.04" = "noble"
299+
"22.04 Minimal" = "jammy"
300+
"24.04 Minimal" = "nobble"
301+
}
297302

298303
ubuntu_worker_pools = {
299304
for k, v in local.enabled_worker_pools : k => {

0 commit comments

Comments
 (0)