Skip to content

feat: adding device sync to Nautobot Operator#2098

Open
abhimanyu003 wants to merge 1 commit into
mainfrom
nautobotOpDeviceSync
Open

feat: adding device sync to Nautobot Operator#2098
abhimanyu003 wants to merge 1 commit into
mainfrom
nautobotOpDeviceSync

Conversation

@abhimanyu003

Copy link
Copy Markdown
Contributor

Add device sync support to the Nautobot operator with full CRUD lifecycle (create/update/delete) following the same patterns as device types.

Sample ConfigMap/YAML files.

---
id: "c3d4e5f6-a7b8-9012-cdef-123456789012"
name: "firewall-01"
device_type: "ASA5525-X"
role: "Infrastructure"
serial: "JMX2145L0XY"
asset_tag: "AST-FW-001"
status: "Active"
location: "dfw1"
rack: "dfw1-b01"
position: 38
face: "front"
comments: "Primary firewall for dfw1"

Sample Config Map

apiVersion: v1
kind: ConfigMap
metadata:
  name: nautobot-devices
  namespace: nautobot
data:
  device-switch-01.yaml: |
    ---
    id: "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
    name: "switch-01"
    device_type: "Nexus 9336C-FX2"
    role: "Infrastructure"
    serial: "FCW2345L0AB"
    asset_tag: "AST-SW-001"
    status: "Active"
    location: "iad3"
    rack: "iad3-a01"
    position: 40
    face: "front"
    comments: "Top of rack switch in iad3"
  device-switch-02.yaml: |
    ---
    id: "b2c3d4e5-f6a7-8901-bcde-f12345678901"
    name: "switch-02"
    device_type: "Nexus 9336C-FX2"
    role: "Infrastructure"
    serial: "FCW2345L0AC"
    asset_tag: "AST-SW-002"
    status: "Active"
    location: "iad3"
    rack: "iad3-a02"
    position: 40
    face: "front"
    comments: "Top of rack switch in iad3"
  device-firewall-01.yaml: |
    ---
    id: "c3d4e5f6-a7b8-9012-cdef-123456789012"
    name: "firewall-01"
    device_type: "ASA5525-X"
    role: "Infrastructure"
    serial: "JMX2145L0XY"
    asset_tag: "AST-FW-001"
    status: "Active"
    location: "dfw1"
    rack: "dfw1-b01"
    position: 38
    face: "front"
    comments: "Primary firewall for dfw1"

{name: "vlan", configRefs: nautobotCR.Spec.VlanRef, syncFunc: r.syncVlan},
// depends on: namespace, rir, location, vlanGroup, vlan, tenant, tenantGroup, role
{name: "prefix", configRefs: nautobotCR.Spec.PrefixRef, syncFunc: r.syncPrefix},
{name: "device", configRefs: nautobotCR.Spec.DeviceRef, syncFunc: r.syncDevice},

@nidzrai nidzrai Jun 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

device sync is currently at the end of the sync order but cluster sync runs earlier on line 99 and tries to assign devices during cluster sync. Since clusters depend on devices already existing, should device sync run before cluster sync? Otherwise new devices may not exist yet when cluster assignment happens.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a problem later on. the current order relies on programmers to manually remember the order of dependency when adding new resources. I don't think that should be the case. We should use a DAG(Directed Acyclic Graphs) here and do a topological sort instead. This would guarantee correct processing order instead of relying on the order in the list. For example, if devices need to be processed before cluster sync, the DAG would enforce that automatically — rather than depending on someone remembering to place device above cluster.

type: array
deviceRef:
items:
description: ConfigMapRef defines a reference to a specific ConfigMap

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we improve the description here? It sounds slightly unintuitive. I can't make sens eof this sentence, 'ie' reference to a specific ConfigMap' of what?

description: ConfigMapRef defines a reference to a specific ConfigMap
properties:
configMapSelector:
description: The name of the ConfigMap resource being referred

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says this selector "is" a name, but then on line 132 we have a separate key field — so it's unclear what the outer description is even referring to. This still looks confusing to me.

description: ConfigMapRef defines a reference to a specific ConfigMap
properties:
configMapSelector:
description: The name of the ConfigMap resource being referred

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same confusion as I described in /config/crd/bases/sync.rax.io_nautobots.yaml

{name: "vlan", configRefs: nautobotCR.Spec.VlanRef, syncFunc: r.syncVlan},
// depends on: namespace, rir, location, vlanGroup, vlan, tenant, tenantGroup, role
{name: "prefix", configRefs: nautobotCR.Spec.PrefixRef, syncFunc: r.syncPrefix},
{name: "device", configRefs: nautobotCR.Spec.DeviceRef, syncFunc: r.syncDevice},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a problem later on. the current order relies on programmers to manually remember the order of dependency when adding new resources. I don't think that should be the case. We should use a DAG(Directed Acyclic Graphs) here and do a topological sort instead. This would guarantee correct processing order instead of relying on the order in the list. For example, if devices need to be processed before cluster sync, the DAG would enforce that automatically — rather than depending on someone remembering to place device above cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants