0

If you have 20 GKE clusters, gcloud container operations list returns too much data.

Google Cloud's official docs lack good examples of how to do filtering:

  • Their docs just mention --filter=[EXPRESSION], which isn't helpful at all without syntax of what the expressions should look like...
  • gcloud container operations list --help just mentions see gcloud topic filters for more info, which tries to explain, but it's difficult to understand without examples.

So the question is what should filtering look like?

1 Answer 1

1
export PROJECT=name-of-your-project export CLUSTER=name-of-your-cluster gcloud container operations list \ --filter="(targetLink ~ $CLUSTER) AND (2024-01-04)" \ --sort-by=START_TIME --format=yaml --project=$PROJECT gcloud container operations list \ --filter="(targetLink ~ $CLUSTER) AND (startTime > 2024-01-04) AND (startTime < 2024-01-08)" \ --sort-by=START_TIME --format=yaml --project=$PROJECT gcloud container operations list \ --filter="(targetLink ~ $CLUSTER) AND (startTime > 2024-01-08T06:18:55.104-08:00) AND (startTime < 2024-01-08T15:18:55.104-08:00)" \ --sort-by=START_TIME --format=yaml --project=$PROJECT 

Explanation of Syntax:

  • --format=yaml ends up improving verbosity (hidden feature), and tells you the accurate name of keys you can filter by.
    (that's how I identified targetLink and startTime as a valid keys)
  • --sort-by=START_TIME is just handy
  • --filter needs the "double quotes"
  • "(true boolean expression) AND (true) AND (true)"
  • --filter="targetLink ~ $CLUSTER"
    The ~ acts as a string in value of key
    so string "$CLUSTER" is contained within the long string value of key named targetLink
    If you have 20 clusters this lets you filter the results to a single cluster :)
  • --filter="2024-01-04"
    This checks for that string in the value of all keys
    Let's you check the operations that occurred on a particular day.
  • --filter="(startTime < 2024-01-06)"
    Is also valid and handy if you want to see entries before a particular date. Note the key always has to be on the left, startTime can't be on the right side of the inequality.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.