Skip to content

Commit bf9a492

Browse files
authored
Fixes incorrect namespace issue when creating secret for OCIR (#272)
* updated default kubernetes version to v1.18.10, fixed deprecated interpolation-only expressions * now looking object storage namespace for ocirsecret instead of having to pass as variable * updated description for tenancy id
1 parent 9da7e87 commit bf9a492

File tree

8 files changed

+67
-78
lines changed

8 files changed

+67
-78
lines changed

docs/terraformoptions.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,6 @@ Refer to {uri-topology}[topology] for more thorough examples.
613613
|
614614
|none
615615

616-
|`tenancy_name`
617-
|The *_name_* of the tenancy to be used when creating the Docker secret. This is different from tenancy_id. *Required* if secret_id is set.
618-
|
619-
|none
620-
621616
|`username`
622617
|The username that can login to the selected tenancy. This is different from tenancy_id. *Required* if secret_id is set.
623618
|

locals.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,11 @@ locals {
121121
}
122122

123123
oke_ocir = {
124-
email_address = var.email_address
125-
ocir_urls = var.ocir_urls
126-
secret_id = var.secret_id
127-
secret_name = var.secret_name
128-
tenancy_name = var.tenancy_name
129-
username = var.username
124+
email_address = var.email_address
125+
ocir_urls = var.ocir_urls
126+
secret_id = var.secret_id
127+
secret_name = var.secret_name
128+
username = var.username
130129
}
131130

132131
oke_kms = {

modules/oke/datasources.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ data "oci_containerengine_node_pools" "all_node_pools" {
1010
data "oci_containerengine_node_pool_option" "node_pool_options" {
1111
node_pool_option_id = oci_containerengine_cluster.k8s_cluster.id
1212
}
13+
14+
# retrieve for creating ocir secret
15+
data "oci_objectstorage_namespace" "object_storage_namespace" {
16+
}

modules/oke/scripts/secret.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
region_registry = '${region_registry}'
1414
secret_id = '${secret_id}'
1515
secret_name = '${secret_name}'
16-
tenancy_name = '${tenancy_name}'
16+
tenancy_namespace = '${tenancy_namespace}'
1717
username = '${username}'
1818

1919
signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
@@ -38,7 +38,7 @@ def read_secret_value(secret_client, secret_id):
3838
delsecret = "kubectl -n default delete secret ${secret_name}"
3939
os.system(delsecret)
4040

41-
crtsecret = ("kubectl create secret docker-registry ${secret_name} -n default --docker-server=${region_registry} --docker-username=${tenancy_name}/${username} --docker-email=${email_address} --docker-password=%s" % secret_content)
41+
crtsecret = ("kubectl create secret docker-registry ${secret_name} -n default --docker-server=${region_registry} --docker-username=${tenancy_namespace}/${username} --docker-email=${email_address} --docker-password=%s" % secret_content)
4242

4343
subprocess.call(["/bin/bash" , "-c" , crtsecret])
4444

modules/oke/secrets.tf

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

4-
data "template_file" "secret" {
5-
template = file("${path.module}/scripts/secret.py")
6-
7-
vars = {
8-
compartment_id = var.compartment_id
9-
region = var.region
10-
11-
email_address = var.oke_ocir.email_address
12-
region_registry = var.oke_ocir.ocir_urls[var.region]
13-
secret_id = var.oke_ocir.secret_id
14-
secret_name = var.oke_ocir.secret_name
15-
tenancy_name = var.oke_ocir.tenancy_name
16-
username = var.oke_ocir.username
17-
18-
}
19-
count = var.oke_operator.operator_enabled == true && var.oke_operator.operator_instance_principal == true && var.oke_ocir.secret_id != "none" ? 1 : 0
20-
}
21-
22-
resource null_resource "secret" {
23-
triggers = {
4+
data "template_file" "secret" {
5+
template = file("${path.module}/scripts/secret.py")
6+
7+
vars = {
8+
compartment_id = var.compartment_id
9+
region = var.region
10+
11+
email_address = var.oke_ocir.email_address
12+
region_registry = var.oke_ocir.ocir_urls[var.region]
13+
secret_id = var.oke_ocir.secret_id
14+
secret_name = var.oke_ocir.secret_name
15+
tenancy_namespace = data.oci_objectstorage_namespace.object_storage_namespace.namespace
16+
username = var.oke_ocir.username
17+
18+
}
19+
count = var.oke_operator.operator_enabled == true && var.oke_operator.operator_instance_principal == true && var.oke_ocir.secret_id != "none" ? 1 : 0
20+
}
21+
22+
resource null_resource "secret" {
23+
triggers = {
2424
secret_id = var.oke_ocir.secret_id
2525
}
26-
connection {
27-
host = var.oke_operator.operator_private_ip
28-
private_key = file(var.oke_ssh_keys.ssh_private_key_path)
29-
timeout = "40m"
30-
type = "ssh"
31-
user = "opc"
32-
33-
bastion_host = var.oke_operator.bastion_public_ip
34-
bastion_user = "opc"
35-
bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path)
36-
}
37-
38-
depends_on = [null_resource.write_kubeconfig_on_operator]
39-
40-
provisioner "file" {
41-
content = data.template_file.secret[0].rendered
42-
destination = "~/secret.py"
43-
}
44-
45-
provisioner "remote-exec" {
46-
inline = [
47-
"chmod +x $HOME/secret.py",
48-
"$HOME/secret.py",
49-
"sleep 10",
50-
"rm -f $HOME/secret.py"
51-
]
52-
}
53-
54-
count = var.oke_operator.operator_enabled == true && var.oke_operator.operator_instance_principal == true && var.oke_ocir.secret_id != "none" ? 1 : 0
55-
}
26+
connection {
27+
host = var.oke_operator.operator_private_ip
28+
private_key = file(var.oke_ssh_keys.ssh_private_key_path)
29+
timeout = "40m"
30+
type = "ssh"
31+
user = "opc"
32+
33+
bastion_host = var.oke_operator.bastion_public_ip
34+
bastion_user = "opc"
35+
bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path)
36+
}
37+
38+
depends_on = [null_resource.write_kubeconfig_on_operator]
39+
40+
provisioner "file" {
41+
content = data.template_file.secret[0].rendered
42+
destination = "~/secret.py"
43+
}
44+
45+
provisioner "remote-exec" {
46+
inline = [
47+
"chmod +x $HOME/secret.py",
48+
"$HOME/secret.py",
49+
"sleep 10",
50+
"rm -f $HOME/secret.py"
51+
]
52+
}
53+
54+
count = var.oke_operator.operator_enabled == true && var.oke_operator.operator_instance_principal == true && var.oke_ocir.secret_id != "none" ? 1 : 0
55+
}

modules/oke/variables.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ variable "lbs" {
7373
# ocir
7474
variable "oke_ocir" {
7575
type = object({
76-
email_address = string
77-
ocir_urls = map(string)
78-
secret_id = string
79-
secret_name = string
80-
tenancy_name = string
81-
username = string
76+
email_address = string
77+
ocir_urls = map(string)
78+
secret_id = string
79+
secret_name = string
80+
username = string
8281
})
8382
}
8483

terraform.tfvars.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ secret_id = "none"
186186

187187
secret_name = "ocirsecret"
188188

189-
tenancy_name = ""
190-
191189
username = ""
192190

193191
# calico

variables.tf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ variable "region" {
1919
}
2020

2121
variable "tenancy_id" {
22-
description = "The tenancy id in which to create the sources."
22+
description = "The tenancy id in which to create the resources."
2323
type = string
2424
}
2525

@@ -435,12 +435,6 @@ variable "secret_name" {
435435
default = "ocirsecret"
436436
}
437437

438-
variable "tenancy_name" {
439-
default = "none"
440-
description = "The tenancy name to use when creating the ocir secret."
441-
type = string
442-
}
443-
444438
variable "username" {
445439
default = "none"
446440
description = "The username to access OCIR."

0 commit comments

Comments
 (0)