16min

Network Policy

Note: if you are running CloudGraph locally you can view the interactive, automatically generated documentation in either GraphQL Playground or Altair by clicking the docs button on the right-hand side of the screen. After reading the below information we highly suggest you use one of these tools to test your queries as they will autocomplete fields for you and let you know if your queries are valid before you even submit them.

Overview

You can currently query the following attributes and connections on a k8s Network Policy:

GraphQL
|

Filtering

Get data for a single network policy that you know the id for:

GraphQL
|

Get data for all of the network policies in a certain k8s Context:

GraphQL
|

Get data for all of the network policies NOT in a certain k8s Context:

GraphQL
|



Advanced Filtering

Get data for all of the network policies that have a namespace:

GraphQL
|

Use multiple filter selectors, (i.e. has, and, not, or) to get data for all of the network policies that have a namespace AND kind OR that do not have a spec. Note that you can use has, and, not, or completely independently of each other:

GraphQL
|

You may also filter using a regex when filtering on a string field like, context if you want to look for a value that matches say, some-value (case insensitive):

GraphQL
|

Ordering

You can order the results you get back either asc or desc depending on your preference:

GraphQL
|

Only select and return the first two network policies that are found:

GraphQL
|

Only select and return the first two network policies that are found, but offset by one so network policies two & three are returned:

GraphQL
|

Aggregation

Count the number of network policies across all scanned K8s contexts:

GraphQL
|

Count the number of network policies in a single context. Note that you can apply all of the same filters that are listed above to aggregate queries:

GraphQL
|

Kitchen Sink

Putting it all together; get all data for all network policies across all k8s contexts in a single query. For the purposes of this example we will only get direct children of the network policy but if you want to it's easy to go from say, networkPolicy -> namespace -> job ...etc:

GraphQL
|

References



Updated 01 Feb 2022
Did this page help?
Yes
No