Resource Selector
Part of the command definition is describing the namespace (and cluster, where there is more than one cluster) where the command is executed. The resource you select in the namespace depends on the function of the command.
For example:
- If you execute a command on a pod, the command must define how to select that pod.
- If you are going to create a new job, the command definition must specify the namespace where the job is created.
Resource selection criteria comes from the namespace and cluster where the command was discovered. See the discussion about command discovery for more information. This by itself can be enough to select the execution namespace.
Resource Selector Configuration Properties describes the properties available for configuring resource selection.
Property | Description |
---|---|
apiVersion | The Kubernetes API version for the kind of resource to select. |
kind | The kind of resource to select. |
name | The name of the resource to select. |
labels | A map of labels a selected resource must have. |
strategy | The strategy to use if more than one matching resource is found. Can be any or all . The default value is
any . |
The following excerpt shows selection criteria specifying a pod with a given name:
resourceSelector:
kind: pods
name: my-pod
The following excerpt shows selection criteria specifying all services with specified labels:
resourceSelector:
kind: services
labels:
app: app-one
The following excerpt shows selection of the current namespace:
resourceSelector: {}
When a resource selector resolves to more than one resource, only one resource is selected for execution by default. Set resourceSelector.strategy
to
all
for execution to occur on all selected resources. If no resources are selected, the command is not executed. For more information, see the discussion about
duplicate command behavior.
The resource that you select is sometimes dependent on argument and flag values. You can use parameter replacement placeholders in your command definition to resolve at execution time.
These placeholders use the ${name}
format.
Parameter Replacement Placeholders describes the placeholders that can be used.
Name | Description |
---|---|
command.flag.name | Where name is the name of the flag. |
command.argument.name | Where name is the name of the argument. |
The following excerpt shows a resource selector added to the hypothetical export command:
command:
name: export
description: Export some data
flags:
- name: engine
shortName: e
type: int
mandatory: false
defaultValue: 1
description: The Engine id
- name: subdomain
shortName: s
type: int
mandatory: false
defaultValue: 1
description: The Subscriber Domain id
resourceSelector:
kind: services
labels:
engineId: ${command.flag.engine}
subDomainId: ${command.flag.subdomain}