-
Notifications
You must be signed in to change notification settings - Fork 243
Cleanup namespaces #4985
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
Merged
openshift-merge-robot
merged 16 commits into
redhat-developer:main
from
anandrkskd:test/cleanup
Sep 3, 2021
Merged
Cleanup namespaces #4985
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1c5c914
Script for cleaning projects
anandrkskd 5af1286
adding script,function for cleaning projects
anandrkskd 33f7836
generify function
anandrkskd 18e5c1c
updated with comment
anandrkskd 92a04aa
update script and use ioutil.writefile
anandrkskd 2bc6d42
file permission change to 0600
anandrkskd f5d2d12
add labels and label checks
anandrkskd 1e146dd
rebase
anandrkskd eb2b2fc
rebase typo fix
anandrkskd 5c24fa6
remove labels, add configmaps with data, team and type
anandrkskd 4326356
use odo to create project
anandrkskd df0f27c
add team check for cleanup
anandrkskd 387cd5f
remove namespace labeling
anandrkskd 7fee700
rebase
anandrkskd 1f88760
Merge branch 'main' into test/cleanup
anandrkskd 8043452
fix lint error
anandrkskd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env sh | ||
# this scripts logins as kubeadmin and removes the namespaces that are more than oneday old. | ||
# this script is used in a kubernetes cronjob for PSI/IBM cloud openshift cluster. | ||
|
||
# login as kubeadmin | ||
if [[ $CLUSTER_TYPE == "PSI" ]]; then | ||
 #PSI cluster login | ||
 oc login -u kubeadmin -p ${OCP4X_KUBEADMIN_PASSWORD} --insecure-skip-tls-verify ${OCP4X_API_URL} | ||
else | ||
 # Login to IBM Cloud using service account API Key | ||
 ibmcloud login --apikey $IBMC_OCP47_APIKEY -a cloud.ibm.com -r eu-de -g "Developer CI and QE" | ||
 | ||
 # Login to cluster in IBM Cloud using cluster API key | ||
 oc login --token=$IBMC_OCLOGIN_APIKEY --server=$IBMC_OCP47_SERVER | ||
fi | ||
|
||
# PROJECT_AND_TIME var will contain namespace and date with time seperated with `|` | ||
# PROJECT_AND_TIME doesn't contain openshift/ibm/kube namespace | ||
# eg. cmd-push-test157kgb|2021-08-17T12:40:20Z | ||
PROJECT_AND_TIME=$(kubectl get projects -o jsonpath='{range .items[*]}{.metadata.name}{"|"}{.metadata.creationTimestamp} {"\n"}{end}' | grep -v '^openshift\|^kube\|^default\|^ibm\|^calico\|^tigera\|^odo-operator-test') | ||
|
||
for PROJECT in ${PROJECT_AND_TIME}; do | ||
IFS='|' read -r PRJ TIME <<<"$PROJECT" # seperate the Namespace and time of creation using IFS(Input Field Seperators) value `|` | ||
echo "INFO: Project="${PRJ}, "Date=" ${TIME} | ||
|
||
dtSec=$(date --date "${TIME}" +'%s') # convert time in sec for namespace age | ||
taSec=$(date --date "1 days ago" +'%s') # convert time allowed for the namespace to be in the cluster | ||
|
||
if [ $dtSec -lt $taSec ]; then | ||
echo too old project : ${TIME} | ||
# delete namespace | ||
oc delete project ${PRJ} | ||
echo --------- | ||
fi | ||
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.