Skip to content
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

Feat/delete os pod #206

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scripts/CEE/delete-os-pod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Delete Openshift Pod Script

## Purpose

This script is designed to delete a pod from OpenShift cluster core namespace

## Usage

Parameters:
- NAMESPACE: Namespace name where por to delete is running, must start with openshift-*.
- POD_NAME: Name of the pod to delete.

```bash
ocm backplane managedjob create CEE/delete-os-pod -p NAMESPACE=openshift-dns -p POD_NAME: dns-default-h7l2w
```


## 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.
- Ensure that the required tools (`oc`) are available in the environment where the script is executed.
28 changes: 28 additions & 0 deletions scripts/CEE/delete-os-pod/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
file: script.sh
name: delete-os-pod
shortDescription: Deletes a pod from openshift namespace
description: Deletes a single pod from openshift's reserved namespace.
author: Alex Volkov
allowedGroups:
- CEE
- SREP
rbac:
clusterRoleRules:
- apiGroups:
- ""
resources:
- "pods"
verbs:
- "delete"
- "get"

envs:
- key: NAMESPACE
description: Namespace name where por to delete is running, must start with openshift-*
optional: false
- key: POD_NAME
description: Name of the pod to delete
optional: false

language: bash
customerDataAccess: false
47 changes: 47 additions & 0 deletions scripts/CEE/delete-os-pod/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -e
set -o errexit
set -o nounset
set -o pipefail

## Input validation
### Check the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <pod_name> <namespace>"
fi

if [[ -z "${POD_NAME:-}" ]]; then
echo 'Variable POD_NAME cannot be blank'
exit 1
fi

if [[ -z "${NAMESPACE:-}" ]]; then
echo 'Variable NAMESPACE cannot be blank'
exit 1
fi

### Check namespace is "openshift-*"
if [[ ! "$NAMESPACE" =~ ^openshift-.*$ ]]; then
echo "The namespace must start with 'openshift-'"
exit 1
fi

## Delete the pod
delete_pod(){
echo -e "\nDeleting pod \"${POD_NAME}\" from \"${NAMESPACE}\" namespace."
oc delete pod "$POD_NAME" -n "$NAMESPACE"

if [ $? -eq 0 ]; then
echo -e "\n[SUCCESS] Pod '$POD_NAME' successfully deleted from namespace '$NAMESPACE'."
else
echo -e "\n[ERROR] Failed to delete pod '$POD_NAME' from namespace '$NAMESPACE'."
fi
}


main(){
delete_pod
}

main