'Cloud Run remove revision tag through CLI

Is there a way to remove a tag(through CLI) that I've set on a cloud run revision when doing a deployment? I can see how to do it through the UI, but I need to include this in my deployment pipeline so it should be through the CLI Delete tag through UI

My use case is the following:

  • deploy a new version of my service with --no-traffic flag and --tag option in order to make the version accessible
  • run test suite on the newly deployed version
  • update traffic to point to the new version
  • remove the tag from the old/new version

The reason I want to remove those is that all versions that contain tag are kept accessible which is a problem for me since I'm also using the min-instances option.

Edit: I was using incorrectly labels instead of tags here.



Solution 1:[1]

The --remove-tags can be used with the update-traffic command. Since every tag can be assigned only to a single run revision this is the correct way to remove a tag from a revision.

** Always using the same tag for deployment preview/testing also works in the above use case since using the same tag on the latest revision effectively removes this tag from older revisions.

Solution 2:[2]

This command below:

gcloud run services update-traffic <service>

With this flag below can remove one or more tags from one or more revisions:

--remove-tags <tag>,…

Now, there are two revisions "editor-v2-0-0" with three tags "green", "orange" and "yellow" and "editor-v1-0-0" with three tags "blue", "black" and "white":

enter image description here

Then, I run the command as shown below to remove one tag "orange" from the revision "editor-v2-0-0":

gcloud run services update-traffic editor --remove-tags orange

Now, one tag "orange" is removed from the revision "editor-v2-0-0" as shown below:

enter image description here

Next, I run the command as shown below to remove one tag "green" from the revision "editor-v2-0-0" and two tags "blue" and "white" from the revision "editor-v1-0-0":

gcloud run services update-traffic editor \
  --remove-tags green,blue,white

Now, one tag "green" is removed from the revision "editor-v2-0-0" and two tags "blue" and "white" are removed from the revision "editor-v1-0-0" as shown below:

enter image description here

*Be careful, if there are one or more empty strings before or after a comma in a list of values, there is an error:

So, if an empty string is before a comma:

gcloud run services update-traffic editor \
  --remove-tags green ,blue,white
                  // An empty string before a comma

Then, there is an error:

ERROR: (gcloud.run.services.update-traffic) unrecognized arguments: ,blue,white

And if an empty string is after a comma:

gcloud run services update-traffic editor \
  --remove-tags green, blue,white??????????????                 
                   // An empty string after a comma

Then, there is an error:

ERROR: (gcloud.run.services.update-traffic) unrecognized arguments: blue,white

So, don't put one or more empty strings before or after a comma in a list of values:

gcloud run services update-traffic editor \
  --remove-tags green,blue,white
                  // No empty strings 
                  // before or after a comma

Next, this command below:

gcloud run services update-traffic <service>

With this flag below can remove all tags from all revisions:

--clear-tags

Now again, there are two revisions "editor-v2-0-0" with three tags "green", "orange" and "yellow" and "editor-v1-0-0" with three tags "blue", "black" and "white":

enter image description here

Then, including the flag above, I run the full command as shown below to remove all the tags from all the revisions:

gcloud run services update-traffic editor --clear-tags

Now, all the tags are removed from all the revisions as shown below:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 scdekov
Solution 2 Kai - Kazuya Ito