Skip to content

Commit 1924663

Browse files
committed
feat: Flexible worker group definition
Signed-off-by: Devon Crouse <[email protected]>
1 parent 9561e1a commit 1924663

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1561
-262
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ provider.tf
1313
generated/**
1414

1515
# visual code
16-
**/.vscode/*
16+
**/.vscode/*
1717

1818
.terraform.lock.hcl

locals.tf

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
1-
# Copyright 2017, 2021 Oracle Corporation and/or affiliates.
1+
# Copyright 2017, 2023 Oracle Corporation and/or affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

44
locals {
5-
tenancy_id = coalesce(var.tenancy_id, var.tenancy_ocid)
6-
compartment_id = coalesce(
7-
var.compartment_id, var.compartment_ocid,
8-
var.tenancy_id, var.tenancy_ocid,
9-
)
10-
user_id = var.user_id != "" ? var.user_id : var.current_user_ocid
5+
worker_image_id = (length(var.worker_group_image_id) > 0 ? var.worker_group_image_id
6+
: var.node_pool_image_id != "none" ? var.node_pool_image_id : "")
7+
worker_image_type = (length(var.worker_group_image_type) > 0 ? var.worker_group_image_type
8+
: var.node_pool_image_type != "none" ? var.node_pool_image_type : "")
119

12-
api_private_key = (
13-
var.api_private_key != ""
14-
? try(base64decode(var.api_private_key), var.api_private_key)
15-
: var.api_private_key_path != ""
16-
? file(var.api_private_key_path)
17-
: null)
18-
19-
bastion_public_ip = var.create_bastion_host == true ? module.bastion[0].bastion_public_ip : var.bastion_public_ip != "" ? var.bastion_public_ip: ""
20-
operator_private_ip = var.create_operator == true ? module.operator[0].operator_private_ip : var.operator_private_ip !="" ? var.operator_private_ip: ""
10+
bastion_public_ip = var.create_bastion_host == true ? module.bastion[0].bastion_public_ip : var.bastion_public_ip != "" ? var.bastion_public_ip : ""
11+
operator_private_ip = var.create_operator == true ? module.operator[0].operator_private_ip : var.operator_private_ip != "" ? var.operator_private_ip : ""
2112
operator_instance_principal_group_name = var.create_operator == true ? module.operator[0].operator_instance_principal_group_name : ""
2213

23-
vcn_id = var.create_vcn == true ? module.vcn[0].vcn_id : coalesce(var.vcn_id, try(data.oci_core_vcns.vcns[0].virtual_networks[0].id,""))
24-
ig_route_id = var.create_vcn == true ? module.vcn[0].ig_route_id : coalesce(var.ig_route_table_id, try(data.oci_core_route_tables.ig[0].route_tables[0].id,""))
25-
nat_route_id = var.create_vcn == true ? module.vcn[0].nat_route_id : coalesce(var.nat_route_table_id, try(data.oci_core_route_tables.nat[0].route_tables[0].id,""))
14+
vcn_id = var.create_vcn == true ? module.vcn[0].vcn_id : coalesce(var.vcn_id, try(data.oci_core_vcns.vcns[0].virtual_networks[0].id, ""))
15+
ig_route_id = var.create_vcn == true ? module.vcn[0].ig_route_id : coalesce(var.ig_route_table_id, try(data.oci_core_route_tables.ig[0].route_tables[0].id, ""))
16+
nat_route_id = var.create_vcn == true ? module.vcn[0].nat_route_id : coalesce(var.nat_route_table_id, try(data.oci_core_route_tables.nat[0].route_tables[0].id, ""))
2617

27-
ssh_key_arg = var.ssh_private_key_path == "none" ? "" : " -i ${var.ssh_private_key_path}"
2818
validate_drg_input = var.create_drg && (var.drg_id != null) ? tobool("[ERROR]: create_drg variable can not be true if drg_id is provided.]") : true
19+
20+
worker_group_primary_subnet_id = coalesce(
21+
var.worker_group_primary_subnet_id,
22+
lookup(module.network.subnet_ids, "workers", ""))
2923
}

main.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ module "extensions" {
398398
vpa_version = var.vpa_version
399399

400400
#Gatekeeper
401-
enable_gatekeeper = var.enable_gatekeeper
401+
enable_gatekeeper = var.enable_gatekeeper
402402
gatekeeper_version = var.gatekeeper_version
403403

404404
# service account
@@ -407,8 +407,9 @@ module "extensions" {
407407
service_account_namespace = var.service_account_namespace
408408
service_account_cluster_role_binding = var.service_account_cluster_role_binding
409409

410-
#check worker nodes are active
411-
check_node_active = var.check_node_active
410+
# check worker nodes are active
411+
check_node_active = var.check_node_active
412+
expected_node_count = module.workergroup.expected_node_count + module.oke.expected_node_count
412413

413414
# oke upgrade
414415
upgrade_nodepool = var.upgrade_nodepool
@@ -421,7 +422,8 @@ module "extensions" {
421422
module.bastion,
422423
module.network,
423424
module.operator,
424-
module.oke
425+
module.oke,
426+
module.workergroup
425427
]
426428

427429
providers = {

modules/bastionsvc/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ variable "label_prefix" {}
88

99
# bastion service parameters
1010
variable "bastion_service_access" {
11-
type = list(string)
11+
type = list(string)
1212
}
1313

1414
variable "bastion_service_name" {}

modules/bastionsvc/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ terraform {
33
oci = {
44
source = "oracle/oci"
55
# pass oci home region provider explicitly for identity operations
6-
version = ">= 4.67.3"
6+
version = ">= 4.67.3"
77
}
88
}
99
required_version = ">= 1.0.0"

modules/extensions/activeworker.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Copyright 2017, 2021 Oracle Corporation and/or affiliates.
1+
# Copyright 2017, 2022 Oracle Corporation and/or affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

44
resource "null_resource" "check_worker_active" {
55
triggers = {
6-
node_pools = length(data.oci_containerengine_node_pools.all_node_pools.node_pools)
6+
expected_node_count = var.expected_node_count
77
}
88

99
connection {

modules/extensions/iam.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ locals {
2020
resource "random_id" "dynamic_group_suffix" {
2121
keepers = {
2222
# Generate a new suffix only when variables are changed
23-
label_prefix = local.dynamic_group_prefix
24-
tenancy_id = var.tenancy_id
23+
label_prefix = local.dynamic_group_prefix
24+
tenancy_id = var.tenancy_id
2525
}
2626

2727
byte_length = 8
@@ -32,21 +32,21 @@ resource "oci_identity_policy" "operator_use_dynamic_group_policy" {
3232
provider = oci.home
3333
compartment_id = random_id.dynamic_group_suffix.keepers.tenancy_id
3434
description = "policy to allow operator host to manage dynamic group"
35-
name = join("-", compact([
35+
name = join("-", compact([
3636
random_id.dynamic_group_suffix.keepers.label_prefix,
3737
"operator-instance-principal-dynamic-group",
3838
random_id.dynamic_group_suffix.hex
3939
]))
40-
statements = ["Allow dynamic-group ${var.operator_dynamic_group} to use dynamic-groups in tenancy"]
41-
count = (local.create_operator_dynamic_group_policy == true) ? 1 : 0
40+
statements = ["Allow dynamic-group ${var.operator_dynamic_group} to use dynamic-groups in tenancy"]
41+
count = (local.create_operator_dynamic_group_policy == true) ? 1 : 0
4242
}
4343

4444
# 30s delay to allow policies to take effect globally
4545
resource "time_sleep" "wait_30_seconds" {
4646
depends_on = [oci_identity_policy.operator_use_dynamic_group_policy]
4747

4848
create_duration = "30s"
49-
count = (local.create_operator_dynamic_group_policy == true) ? 1 : 0
49+
count = (local.create_operator_dynamic_group_policy == true) ? 1 : 0
5050
}
5151

5252
resource "null_resource" "update_dynamic_group" {
@@ -76,5 +76,5 @@ resource "null_resource" "update_dynamic_group" {
7676
]
7777
}
7878

79-
count = (local.create_operator_dynamic_group_policy && var.bastion_state == "RUNNING" ) ? 1 : 0
79+
count = (local.create_operator_dynamic_group_policy && var.bastion_state == "RUNNING") ? 1 : 0
8080
}

modules/extensions/k8stools.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "null_resource" "install_k8stools_on_operator" {
2121

2222
provisioner "remote-exec" {
2323
inline = [
24-
"cloud-init status --wait",
24+
"cloud-init status --wait &> /dev/null",
2525
"if [ -f \"$HOME/install_kubectx.sh\" ]; then bash \"$HOME/install_kubectx.sh\"; rm -f \"$HOME/install_kubectx.sh\";fi",
2626
]
2727
}

modules/extensions/locals.tf

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
# Copyright 2017, 2021 Oracle Corporation and/or affiliates.
1+
# Copyright 2017, 2022 Oracle Corporation and/or affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

44
locals {
55
ssh_private_key = (
66
var.ssh_private_key != ""
77
? try(base64decode(var.ssh_private_key), var.ssh_private_key)
88
: var.ssh_private_key_path != "none"
9-
? file(var.ssh_private_key_path)
10-
: null)
11-
12-
node_pools_size_list = [
13-
for node_pool in data.oci_containerengine_node_pools.all_node_pools.node_pools :
14-
node_pool.node_config_details[0].size
15-
]
16-
17-
# workaround for summing a list of numbers: https://github.com/hashicorp/terraform/issues/17239
18-
total_nodes = length(flatten([
19-
for nodes in local.node_pools_size_list : range(nodes)
20-
]))
9+
? file(var.ssh_private_key_path)
10+
: null)
2111

2212
service_account_cluster_role_binding_name = var.service_account_cluster_role_binding == "" ? "${var.service_account_name}-crb" : var.service_account_cluster_role_binding
2313

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
1-
#!/bin/bash
2-
# Copyright 2017, 2021 Oracle Corporation and/or affiliates.
1+
#!/usr/bin/env bash
2+
# Copyright 2017, 2022 Oracle Corporation and/or affiliates.
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
4+
# shellcheck disable=SC1083,SC2309,SC2154,SC2157,SC2034 # Ignore templated/escaped/unused file variables
5+
export ALL_FILE=~/all_node.active ONE_FILE=~/one_node.active
46

5-
rm -f all_node.active
6-
rm -f one_node.active
7-
8-
while [ ! -f $HOME/*node.active ]
9-
do
10-
echo 'sleeping for 30s'
11-
sleep 30
12-
if [ ${check_node_active} == all ]; then
13-
echo 'checking if all worker nodes are active'
14-
active_workers=`(kubectl get nodes | awk 'NR>1 {print $2}' | wc -l)`
15-
echo $active_workers 'active worker nodes found out of ${total_nodes}'
16-
if [ $active_workers -eq ${total_nodes} ]; then
17-
touch all_node.active
7+
function clean_node_active() {
8+
rm -f "$${ALL_FILE}" "$${ONE_FILE}"
9+
}
10+
11+
function get_actual_node_count() {
12+
(kubectl get --no-headers nodes | grep -v NotReady | awk '{print $1}' | wc -l) 2>/dev/null || echo '0'
13+
}
14+
15+
function wait_for_active() {
16+
clean_node_active
17+
18+
while true; do
19+
local actual_node_count
20+
actual_node_count=$(get_actual_node_count)
21+
if [[ $${actual_node_count} -ge ${expected_node_count} ]]; then touch all_node.active; fi
22+
if [[ $${actual_node_count} -ge 1 ]]; then touch one_node.active; fi
23+
24+
if [[ -f "$${ONE_FILE}" ]] && [[ "${check_node_active}" == 'one' ]]; then
25+
echo "Ready with $${actual_node_count} node(s)"
26+
break
1827
fi
19-
else
20-
echo 'checking if 1 active worker node'
21-
active_workers=`(kubectl get nodes | awk 'NR>1 {print $2}' | wc -l)`
22-
if [ $active_workers -ge 1 ]; then
23-
echo '1 active worker node found'
24-
touch one_node.active
28+
29+
if [[ -f "$${ALL_FILE}" ]] && [[ "${check_node_active}" == 'all' ]]; then
30+
echo "Ready with $${actual_node_count} node(s)"
31+
break
2532
fi
26-
fi
27-
done
33+
34+
echo "$(date): Waiting for ${check_node_active} of ${expected_node_count} node(s) to become ready ($${actual_node_count} found)"
35+
sleep 30
36+
done
37+
}
38+
39+
if [[ ${expected_node_count} -ge 1 ]]; then time wait_for_active; fi

0 commit comments

Comments
 (0)