Skip to content

Commit b7be7e3

Browse files
mounicatellabatiraagamounica
andauthored
feat: Updates: <br>- Add binaries installation support in script for Waypoint runtime compatibilty <br>- use terraform_data resource in-place of null_resource(#95)
* feat: add binary installation support for Waypoint runtime compatibility * fix: remove local duplicates * fix: remove local duplicates * fix: update permissions to install-binaries script * fix: removing unused binary JQ * chore: update subscription version to latest v4.19.15 * fix: removed unused null provider declaration * fix: removed unused null provider block in readme * fix: fixing the pipeline issues * " fix: fixing the pipeline issues" This reverts commit e4a7fa0. * chore: replace triggers * fix: fixed pre-commit errors * fix: fixed ci pipeline issues * fix: fixing indentations issues * SKIP UPGRADE TEST * fix: remove triggers and update depends on for installed binaries * fix: updated tag version --------- Co-authored-by: raagamounica <mounica.tellabati@ibm.com>
1 parent ebb25e1 commit b7be7e3

File tree

10 files changed

+114
-43
lines changed

10 files changed

+114
-43
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ This module configures Openshift Virtualization on an IBM Cloud Red Hat OpenShif
2424
* [Examples](./examples)
2525
:information_source: Ctrl/Cmd+Click or right-click on the Schematics deploy button to open in a new tab
2626
* <a href="./examples/basic">Basic example</a> <a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=ocp-virtualization-basic-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-ocp-virtualization/tree/main/examples/basic"><img src="https://img.shields.io/badge/Deploy%20with IBM%20Cloud%20Schematics-0f62fe?logo=ibm&logoColor=white&labelColor=0f62fe" alt="Deploy with IBM Cloud Schematics" style="height: 16px; vertical-align: text-bottom; margin-left: 5px;"></a>
27+
* [Deployable Architectures](./solutions)
28+
* <a href="./solutions/fully-configurable">Cloud automation for OpenShift Virtualization (Fully configurable)</a>
29+
* <a href="./solutions/quickstart">Cloud automation for OpenShift Virtualization (Quickstart)</a>
2730
* [Contributing](#contributing)
2831
<!-- END OVERVIEW HOOK -->
2932

@@ -113,7 +116,6 @@ You need the following permissions to run this module.
113116
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 3.0.0, <4.0.0 |
114117
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.79.1, <2.0.0 |
115118
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 3.0.0, < 4.0.0 |
116-
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 3.2.1, < 4.0.0 |
117119
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.1, < 1.0.0 |
118120

119121
### Modules
@@ -128,10 +130,11 @@ No modules.
128130
| [helm_release.subscription](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
129131
| [kubernetes_config_map_v1_data.disable_default_storageclass](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/config_map_v1_data) | resource |
130132
| [kubernetes_config_map_v1_data.set_vpc_file_default_storage_class](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/config_map_v1_data) | resource |
131-
| [null_resource.config_map_status](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
132-
| [null_resource.enable_catalog_source](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
133-
| [null_resource.storageprofile_status](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
134-
| [null_resource.update_storage_profile](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
133+
| [terraform_data.config_map_status](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
134+
| [terraform_data.enable_catalog_source](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
135+
| [terraform_data.install_required_binaries](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
136+
| [terraform_data.storageprofile_status](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
137+
| [terraform_data.update_storage_profile](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/resources/data) | resource |
135138
| [time_sleep.wait_for_subscription](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
136139
| [ibm_container_cluster_config.cluster_config](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_cluster_config) | data source |
137140
| [ibm_container_vpc_cluster.cluster](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_vpc_cluster) | data source |
@@ -144,6 +147,7 @@ No modules.
144147
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | The ID of the cluster to deploy the agents in. | `string` | n/a | yes |
145148
| <a name="input_cluster_resource_group_id"></a> [cluster\_resource\_group\_id](#input\_cluster\_resource\_group\_id) | The resource group ID of the cluster. | `string` | n/a | yes |
146149
| <a name="input_infra_node_selectors"></a> [infra\_node\_selectors](#input\_infra\_node\_selectors) | List of infra node selectors to apply to HyperConverged pods. [Learn more](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). | <pre>list(object({<br/> key = string<br/> values = list(string)<br/> }))</pre> | <pre>[<br/> {<br/> "key": "ibm-cloud.kubernetes.io/server-type",<br/> "values": [<br/> "virtual",<br/> "physical"<br/> ]<br/> }<br/>]</pre> | no |
150+
| <a name="input_install_required_binaries"></a> [install\_required\_binaries](#input\_install\_required\_binaries) | When true, run a script to ensure required CLI binary (kubectl) is available in the runtime; if missing the script will attempt to download them to /tmp. Set to false to skip. | `bool` | `true` | no |
147151
| <a name="input_vpc_file_default_storage_class"></a> [vpc\_file\_default\_storage\_class](#input\_vpc\_file\_default\_storage\_class) | The name of the VPC File storage class which will be set as the default storage class. | `string` | `"ibmc-vpc-file-metro-1000-iops"` | no |
148152
| <a name="input_wait_till"></a> [wait\_till](#input\_wait\_till) | To avoid long wait times when you run your Terraform code, you can specify the stage when you want Terraform to mark the cluster resource creation as completed. Depending on what stage you choose, the cluster creation might not be fully completed and continues to run in the background. However, your Terraform code can continue to run without waiting for the cluster to be fully created. Supported args are `MasterNodeReady`, `OneWorkerNodeReady`, `IngressReady` and `Normal`. | `string` | `"Normal"` | no |
149153
| <a name="input_wait_till_timeout"></a> [wait\_till\_timeout](#input\_wait\_till\_timeout) | Timeout for wait\_till in minutes. | `number` | `90` | no |

main.tf

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ resource "kubernetes_config_map_v1_data" "disable_default_storageclass" {
2626
force = true
2727
}
2828

29-
resource "null_resource" "config_map_status" {
29+
resource "terraform_data" "install_required_binaries" {
30+
count = var.install_required_binaries ? 1 : 0
3031
provisioner "local-exec" {
31-
command = "${path.module}/scripts/get_config_map_status.sh"
32+
command = "${path.module}/scripts/install-binaries.sh ${local.binaries_path}"
33+
interpreter = ["/bin/bash", "-c"]
34+
}
35+
}
36+
37+
resource "terraform_data" "config_map_status" {
38+
depends_on = [terraform_data.install_required_binaries]
39+
provisioner "local-exec" {
40+
command = "${path.module}/scripts/get_config_map_status.sh ${local.binaries_path}"
3241
interpreter = ["/bin/bash", "-c"]
3342
environment = {
3443
KUBECONFIG = data.ibm_container_cluster_config.cluster_config.config_file_path
@@ -37,7 +46,7 @@ resource "null_resource" "config_map_status" {
3746
}
3847

3948
resource "kubernetes_config_map_v1_data" "set_vpc_file_default_storage_class" {
40-
depends_on = [null_resource.config_map_status]
49+
depends_on = [terraform_data.config_map_status, terraform_data.install_required_binaries]
4150
metadata {
4251
name = "addon-vpc-file-csi-driver-configmap"
4352
namespace = "kube-system"
@@ -50,9 +59,10 @@ resource "kubernetes_config_map_v1_data" "set_vpc_file_default_storage_class" {
5059
force = true
5160
}
5261

53-
resource "null_resource" "enable_catalog_source" {
62+
resource "terraform_data" "enable_catalog_source" {
63+
depends_on = [terraform_data.install_required_binaries]
5464
provisioner "local-exec" {
55-
command = "${path.module}/scripts/enable_catalog_source.sh"
65+
command = "${path.module}/scripts/enable_catalog_source.sh ${local.binaries_path}"
5666
interpreter = ["/bin/bash", "-c"]
5767
environment = {
5868
KUBECONFIG = data.ibm_container_cluster_config.cluster_config.config_file_path
@@ -65,13 +75,13 @@ resource "null_resource" "enable_catalog_source" {
6575
########################################################################################################################
6676

6777
locals {
68-
subscription_version = "v4.17.4"
78+
subscription_version = "v4.19.15"
6979
subscription_chart_location = "${path.module}/chart/subscription"
7080
namespace = "openshift-cnv" # This is hard-coded because using any other namespace will break the virtualization.
7181
}
7282

7383
resource "helm_release" "subscription" {
74-
depends_on = [null_resource.enable_catalog_source]
84+
depends_on = [terraform_data.enable_catalog_source]
7585
name = "${data.ibm_container_vpc_cluster.cluster.name}-subscription"
7686
chart = local.subscription_chart_location
7787
namespace = local.namespace
@@ -92,10 +102,11 @@ resource "helm_release" "subscription" {
92102

93103
#########################################################################################################################
94104
# Deploying the OpenShift Virtualization Operator
95-
########################################################################################################################
105+
#########################################################################################################################
96106

97107
locals {
98108
operator_chart_location = "${path.module}/chart/operator"
109+
binaries_path = "/tmp"
99110
}
100111

101112
resource "time_sleep" "wait_for_subscription" {
@@ -124,22 +135,21 @@ resource "helm_release" "operator" {
124135
]
125136
}
126137

127-
resource "null_resource" "storageprofile_status" {
128-
depends_on = [helm_release.operator]
129-
138+
resource "terraform_data" "storageprofile_status" {
139+
depends_on = [helm_release.operator, terraform_data.install_required_binaries]
130140
provisioner "local-exec" {
131-
command = "${path.module}/scripts/confirm-storageprofile-status.sh"
141+
command = "${path.module}/scripts/confirm-storageprofile-status.sh ${local.binaries_path}"
132142
interpreter = ["/bin/bash", "-c"]
133143
environment = {
134144
KUBECONFIG = data.ibm_container_cluster_config.cluster_config.config_file_path
135145
}
136146
}
137147
}
138148

139-
resource "null_resource" "update_storage_profile" {
140-
depends_on = [null_resource.storageprofile_status]
149+
resource "terraform_data" "update_storage_profile" {
150+
depends_on = [terraform_data.storageprofile_status, terraform_data.install_required_binaries]
141151
provisioner "local-exec" {
142-
command = "${path.module}/scripts/update_storage_profile.sh ${var.vpc_file_default_storage_class}"
152+
command = "${path.module}/scripts/update_storage_profile.sh ${var.vpc_file_default_storage_class} ${local.binaries_path}"
143153
interpreter = ["/bin/bash", "-c"]
144154
environment = {
145155
KUBECONFIG = data.ibm_container_cluster_config.cluster_config.config_file_path

scripts/confirm-storageprofile-status.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
set -e
44

5+
# The binaries downloaded by the install-binaries script are located in the /tmp directory.
6+
export PATH=$PATH:${1:-"/tmp"}
7+
58
attempt=0
69
retry_wait_time=60
710
MAX_ATTEMPTS=10

scripts/enable_catalog_source.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
22

33
set -euo pipefail
44

5+
# The binaries downloaded by the install-binaries script are located in the /tmp directory.
6+
export PATH=$PATH:${1:-"/tmp"}
57

6-
PATCH_APPLY="oc patch operatorhub cluster --type json -p '[{\"op\": \"add\", \"path\": \"/spec/disableAllDefaultSources\", \"value\": false}]'"
8+
PATCH_APPLY="kubectl patch operatorhub cluster --type=json -p '[{\"op\": \"add\", \"path\": \"/spec/disableAllDefaultSources\", \"value\": false}]'"
79
MAX_ATTEMPTS=10
810

9-
function check_oc_cli() {
10-
if ! command -v oc &> /dev/null; then
11-
echo "Error: OpenShift CLI (oc) is not installed. Exiting."
11+
function check_kubectl_cli() {
12+
if ! command -v kubectl &> /dev/null; then
13+
echo "Error: Kubernetes CLI (kubectl) is not installed. Exiting."
1214
exit 1
1315
fi
1416
}
1517

16-
function apply_oc_patch() {
18+
function apply_kubectl_patch() {
1719

1820
local attempt=0
1921
local retry_wait_time=5
2022

2123
while [ $attempt -lt $MAX_ATTEMPTS ]; do
22-
echo "Attempt $((attempt+1)) of $MAX_ATTEMPTS: Applying OpenShift Console patch..."
24+
echo "Attempt $((attempt + 1)) of $MAX_ATTEMPTS: Applying Kubernetes patch..."
2325

2426
if eval "$PATCH_APPLY"; then
2527
echo "Patch applied successfully."
@@ -37,9 +39,9 @@ function apply_oc_patch() {
3739

3840
echo "========================================="
3941

40-
check_oc_cli
42+
check_kubectl_cli
4143

42-
echo "Enabling default catalog source"
43-
apply_oc_patch
44+
echo "Enabling default catalog source"
45+
apply_kubectl_patch
4446

4547
echo "========================================="

scripts/get_config_map_status.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
set -e
44

5+
# The binaries downloaded by the install-binaries script are located in the /tmp directory.
6+
export PATH=$PATH:${1:-"/tmp"}
7+
58
CONFIGMAP_NAME="addon-vpc-file-csi-driver-configmap"
69
NAMESPACE="kube-system"
710
COUNTER=0

scripts/install-binaries.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# Installs required CLI binaries into the provided directory (defaults to /tmp).
4+
set -o errexit
5+
set -o pipefail
6+
7+
DIRECTORY=${1:-"/tmp"}
8+
export PATH=$PATH:$DIRECTORY
9+
# renovate: datasource=github-tags depName=terraform-ibm-modules/common-bash-library
10+
TAG=v0.2.1
11+
TMP_DIR=$(mktemp -d "${DIRECTORY}/common-bash-XXXXX")
12+
13+
echo "Downloading common-bash-library version ${TAG}."
14+
15+
# download common-bash-library
16+
curl --silent \
17+
--connect-timeout 5 \
18+
--max-time 10 \
19+
--retry 3 \
20+
--retry-delay 2 \
21+
--retry-connrefused \
22+
--fail \
23+
--show-error \
24+
--location \
25+
--output "${TMP_DIR}/common-bash.tar.gz" \
26+
"https://github.com/terraform-ibm-modules/common-bash-library/archive/refs/tags/$TAG.tar.gz"
27+
28+
mkdir -p "${TMP_DIR}/common-bash-library"
29+
tar -xzf "${TMP_DIR}/common-bash.tar.gz" -C "${TMP_DIR}"
30+
rm -f "${TMP_DIR}/common-bash.tar.gz"
31+
32+
# shellcheck disable=SC1091,SC1090
33+
source "${TMP_DIR}/common-bash-library-${TAG#v}/common/common.sh"
34+
35+
echo "Installing kubectl."
36+
install_kubectl "latest" "${DIRECTORY}" "true"
37+
38+
rm -rf "$TMP_DIR"
39+
40+
echo "Installation complete successfully"

scripts/update_storage_profile.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@
22

33
set -euo pipefail
44

5+
# STORAGE_CLASS is the first argument; optional binaries path is the second argument.
56
STORAGE_CLASS="$1"
7+
# The binaries downloaded by the install-binaries script are located in the /tmp directory.
8+
export PATH=$PATH:${2:-"/tmp"}
9+
10+
PATCH_PAYLOAD='{"spec":{"claimPropertySets":[{"accessModes":["ReadWriteMany"],"volumeMode":"Filesystem"}]}}'
11+
STORAGE_PROFILE="kubectl patch storageprofile $STORAGE_CLASS --type=merge -p '$PATCH_PAYLOAD'"
612

7-
STORAGE_PROFILE="oc patch storageprofile $STORAGE_CLASS -p '{\"spec\": {\"claimPropertySets\": [{\"accessModes\": [\"ReadWriteMany\"], \"volumeMode\": \"Filesystem\"}]}}' --type merge"
813
MAX_ATTEMPTS=10
914
RETRY_WAIT=5
1015

11-
function check_oc_cli() {
12-
if ! command -v oc &>/dev/null; then
13-
echo "Error: OpenShift CLI (oc) is not installed. Exiting."
16+
function check_kubectl_cli() {
17+
if ! command -v kubectl &>/dev/null; then
18+
echo "Error: Kubernetes CLI (kubectl) is not installed. Exiting."
1419
exit 1
1520
fi
1621
}
1722

18-
function apply_oc_patch() {
19-
23+
function apply_kubectl_patch() {
2024
local attempt=0
25+
2126
while [ $attempt -lt $MAX_ATTEMPTS ]; do
22-
echo "Attempt $((attempt + 1)) of $MAX_ATTEMPTS: Applying OpenShift Console patch..."
27+
echo "Attempt $((attempt + 1)) of $MAX_ATTEMPTS: Applying Kubernetes patch..."
2328

2429
if eval "$STORAGE_PROFILE"; then
2530
echo "Patch applied successfully."
@@ -38,6 +43,7 @@ function apply_oc_patch() {
3843

3944
echo "========================================="
4045

41-
check_oc_cli
42-
apply_oc_patch
46+
check_kubectl_cli
47+
apply_kubectl_patch
48+
4349
echo "========================================="

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ variable "workloads_node_selectors" {
7474
values = ["physical"]
7575
}]
7676
}
77+
78+
variable "install_required_binaries" {
79+
type = bool
80+
default = true
81+
description = "When true, run a script to ensure required CLI binary (kubectl) is available in the runtime; if missing the script will attempt to download them to /tmp. Set to false to skip."
82+
nullable = false
83+
}

version.tf

100644100755
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ terraform {
1010
source = "hashicorp/helm"
1111
version = ">= 3.0.0, <4.0.0"
1212
}
13-
null = {
14-
source = "hashicorp/null"
15-
version = ">= 3.2.1, < 4.0.0"
16-
}
1713
kubernetes = {
1814
source = "hashicorp/kubernetes"
1915
version = ">= 3.0.0, < 4.0.0"

0 commit comments

Comments
 (0)