0

I ran this code to check and delete the imagestreams in Openshift

 openshift.withCluster("${CLUSTER_NAME}") {
                        openshift.withProject("${DEV_ENV}") {
                            if (openshift.selector('imagestreams', '${imagestream_name}').exists()) {
                                openshift.selector('imagestreams', '${imagestream_name}').delete()

then I ran this

openshift.withCluster("${CLUSTER_NAME}") {
                        openshift.withProject("${DEV_ENV}") {
                            openshift.apply(openshift.raw("create -f '${imagestream_name}'.yaml"))

to create new imagestream from local yaml file but it end up with this error

ERROR: raw command [create -f 'imagestream-test'.yaml] returned an error;
{err=Error from server (AlreadyExists): error when creating "imagestream-test.yaml": imagestreams.image.openshift.io "testimagestream" already exists

Is there anyway to check if the imagestream is already in openshift ?

Winston
  • 1
  • 1

1 Answers1

0

How about using apply instead of create? oc apply will create a resource if it doesn't exist or update if it does.

openshift.withCluster("${CLUSTER_NAME}") {
                        openshift.withProject("${DEV_ENV}") {
                            openshift.apply(openshift.raw("apply -f '${imagestream_name}'.yaml"))
ycr
  • 12,828
  • 2
  • 25
  • 45