6

I know oc tag -d python:3.5 will remove only 3.5 tag.However I would like to remove multiple old tags from the same Image Stream using oc command.

For instance image streams phython:rel-1, phython:rel-2, phython:rel-3. I am trying like oc tag -d python:rel-*. But I end up with below error message.

*Error from server (NotFound): imagestreamtags.image.openshift.io "rel-*" not found*

I am wondering is there any way to apply wildcards for tags to remove multiple old tags in one go?

Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55
srk
  • 3,606
  • 2
  • 18
  • 23

1 Answers1

10

Not fully tested, and you can't do it in one command invocation, but you can use a shell script something like:

#!/bin/bash

TAGS=`oc get is python --template='{{range .spec.tags}}{{" "}}{{.name}}{{end}}{{"\n"}}'`

for tag in $TAGS; do
    if [[ "$tag" = rel-* ]]; then
        oc tag python:$tag -d
    fi
done
Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • Thank You for the response. I have no idea about "--template='{{range .spec.tags}}{{" "}}{{.name}}{{end}}{{"\n"}}". Could you please paste some links here to get in depth knowledge about "--template='{{range .spec.tags}}{{" "}}{{.name}}{{end}}{{"\n"}}"? – srk Apr 17 '18 at 18:34
  • It is a Golang Template. Perhaps have a look through https://golang.org/pkg/text/template/ to try and understand the format. – Graham Dumpleton Apr 18 '18 at 04:44