TargetSource
The TargetSource resource enables dynamic discovery of network devices from external sources. The operator automatically creates, updates, and deletes Target resources based on discovered devices.
Basic Configuration
apiVersion: operator.gnmic.dev/v1alpha1
kind: TargetSource
metadata:
name: targetsource-1
spec:
provider:
# see Discovery Providers section
targetProfile: default
targetLabels:
source: inventory
Spec Fields
| Field | Type | Required | Description |
|---|---|---|---|
provider | object | Yes | Provider-specific discovery configuration. Exactly one provider must be configured |
targetProfile | string | Yes | Reference to TargetProfile applied to all targets |
targetLabels | map[string]string | No | Labels added to all discovered targets |
Discovery Providers
TargetSource supports the following discovery providers:
| Provider | Description |
|---|---|
http | Discover targets from an HTTP JSON endpoint |
HTTP Provider
The HTTP provider discovers targets from an HTTP endpoint returning a JSON array of target definitions.
spec:
provider:
http:
url: http://inventory-service:8080/targets
HTTP Spec Fields
| Field | Type | Required | Description |
|---|---|---|---|
url | string | Yes | URL pointing to the inventory server |
Response Format
The endpoint must return a JSON array of objects with the following structure:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the generated Target resource |
address | string | Yes | Device address in host:port format |
labels | map[string]string | No | Labels added to the generated Target resource |
Example response:
[
{
"name": "spine1",
"address": "spine1:57400",
"labels": {
"role": "spine"
}
},
{
"name": "leaf1",
"address": "leaf1:57400",
"labels": {
"role": "leaf"
}
},
{
"name": "leaf2",
"address": "leaf2:57400",
"labels": {
"role": "leaf"
}
}
]
Label Inheritance
Each generated Target receives an ownership label identifying the originating TargetSource:
operator.gnmic.dev/targetsource: targetsource-1
This label is automatically managed by the operator and is used to:
- Identify targets owned by a specific
TargetSource - Determine which targets should be updated or deleted during reconciliation
The operator.gnmic.dev/targetsource label is reserved and always takes precedence over any provider-supplied labels.
TargetSource Labels
Additional labels can be applied to all generated targets using spec.targetLabels:
apiVersion: operator.gnmic.dev/v1alpha1
kind: TargetSource
metadata:
name: targetsource-1
spec:
provider:
http:
url: http://targetsource-1:8080/targets
targetLabels:
datacenter: dc-a
environment: production
All targets discovered from this source will have:
datacenter: dc-aenvironment: production
This enables Pipelines to select targets using label selectors.
Labels from Discovery Providers
Discovery providers may return additional labels for each target. These labels are applied directly to the generated Target resource.
The gnmic_operator_ label prefix is reserved for operator-specific behavior. Labels using this prefix are interpreted by the operator and are not applied directly to the generated Target resource.
Supported operator labels:
| Label | Description |
|---|---|
gnmic_operator_target_profile | Overrides the TargetProfile configured in the TargetSource |
Label Precedence
If the same label key is defined in multiple places, labels are applied in the following order (highest precedence first):
TargetSourceownership label (operator.gnmic.dev/targetsource)- Labels from
TargetSource.spec.targetLabels - Labels returned by the discovery provider
Status
The TargetSource status shows discovery state:
status:
status: Synced
targetsCount: 42
lastSync: "2024-01-15T10:30:00Z"
| Field | Description |
|---|---|
status | Current sync status (Synced, Error, Pending) |
targetsCount | Number of targets discovered |
lastSync | Timestamp of last successful sync |
Lifecycle
Target Creation
When a TargetSource discovers a new device:
- A new
Targetresource is created - The
TargetProfilereferenced inspec.targetProfileis assigned - Labels from
spec.targetLabelsare applied - The
TargetSourceis set as the owner reference
Target Updates
On each discovery cycle, existing Target resources are reconciled with the latest discovered state:
- The corresponding
Targetresource is updated and overwritten - Clusters consuming the target are reconciled automatically
Manual changes to
Targetresources managed by aTargetSourceare overwritten on every reconciliation cycle.
Target Deletion
When a device is no longer returned by the discovery provider:
- The corresponding
Targetresource is deleted - Clusters automatically stop using the target
TargetSource Deletion
When a TargetSource is deleted:
- All
Targetresources owned by it are deleted via owner references - Clusters are reconciled and remove the deleted targets