get() function is able to retrieve any resource from the kubernetes cluster either cached or directly.
get() takes parameters in the form of
get(Kind, apiVersion, Name, GetOptions?).
If the resource cannot be found
undefined is returned.
If you call
list() within a policy, jsPolicy will by default try to get the resources from its internal cache to save time and ease pressure on the api server.
You do not need to configure in jsPolicy which resources are cached by jsPolicy as it will figure this out automatically by tracking which resources are called in get() and list().
If resources are not needed anymore in the cache (after no
list() has been called for a specific time), jsPolicy will delete its internal cache for that resource automatically.
You can explicitly tell jsPolicy to make a direct call to the api server instead of retrieving the resources from the cache via the get or list options.
jsPolicy also supports 'smart' caching for
get(), where it tries to find a resource in the cache first and if not found will try to retrieve it from the api server.
This example shows how you can use the
get() function in a JsPolicy.