generated from terraform-ibm-modules/terraform-ibm-module-template
-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add support for major openshift version upgrade #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+159
−16
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bce7633
feat: add support for major openshift version upgrade
65e16ea
feat: add support for openshift major version upgrade
fb889fa
Merge branch 'main' into 15216-mvu
iamar7 5780ded
update script
b193603
resolve pc
iamar7 ccad3f8
add modules to test
412aad3
Merge branch '15216-mvu' of https://github.com/terraform-ibm-modules/…
0cd96a9
update toolchain
iamar7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule common-dev-assets
updated
26 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ############################################################################## | ||
| # OCP Cluster Version | ||
| ############################################################################## | ||
|
|
||
| data "external" "get_ocp_cluster_version" { | ||
| program = ["bash", "${path.module}/scripts/get_ocp_cluster_version.sh"] | ||
|
|
||
| query = { | ||
| cluster_name = var.cluster_name | ||
| ibmcloud_api_key = var.ibmcloud_api_key | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ############################################################################## | ||
| # Outputs | ||
| ############################################################################## | ||
|
|
||
| output "ocp_version" { | ||
| description = "OpenShift version of the cluster" | ||
| value = tonumber(data.external.get_ocp_cluster_version.result["ocp_version"]) | ||
| } |
54 changes: 54 additions & 0 deletions
54
modules/get-ocp-version/scripts/get_ocp_cluster_version.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/bin/bash | ||
|
|
||
| ## Returns the OCP major.minor version for the given cluster | ||
| ## Script is designed to be used with Terraform "external" data source | ||
| ## It always outputs JSON (even on error) so Terraform plan/apply does not break | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| login(){ | ||
| # Login into the IBM Cloud CLI | ||
| echo "[login] Login to IBM Cloud CLI" >&2 | ||
| DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| "$DIR"/ibm_cloud_login.sh >/dev/null 2>&1 | ||
| echo "[login] Login complete" >&2 | ||
| } | ||
|
|
||
| get_ocp_version(){ | ||
| local cluster_name=$1 | ||
| echo " Retrieving OCP version for cluster $cluster_name" >&2 | ||
|
|
||
| local output | ||
| output=$(ibmcloud oc cluster get -c "$cluster_name" --output json 2>/dev/null || true) | ||
|
|
||
| local version | ||
| version=$(echo "$output" | jq -r '.masterKubeVersion' | cut -d. -f1,2) | ||
|
|
||
| if [[ -z "$version" || "$version" == "null" ]]; then | ||
| echo "Could not retrieve version for cluster $cluster_name" >&2 | ||
| version="-1" | ||
| fi | ||
|
|
||
| echo "$version" | ||
| } | ||
|
|
||
| ## Always return JSON even if something fails | ||
| handle_error() { | ||
| echo '{"ocp_version": "-1"}' | ||
| exit 0 | ||
| } | ||
|
|
||
| ## Parse variables passed from Terraform "query" | ||
| ## (reads stdin JSON and converts to shell vars) | ||
| eval "$(jq -r '@sh "cluster_name=\(.cluster_name) IBMCLOUD_API_KEY=\(.ibmcloud_api_key)"')" | ||
| export IBMCLOUD_API_KEY | ||
|
|
||
| ## Trap all errors after parsing input | ||
| trap 'handle_error' ERR | ||
|
|
||
| ## Login and retrieve version | ||
| login | ||
| ocp_version=$(get_ocp_version "$cluster_name") | ||
|
|
||
| ## Return JSON to Terraform | ||
| jq -n -r --arg ocp_version "$ocp_version" '{"ocp_version":$ocp_version}' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| attempts=1 | ||
| # Expects the environment variable $IBMCLOUD_API_KEY to be set | ||
| until ibmcloud login -q --no-region || [ $attempts -ge 3 ]; do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be using cli commands due to this issue. |
||
| attempts=$((attempts+1)) | ||
| echo "Error logging in to IBM Cloud CLI..." >&2 | ||
| sleep 5 | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ############################################################################## | ||
| # Input Variables | ||
| ############################################################################## | ||
|
|
||
| variable "ibmcloud_api_key" { | ||
| description = "APIkey that's associated with the account to use, set via environment variable TF_VAR_ibmcloud_api_key" | ||
| type = string | ||
| sensitive = true | ||
| } | ||
|
|
||
| variable "cluster_name" { | ||
| type = string | ||
| description = "Name of the target IBM Cloud OpenShift Cluster" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| terraform { | ||
| required_version = ">= 1.9.0" | ||
| required_providers { | ||
| external = { | ||
| source = "hashicorp/external" | ||
| version = ">= 2.2.3" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.