Skip to content

Commit

Permalink
adding machine autoscaler inspect script
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Volkov committed Dec 13, 2024
1 parent f43d311 commit 5a79130
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
17 changes: 17 additions & 0 deletions scripts/CEE/machine-autoscaler-inspect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Machine Autoscaler Data Collector Script

## Purpose

This script is designed to collect and retrieve the machine autoscaler data from OpenShift cluster.

## Usage

```bash
ocm backplane managedjob create CEE/machine-autoscaler-inspect
```

## Important Notes

- The script utilizes the `oc` command-line tool, and the user running the script should have the necessary permissions to access the cluster.
- This script is read-only and does not modify any resources in the cluster.
- Ensure that the required tools (`oc`) are available in the environment where the script is executed.
22 changes: 22 additions & 0 deletions scripts/CEE/machine-autoscaler-inspect/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
file: script.sh
name: machine-autoscaler-inspect
shortDescription: Collects machine autoscaler inspect data.
description: |
Collects and prints the machine autoscaler resources data in yaml format from OpenShift cluster.
author: Alex Volkov
allowedGroups:
- SREP
- CEE
rbac:
clusterRoleRules:
- apiGroups:
- "autoscaling.openshift.io"
resources:
- "machineautoscalers"
verbs:
- "get"
- "list"
language: bash
customerDataAccess: false
24 changes: 24 additions & 0 deletions scripts/CEE/machine-autoscaler-inspect/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e
set -o nounset
set -o pipefail

#VARS
NAMESPACE="openshift-machine-api"

echo "Fetching machine autoscaler resources in namespace '$NAMESPACE'..."
# Fetch machine autoscaler names
MACHINE_AUTOSCALERS=$(oc get machineautoscaler -n "$NAMESPACE" -o jsonpath='{.items[*].metadata.name}')
if [ -z "$MACHINE_AUTOSCALERS" ]; then
echo "No machine autoscaler resources found in namespace '$NAMESPACE'."
exit 1
fi

echo "Collecting machine autoscaler resources..."
for AUTOSCALER in $MACHINE_AUTOSCALERS; do
# Print the current machine autoscaler YAML
if ! oc get machineautoscaler "$AUTOSCALER" -n "$NAMESPACE" -o yaml; then
echo "Failed to fetch details for machine autoscaler '$AUTOSCALER'. Skipping..."
fi
done

0 comments on commit 5a79130

Please sign in to comment.