TargetSource

Dynamic target discovery from external sources

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

FieldTypeRequiredDescription
providerobjectYesProvider-specific discovery configuration. Exactly one provider must be configured
targetProfilestringYesReference to TargetProfile applied to all targets
targetLabelsmap[string]stringNoLabels added to all discovered targets

Discovery Providers

TargetSource supports the following discovery providers:

ProviderDescription
httpDiscover 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

FieldTypeRequiredDescription
urlstringYesURL pointing to the inventory server

Response Format

The endpoint must return a JSON array of objects with the following structure:

FieldTypeRequiredDescription
namestringYesName of the generated Target resource
addressstringYesDevice address in host:port format
labelsmap[string]stringNoLabels 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-a
  • environment: 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:

LabelDescription
gnmic_operator_target_profileOverrides 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):

  1. TargetSource ownership label (operator.gnmic.dev/targetsource)
  2. Labels from TargetSource.spec.targetLabels
  3. Labels returned by the discovery provider

Status

The TargetSource status shows discovery state:

status:
  status: Synced
  targetsCount: 42
  lastSync: "2024-01-15T10:30:00Z"
FieldDescription
statusCurrent sync status (Synced, Error, Pending)
targetsCountNumber of targets discovered
lastSyncTimestamp of last successful sync

Lifecycle

Target Creation

When a TargetSource discovers a new device:

  1. A new Target resource is created
  2. The TargetProfile referenced in spec.targetProfile is assigned
  3. Labels from spec.targetLabels are applied
  4. The TargetSource is set as the owner reference

Target Updates

On each discovery cycle, existing Target resources are reconciled with the latest discovered state:

  1. The corresponding Target resource is updated and overwritten
  2. Clusters consuming the target are reconciled automatically

Manual changes to Target resources managed by a TargetSource are overwritten on every reconciliation cycle.

Target Deletion

When a device is no longer returned by the discovery provider:

  1. The corresponding Target resource is deleted
  2. Clusters automatically stop using the target

TargetSource Deletion

When a TargetSource is deleted:

  1. All Target resources owned by it are deleted via owner references
  2. Clusters are reconciled and remove the deleted targets