Skip to content

Commit d6558b0

Browse files
authored
Improve operator pkg installation (#890)
* upgrade to olcne 1.8 on operator & add ability to install kubectl from k8s.io using curl * fix kubectl for_each
1 parent da9619e commit d6558b0

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

module-operator.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ module "operator" {
6060
image_id = local.operator_image_id
6161
install_cilium = var.cilium_install
6262
install_helm = var.operator_install_helm
63+
install_istioctl = var.operator_install_istioctl
6364
install_k9s = var.operator_install_k9s
6465
install_kubectx = var.operator_install_kubectx
66+
install_kubectl_from_repo = var.operator_install_kubectl_from_repo
6567
kubeconfig = yamlencode(local.kubeconfig_private)
6668
kubernetes_version = var.kubernetes_version
6769
nsg_ids = compact(flatten([var.operator_nsg_ids, try(module.network.operator_nsg_id, null)]))
@@ -76,6 +78,7 @@ module "operator" {
7678
user = var.operator_user
7779
volume_kms_key_id = var.operator_volume_kms_key_id
7880

81+
7982
# Standard tags as defined if enabled for use, or freeform
8083
# User-provided tags are merged last and take precedence
8184
defined_tags = merge(var.use_defined_tags ? {

modules/operator/cloudinit.tf

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ locals {
1010

1111
baserepo = "ol${var.operator_image_os_version}"
1212
developer_EPEL = "${local.baserepo}_developer_EPEL"
13-
olcne17 = "${local.baserepo}_olcne17"
13+
olcne18 = "${local.baserepo}_olcne18"
1414
developer_olcne = "${local.baserepo}_developer_olcne"
1515
arch_amd = "amd64"
1616
arch_arm = "aarch64"
17-
1817
}
1918

2019
# https://registry.terraform.io/providers/hashicorp/template/latest/docs/data-sources/cloudinit_config.html
@@ -32,9 +31,10 @@ data "cloudinit_config" "operator" {
3231
packages = compact([
3332
"git",
3433
"jq",
35-
"kubectl",
3634
"python3-oci-cli",
3735
var.install_helm ? "helm" : null,
36+
var.install_istioctl ? "istio-istioctl" : null,
37+
var.install_kubectl_from_repo ? "kubectl": null,
3838
])
3939
yum_repos = {
4040
"${local.developer_EPEL}" = {
@@ -44,9 +44,9 @@ data "cloudinit_config" "operator" {
4444
gpgcheck = true
4545
enabled = true
4646
}
47-
"${local.olcne17}" = {
48-
name = "Oracle Linux Cloud Native Environment 1.7 ($basearch)"
49-
baseurl = "https://yum$ociregion.$ocidomain/repo/OracleLinux/OL${var.operator_image_os_version}/olcne17/$basearch/"
47+
"${local.olcne18}" = {
48+
name = "Oracle Linux Cloud Native Environment 1.8 ($basearch)"
49+
baseurl = "https://yum$ociregion.$ocidomain/repo/OracleLinux/OL${var.operator_image_os_version}/olcne18/$basearch/"
5050
gpgkey = "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle"
5151
gpgcheck = true
5252
enabled = true
@@ -101,6 +101,24 @@ data "cloudinit_config" "operator" {
101101
merge_type = local.default_cloud_init_merge_type
102102
}
103103

104+
# kubectl installation
105+
dynamic "part" {
106+
for_each = var.install_kubectl_from_repo ? [] : [1]
107+
content {
108+
content_type = "text/cloud-config"
109+
content = jsonencode({
110+
runcmd = [
111+
"CLI_ARCH='${local.arch_amd}'",
112+
"if [ \"$(uname -m)\" = ${local.arch_arm} ]; then CLI_ARCH='arm64'; fi",
113+
"curl -LO https://dl.k8s.io/release/${var.kubernetes_version}/bin/linux/$CLI_ARCH/kubectl",
114+
"install -o root -g root -m 0755 kubectl /usr/bin/kubectl"
115+
]
116+
})
117+
filename = "20-kubectl.yml"
118+
merge_type = local.default_cloud_init_merge_type
119+
}
120+
}
121+
104122
# kubectx/kubens installation
105123
dynamic "part" {
106124
for_each = var.install_kubectx ? [1] : []
@@ -164,8 +182,8 @@ data "cloudinit_config" "operator" {
164182
content = jsonencode({
165183
runcmd = [
166184
"CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/master/stable.txt)",
167-
"CLI_ARCH=${local.arch_amd}",
168-
"if [ '$(uname -m)' = ${local.arch_arm} ]; then CLI_ARCH=${local.arch_arm}; fi",
185+
"CLI_ARCH='${local.arch_amd}'",
186+
"if [ \"$(uname -m)\" = ${local.arch_arm} ]; then CLI_ARCH='arm64'; fi",
169187
"curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/$CILIUM_CLI_VERSION/cilium-linux-$CLI_ARCH.tar.gz",
170188
"tar xzvfC cilium-linux-$CLI_ARCH.tar.gz /usr/local/bin"
171189
]

modules/operator/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ variable "cloud_init" { type = list(map(string)) }
1616
variable "image_id" { type = string }
1717
variable "install_cilium" { type = bool }
1818
variable "install_helm" { type = bool }
19+
variable "install_istioctl" { type = bool }
1920
variable "install_k9s" { type = bool }
21+
variable "install_kubectl_from_repo" {
22+
type = bool
23+
default = true
24+
}
2025
variable "install_kubectx" { type = bool }
2126
variable "kubeconfig" { type = string }
2227
variable "kubernetes_version" { type = string }

variables-operator.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,24 @@ variable "operator_install_helm" {
6565
type = bool
6666
}
6767

68+
variable "operator_install_istioctl" {
69+
default = false
70+
description = "Whether to install istioctl on the created operator host."
71+
type = bool
72+
}
73+
6874
variable "operator_install_k9s" {
6975
default = false
7076
description = "Whether to install k9s on the created operator host. NOTE: Provided only as a convenience and not supported by or sourced from Oracle - use at your own risk."
7177
type = bool
7278
}
7379

80+
variable "operator_install_kubectl_from_repo" {
81+
default = true
82+
description = "Whether to install kubectl on the created operator host from olcne repo."
83+
type = bool
84+
}
85+
7486
variable "operator_install_kubectx" {
7587
default = true
7688
description = "Whether to install kubectx/kubens on the created operator host. NOTE: Provided only as a convenience and not supported by or sourced from Oracle - use at your own risk."

0 commit comments

Comments
 (0)