Skip to content

Commit

Permalink
Cloud init args and parts support for Node Pool
Browse files Browse the repository at this point in the history
Signed-off-by: junior <[email protected]>
  • Loading branch information
junior committed Dec 12, 2022
1 parent 3a4f80e commit d0fed41
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ module "oke_node_pools" {
node_pool_node_shape_config_ocpus = each.value.node_pool_node_shape_config_ocpus
node_pool_node_shape_config_memory_in_gbs = each.value.node_pool_node_shape_config_memory_in_gbs
existent_oke_nodepool_id_for_autoscaler = each.value.existent_oke_nodepool_id_for_autoscaler
node_pool_oke_init_params = each.value.node_pool_oke_init_params
node_pool_cloud_init_parts = each.value.node_pool_cloud_init_parts
public_ssh_key = local.workers_public_ssh_key
image_operating_system = each.value.image_operating_system
image_operating_system_version = each.value.image_operating_system_version
Expand Down Expand Up @@ -148,6 +150,8 @@ locals {
node_pool_node_shape_config_memory_in_gbs = var.node_pool_instance_shape_1.memory
node_pool_boot_volume_size_in_gbs = var.node_pool_boot_volume_size_in_gbs_1
existent_oke_nodepool_id_for_autoscaler = var.existent_oke_nodepool_id_for_autoscaler_1
node_pool_oke_init_params = var.node_pool_oke_init_params_1
node_pool_cloud_init_parts = var.node_pool_cloud_init_parts_1
node_pool_alternative_subnet = null
image_operating_system = var.image_operating_system_1
image_operating_system_version = var.image_operating_system_version_1
Expand Down
24 changes: 24 additions & 0 deletions modules/oke-node-pool/datasources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,28 @@ data "oci_identity_availability_domain" "specfic" {
ad_number = var.node_pool_shape_specific_ad

count = (var.node_pool_shape_specific_ad > 0) ? 1 : 0
}

# Prepare Cloud Unit for Node Pool nodes
data "cloudinit_config" "nodes" {
gzip = true
base64_encode = true

part {
content_type = "text/x-shellscript"
content = <<EOF
#!/bin/bash
curl --fail -H "Authorization: Bearer Oracle" -L0 http://169.254.169.254/opc/v2/instance/metadata/oke_init_script | base64 --decode >/var/run/oke-init.sh
bash /var/run/oke-init.sh ${var.node_pool_oke_init_params}
EOF
}

dynamic "part" {
for_each = var.node_pool_cloud_init_parts
content {
content_type = part.value["content_type"]
content = part.value["content"]
filename = part.value["filename"]
}
}
}
11 changes: 10 additions & 1 deletion modules/oke-node-pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ resource "oci_containerengine_node_pool" "oke_node_pool" {
# eviction_grace_duration = "PT1H"
# is_force_delete_after_grace_duration = false
# }
# node_metadata = {}
node_metadata = {
user_data = anytrue([var.node_pool_oke_init_params != "", var.node_pool_cloud_init_parts != []]) ? data.cloudinit_config.nodes.rendered : null
}
# dynamic "node_metadata" {
# for_each = alltrue([var.node_pool_oke_init_params != "", var.node_pool_cloud_init_parts != []]) ? [1] : []

# content {
# user_data = data.cloudinit_config.nodes.rendered
# }
# }

initial_node_labels {
key = "name"
Expand Down
14 changes: 14 additions & 0 deletions modules/oke-node-pool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ variable "node_pool_boot_volume_size_in_gbs" {
default = "50"
description = "Specify a custom boot volume size (in GB)"
}
variable "node_pool_oke_init_params" {
type = string
default = ""
description = "OKE Init params"
}
variable "node_pool_cloud_init_parts" {
type = list(object({
content_type = string
content = string
filename = string
}))
default = []
description = "Node Pool nodes Cloud init parts"
}
variable "public_ssh_key" {
default = ""
description = "In order to access your private nodes with a public SSH key you will need to set up a bastion host (a.k.a. jump box). If using public nodes, bastion is not needed. Left blank to not import keys."
Expand Down

0 comments on commit d0fed41

Please sign in to comment.