Skip to content

Commit c603b0b

Browse files
authored
feat: add the ability to disable / enable the OCP console using new input enable_ocp_console (#588)
1 parent a10425b commit c603b0b

File tree

8 files changed

+113
-0
lines changed

8 files changed

+113
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ Optionally, you need the following permissions to attach Access Management tags
285285
| [null_resource.config_map_status](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
286286
| [null_resource.confirm_lb_active](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
287287
| [null_resource.confirm_network_healthy](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
288+
| [null_resource.ocp_console_management](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
288289
| [null_resource.reset_api_key](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
289290
| [ibm_container_addons.existing_addons](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_addons) | data source |
290291
| [ibm_container_cluster_config.cluster_config](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/data-sources/container_cluster_config) | data source |
@@ -316,6 +317,7 @@ Optionally, you need the following permissions to attach Access Management tags
316317
| <a name="input_custom_security_group_ids"></a> [custom\_security\_group\_ids](#input\_custom\_security\_group\_ids) | Security groups to add to all worker nodes. This comes in addition to the IBM maintained security group if attach\_ibm\_managed\_security\_group is set to true. If this variable is set, the default VPC security group is NOT assigned to the worker nodes. | `list(string)` | `null` | no |
317318
| <a name="input_disable_outbound_traffic_protection"></a> [disable\_outbound\_traffic\_protection](#input\_disable\_outbound\_traffic\_protection) | Whether to allow public outbound access from the cluster workers. This is only applicable for `ocp_version` 4.15 | `bool` | `false` | no |
318319
| <a name="input_disable_public_endpoint"></a> [disable\_public\_endpoint](#input\_disable\_public\_endpoint) | Whether access to the public service endpoint is disabled when the cluster is created. Does not affect existing clusters. You can't disable a public endpoint on an existing cluster, so you can't convert a public cluster to a private cluster. To change a public endpoint to private, create another cluster with this input set to `true`. | `bool` | `false` | no |
320+
| <a name="input_enable_ocp_console"></a> [enable\_ocp\_console](#input\_enable\_ocp\_console) | Flag to specify whether to enable or disable the OpenShift console. | `bool` | `true` | no |
319321
| <a name="input_enable_registry_storage"></a> [enable\_registry\_storage](#input\_enable\_registry\_storage) | Set to `true` to enable IBM Cloud Object Storage for the Red Hat OpenShift internal image registry. Set to `false` only for new cluster deployments in an account that is allowlisted for this feature. | `bool` | `true` | no |
320322
| <a name="input_existing_cos_id"></a> [existing\_cos\_id](#input\_existing\_cos\_id) | The COS id of an already existing COS instance to use for OpenShift internal registry storage. Only required if 'enable\_registry\_storage' and 'use\_existing\_cos' are true | `string` | `null` | no |
321323
| <a name="input_force_delete_storage"></a> [force\_delete\_storage](#input\_force\_delete\_storage) | Flag indicating whether or not to delete attached storage when destroying the cluster - Default: false | `bool` | `false` | no |

examples/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ module "ocp_fscloud" {
250250
additional_lb_security_group_ids = [module.custom_sg["custom-lb-sg"].security_group_id]
251251
use_private_endpoint = true
252252
ocp_entitlement = var.ocp_entitlement
253+
enable_ocp_console = false
253254
kms_config = {
254255
instance_id = var.hpcs_instance_guid
255256
crk_id = local.cluster_hpcs_cluster_key_id

main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,25 @@ resource "null_resource" "confirm_network_healthy" {
456456
}
457457
}
458458

459+
##############################################################################
460+
# OCP Console Patch enablement
461+
##############################################################################
462+
resource "null_resource" "ocp_console_management" {
463+
464+
depends_on = [ibm_container_vpc_cluster.cluster, ibm_container_vpc_cluster.autoscaling_cluster, ibm_container_vpc_worker_pool.pool, ibm_container_vpc_worker_pool.autoscaling_pool]
465+
triggers = {
466+
enable_ocp_console = var.enable_ocp_console
467+
}
468+
provisioner "local-exec" {
469+
command = "${path.module}/scripts/enable_disable_ocp_console.sh"
470+
interpreter = ["/bin/bash", "-c"]
471+
environment = {
472+
KUBECONFIG = data.ibm_container_cluster_config.cluster_config[0].config_file_path
473+
ENABLE_OCP_CONSOLE = var.enable_ocp_console
474+
}
475+
}
476+
}
477+
459478
##############################################################################
460479
# Addons
461480
##############################################################################

modules/fscloud/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ No resources.
123123
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name that will be assigned to the provisioned cluster | `string` | n/a | yes |
124124
| <a name="input_cluster_ready_when"></a> [cluster\_ready\_when](#input\_cluster\_ready\_when) | The cluster is ready when one of the following: MasterNodeReady (not recommended), OneWorkerNodeReady, Normal, IngressReady | `string` | `"IngressReady"` | no |
125125
| <a name="input_custom_security_group_ids"></a> [custom\_security\_group\_ids](#input\_custom\_security\_group\_ids) | Security groups to add to all worker nodes. This comes in addition to the IBM maintained security group if use\_ibm\_managed\_security\_group is set to true. If this variable is set, the default VPC security group is NOT assigned to the worker nodes. | `list(string)` | `null` | no |
126+
| <a name="input_enable_ocp_console"></a> [enable\_ocp\_console](#input\_enable\_ocp\_console) | Flag to specify whether to enable or disable the OpenShift console. | `bool` | `true` | no |
126127
| <a name="input_existing_cos_id"></a> [existing\_cos\_id](#input\_existing\_cos\_id) | The COS id of an already existing COS instance | `string` | n/a | yes |
127128
| <a name="input_force_delete_storage"></a> [force\_delete\_storage](#input\_force\_delete\_storage) | Flag indicating whether or not to delete attached storage when destroying the cluster - Default: false | `bool` | `false` | no |
128129
| <a name="input_ignore_worker_pool_size_changes"></a> [ignore\_worker\_pool\_size\_changes](#input\_ignore\_worker\_pool\_size\_changes) | Enable if using worker autoscaling. Stops Terraform managing worker count | `bool` | `false` | no |

modules/fscloud/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ module "fscloud" {
3535
number_of_lbs = var.number_of_lbs
3636
additional_vpe_security_group_ids = var.additional_vpe_security_group_ids
3737
cbr_rules = var.cbr_rules
38+
enable_ocp_console = var.enable_ocp_console
3839
}

modules/fscloud/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,9 @@ variable "cbr_rules" {
265265
description = "The list of context-based restriction rules to create."
266266
default = []
267267
}
268+
269+
variable "enable_ocp_console" {
270+
description = "Flag to specify whether to enable or disable the OpenShift console."
271+
type = bool
272+
default = true
273+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
6+
PATCH_APPLY="oc patch consoles.operator.openshift.io cluster --patch '{\"spec\":{\"managementState\":\"Managed\"}}' --type=merge"
7+
PATCH_REMOVE="oc patch consoles.operator.openshift.io cluster --patch '{\"spec\":{\"managementState\":\"Removed\"}}' --type=merge"
8+
MAX_ATTEMPTS=10
9+
RETRY_WAIT=5
10+
11+
function check_oc_cli() {
12+
if ! command -v oc &> /dev/null; then
13+
echo "Error: OpenShift CLI (oc) is not installed. Exiting."
14+
exit 1
15+
fi
16+
}
17+
18+
function apply_oc_patch() {
19+
20+
local attempt=0
21+
while [ $attempt -lt $MAX_ATTEMPTS ]; do
22+
echo "Attempt $((attempt+1)) of $MAX_ATTEMPTS: Applying OpenShift Console patch..."
23+
24+
if eval "$PATCH_APPLY"; then
25+
echo "Patch applied successfully."
26+
return 0
27+
else
28+
echo "Failed to apply patch. Retrying in ${RETRY_WAIT}s..."
29+
sleep $RETRY_WAIT
30+
((attempt++))
31+
RETRY_WAIT=$((RETRY_WAIT * 2))
32+
fi
33+
done
34+
35+
echo "Maximum retry attempts reached. Could not apply patch."
36+
exit 1
37+
}
38+
39+
function remove_oc_patch() {
40+
41+
local attempt=0
42+
while [ $attempt -lt $MAX_ATTEMPTS ]; do
43+
echo "Attempt $((attempt+1)) of $MAX_ATTEMPTS: Removing OpenShift Console patch..."
44+
45+
if eval "$PATCH_REMOVE"; then
46+
echo "Patch removed successfully."
47+
return 0
48+
else
49+
echo "Failed to remove patch. Retrying in ${RETRY_WAIT}s..."
50+
sleep $RETRY_WAIT
51+
((attempt++))
52+
RETRY_WAIT=$((RETRY_WAIT * 2))
53+
fi
54+
done
55+
56+
echo "Maximum retry attempts reached. Could not remove patch."
57+
exit 1
58+
}
59+
60+
echo "========================================="
61+
62+
if [[ -z "${ENABLE_OCP_CONSOLE}" ]]; then
63+
echo "ENABLE_OCP_CONSOLE must be set" >&2
64+
exit 1
65+
fi
66+
67+
check_oc_cli
68+
69+
if [ "${ENABLE_OCP_CONSOLE}" == "true" ]; then
70+
echo "Enabling the OpenShift Console"
71+
apply_oc_patch
72+
else
73+
echo "Disabling the OpenShift Console"
74+
remove_oc_patch
75+
fi
76+
77+
echo "========================================="

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ variable "cluster_config_endpoint_type" {
333333
}
334334
}
335335

336+
variable "enable_ocp_console" {
337+
description = "Flag to specify whether to enable or disable the OpenShift console."
338+
type = bool
339+
default = true
340+
}
341+
336342
##############################################################################
337343

338344
##############################################################

0 commit comments

Comments
 (0)