Skip to content

Instantly share code, notes, and snippets.

@rcarrata
Last active July 22, 2022 10:15
Show Gist options
  • Save rcarrata/db67437f42e05dcfedf8406e20645511 to your computer and use it in GitHub Desktop.
Save rcarrata/db67437f42e05dcfedf8406e20645511 to your computer and use it in GitHub Desktop.
Hibernate Clusters with OpenShift Cluster Manager (OCM)

OCM Management - Hibernate

With Hibernate, OpenShift clusters can be stopped and started by simply shutting down their machines and starting them back up

On the other hand, developers can view or programatically manage clusters through https://api.openshift.com/.

Hibernate using api.openshift.com

TOKEN="Grabbed from console.redhat.com/openshift/token"
  • Use the Token to authenticate against Red Hat SSO to get the access_token:
AUTH_HEADER="Basic $(echo cloud-services: | base64)"

ACCESS_TOKEN=$(curl -H "Authorization: $AUTH_HEADER" -s https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token -d grant_type=refresh_token -d refresh_token=$TOKEN | jq -r .access_token)
  • Get Access to the Clusters
 curl -H "Authorization: Bearer $ACCESS_TOKEN" https://api.openshift.com/api/clusters_mgmt/v1/clusters | jq .
  • Define the Cluster ID for the cluster
ID="xxxxxxxx"
  • Hibernate the cluster
curl -v -X 'POST' -H "Authorization: Bearer $ACCESS_TOKEN" "https://api.openshift.com/api/clusters_mgmt/v1/clusters/${ID}/hibernate" | jq -r .
  • Resume the Cluster state
curl -v -X 'POST' -H "Authorization: Bearer $ACCESS_TOKEN" "https://api.openshift.com/api/clusters_mgmt/v1/clusters/${ID}/resume" | jq -r .

Hibernate using the OCM CLI

ocm login --token=$TOKEN
  • Check the status of the cluster:
ocm list clusters --no-headers | grep gcp | grep mobb
xxxxxxxx  mobb-infra-gcp                https://api.mobb-infra-gcp.xxxx.p2.openshiftapps.com:6443   4.10.13             osd             gcp             us-east1        running
  • Extract the ID of the cluster
ID=$(ocm list clusters --no-headers | grep gcp | grep mobb | awk '{ print $1 }')
  • Hibernate the Cluster using their ID
ocm hibernate cluster $ID
  • Resume the Cluster using their ID
ocm resume cluster $ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment