[SCRIPT] How to delete images from openshift registry

June 15, 2022

 

#!/bin/bash

read -p "Enter project/namespace: " PROJECT

oc project $PROJECT

oc get imagestreams | awk NR\>1 | awk '{ print $1}' > streams.tmp

 

for IMGSTREAM in `cat streams.tmp`;

do

 

 

oc get imagestream $IMGSTREAM -o jsonpath='{range .status.tags[*]}{.tag} {range .items[*]}{.image} {.created}{"\n"}{end}' | sed 's/@/ /'| sort -k3,3 > images.tmp

LINES=`cat images.tmp|wc -l`

if [ $LINES -ge 3 ]; then head -n -3 images.tmp> images.tmp2 && mv images.tmp2 images.tmp;

for i in `cat images.tmp|awk '{ print $2}'`; do oc delete image $i ; done

for i in `cat images.tmp|awk '{ print $1}'`; do oc tag -d $IMGSTREAM:$i ; done

fi

 

done

 

rm images.tmp

rm streams.tmp

No comments:

Powered by Blogger.