Skip to content

Commit 8ab6f21

Browse files
authored
added sleep to ensure oci-cli has finished installing before generati… (#146)
* added sleep to ensure oci-cli has finished installing before generating kubeconfig. also added explicit dependencies for generating the kubeconfig and creating the ocir secret on install_kubectl * upgraded base module to 1.1.3, added wait until admin and instance_principal is ready to generate kubeconfig Signed-off-by: Ali Mukadam <[email protected]> * sleep for 30s after instance_principal for admin is detected before generating kubeconfig Signed-off-by: Ali Mukadam <[email protected]> * added separate delay to ensure OCI_CLI_AUTH is set, kubeconfig is created and instance_principal is active; removed unneceunnecessary token variable version and expiration Signed-off-by: Ali Mukadam <[email protected]>
1 parent 861fddd commit 8ab6f21

File tree

7 files changed

+55
-15
lines changed

7 files changed

+55
-15
lines changed

CHANGELOG.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ All notable changes to this project are documented in this file.
77

88
The format is based on {uri-changelog}[Keep a Changelog].
99

10+
== 2.1.6 (April 13, 2020)
11+
* Fixed issue with admin host ordering of oci-cli installation, instance_principal creation and kubeconfig generation (#143)
12+
* Upgraded base module to 1.1.3 to be able to detect when admin instance_principal is ready
13+
* Removed unnecessary token variable version and expiration
14+
1015
== 2.1.5 (April 06, 2020)
1116
* Added ig_route_id, nat_route_id, subnet_ids, vcn_id for reuse (#145)
1217

main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ terraform {
66
}
77

88
module "base" {
9-
# source = "github.com/oracle-terraform-modules/terraform-oci-base?ref=v1.1.1"
109
source = "oracle-terraform-modules/base/oci"
11-
version = "1.1.1"
10+
version = "1.1.3"
1211

1312
# identity
1413
oci_base_identity = local.oci_base_identity
@@ -25,6 +24,9 @@ module "base" {
2524
# admin server parameters
2625
oci_base_admin = local.oci_base_admin
2726

27+
# tagging
28+
tagging = var.tagging
29+
2830
}
2931

3032
module "policies" {

modules/oke/kubeconfig.tf

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
data "oci_containerengine_cluster_kube_config" "kube_config" {
55
cluster_id = oci_containerengine_cluster.k8s_cluster.id
6-
expiration = var.cluster_kube_config_expiration
7-
token_version = var.cluster_kube_config_token_version
86
}
97

108
resource "null_resource" "create_local_kubeconfig" {
@@ -60,6 +58,31 @@ resource "null_resource" "install_kubectl_admin" {
6058
count = var.oke_admin.bastion_enabled == true && var.oke_admin.admin_enabled == true ? 1 : 0
6159
}
6260

61+
# wait for 1. admin being ready 2. instance_principal created 3. kubectl is installed (the script will create the .kube directory)
62+
resource null_resource "wait_for_admin" {
63+
connection {
64+
host = var.oke_admin.admin_private_ip
65+
private_key = file(var.oke_ssh_keys.ssh_private_key_path)
66+
timeout = "40m"
67+
type = "ssh"
68+
user = "opc"
69+
70+
bastion_host = var.oke_admin.bastion_public_ip
71+
bastion_user = "opc"
72+
bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path)
73+
}
74+
75+
depends_on = [null_resource.install_kubectl_admin]
76+
77+
provisioner "remote-exec" {
78+
inline = [
79+
"while [ ! -f /home/opc/admin.finish ] || [ ! -f /home/opc/ip.finish ]; do sleep 10; done",
80+
]
81+
}
82+
83+
count = var.oke_admin.bastion_enabled == true && var.oke_admin.admin_enabled == true ? 1 : 0
84+
}
85+
6386
data "template_file" "generate_kubeconfig" {
6487
template = file("${path.module}/scripts/generate_kubeconfig.template.sh")
6588

@@ -84,7 +107,7 @@ resource "null_resource" "write_kubeconfig_on_admin" {
84107
bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path)
85108
}
86109

87-
depends_on = [oci_containerengine_cluster.k8s_cluster]
110+
depends_on = [oci_containerengine_cluster.k8s_cluster, null_resource.wait_for_admin]
88111

89112
provisioner "file" {
90113
content = data.template_file.generate_kubeconfig[0].rendered

modules/oke/ocir.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ resource null_resource "create_ocir_secret" {
3131
bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path)
3232
}
3333

34-
depends_on = [null_resource.write_kubeconfig_on_admin]
34+
depends_on = [null_resource.install_kubectl_admin, null_resource.write_kubeconfig_on_admin]
3535

3636
provisioner "file" {
3737
content = data.template_file.create_ocir_script[0].rendered

modules/oke/variables.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ variable "lbs" {
7575
})
7676
}
7777

78-
# kubeconfig
79-
variable "cluster_kube_config_expiration" {
80-
default = 2592000
81-
}
82-
variable "cluster_kube_config_token_version" {
83-
default = "2.0.0"
84-
}
85-
8678
# ocir
8779
variable "oke_ocir" {
8880
type = object({

terraform.tfvars.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ availability_domains = {
9696
admin = 1
9797
}
9898

99+
tagging = {
100+
computetag = { "Environment" = "uat" }
101+
networktag = { "Name" = "network" }
102+
}
103+
99104
# oke
100105

101106
allow_node_port_access = false

variables.tf

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ variable "vcn_cidr" {
100100
}
101101

102102
variable "vcn_dns_label" {
103-
type = string
103+
type = string
104104
}
105105

106106
variable "vcn_name" {
@@ -236,6 +236,19 @@ variable "availability_domains" {
236236
type = map
237237
}
238238

239+
# tagging
240+
241+
variable "tagging" {
242+
type = object({
243+
computetag = map(any)
244+
networktag = map(any)
245+
})
246+
default = {
247+
computetag = { "Environment" = "uat" }
248+
networktag = { "Name" = "network" }
249+
}
250+
}
251+
239252
# oke
240253

241254
variable "allow_node_port_access" {

0 commit comments

Comments
 (0)