This repository has the source code as well as the deployment for two Kubernetes CronJobs that will Hibernate and Resume your OpenShift clusters.
- Red Hat Advanced Cluster Management for Kubernetes 2.1
- OpenShift 4.5 and 4.6 clusters provisioned by ACM
- Log into your ACM Hub on OpenShift
- Run the command:
make setup-go
- Monitor the CornJobs
oc get cronjobs
The default settings is to have the clusters runnings from 8am - 6pm Mon - Fri EST. You can adjust the times by modifying the two CronJobs:
deploy/hibernating-cronjob.yaml
deploy/running-cronjob.yaml
It uses the standard CronJob format and the check is done against a UTC clock. For EDT, that means +4hrs.
The job will only target clusters deployed by Hive. It looks for the ClusterDeployment objects. If you put a label on either of these objects hibernate: skip
they will be ignored by both CronJobs.
make running-go
## OR
oc create -f deploy-go/hibernation-job.yaml
make hibernate-go
## OR
oc create -f deploy-go/running-job.yaml
Edit the ClusterDeployment resource for the cluster you want to change the state for. Find the spec.powerState
key and change the value to either: Hibernating
or Running
You'll need docker and a connection to a registry that your OpenShift can reach. Modify the Makefile and replace the value of REPO_URL
with your own registry URL. Next modify the two CronJobs to use your new image:
deploy-go/hibernating-cronjob.yaml
deploy-go/running-cronjob.yaml
Setup the following environment variables, then run python hibernate-cronjob/action.py
export TARGET_ACTION=hibernating # Or "running"
export CM_TOKEN= # Your OpenShift API token
export CM_API_URL # API URL for your cluster https://my.cluster.hostname.com:6443
Setup the following environment variables, then run go run ./pkg
export REPO_URL= # The repository you will upload your image too
export VERSION= # The image version you want to use
Time Zone | UTC offset | Example |
---|---|---|
EST | +5hr | 11:22EST = 16:22UTC |
EDT | +4hr | 11:22EDT = 15:22UTC |
PST | +8hr | 11:22PST = 19:22UTC |
- Added to the open-cluster-management community 2020-11-25