From 5a79130ea4755fadd6f0c685c511f46aac4970ea Mon Sep 17 00:00:00 2001 From: Alex Volkov Date: Fri, 13 Dec 2024 14:04:19 +0100 Subject: [PATCH] adding machine autoscaler inspect script --- .../CEE/machine-autoscaler-inspect/README.md | 17 +++++++++++++ .../machine-autoscaler-inspect/metadata.yaml | 22 +++++++++++++++++ .../CEE/machine-autoscaler-inspect/script.sh | 24 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 scripts/CEE/machine-autoscaler-inspect/README.md create mode 100644 scripts/CEE/machine-autoscaler-inspect/metadata.yaml create mode 100755 scripts/CEE/machine-autoscaler-inspect/script.sh diff --git a/scripts/CEE/machine-autoscaler-inspect/README.md b/scripts/CEE/machine-autoscaler-inspect/README.md new file mode 100644 index 0000000..274fa93 --- /dev/null +++ b/scripts/CEE/machine-autoscaler-inspect/README.md @@ -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. diff --git a/scripts/CEE/machine-autoscaler-inspect/metadata.yaml b/scripts/CEE/machine-autoscaler-inspect/metadata.yaml new file mode 100644 index 0000000..c383464 --- /dev/null +++ b/scripts/CEE/machine-autoscaler-inspect/metadata.yaml @@ -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 diff --git a/scripts/CEE/machine-autoscaler-inspect/script.sh b/scripts/CEE/machine-autoscaler-inspect/script.sh new file mode 100755 index 0000000..3f39851 --- /dev/null +++ b/scripts/CEE/machine-autoscaler-inspect/script.sh @@ -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