Skip to content

feat(nautobotOP): Use UUID for Nautobot Operator Sync#1994

Open
abhimanyu003 wants to merge 2 commits intomainfrom
nautobotOpIDUpdate
Open

feat(nautobotOP): Use UUID for Nautobot Operator Sync#1994
abhimanyu003 wants to merge 2 commits intomainfrom
nautobotOpIDUpdate

Conversation

@abhimanyu003
Copy link
Copy Markdown
Contributor

This PR focuses on Nautobot Operator Sync.

  • During sync, the operator will create objects using the unique ID provided in the YAML file.
  • This helps support renaming objects in Nautobot.
    • If the unique ID already exists, the operator will rename or update the object in Nautobot.
    • If the unique ID does not exist, the operator will create a new object with the given UUID.
  • Delete behavior remains unchanged the operator will continue to check whether the object was created by the operator user. If it was not, the delete operation will be skipped.
flowchart TD
    A[Start sync] --> B[Read object from YAML]
    B --> C[Get unique ID from YAML]
    C --> D{Does unique ID exist in Nautobot?}

    D -- Yes --> E[Rename or update existing object]
    D -- No --> F[Create new object with given UUID]

    E --> G[Sync complete]
    F --> G

    H[Delete requested] --> I{Was object created by operator user?}
    I -- Yes --> J[Delete object from Nautobot]
    I -- No --> K[Skip delete]

    J --> L[Delete complete]
    K --> L
Loading

s.client.AddReport("UpdateLocation", "failed to check ownership", "id", id, "error", err.Error())
return nil, err
}
if !owned {
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.

if !owned , this check is gone from Update but still exists in destroy . without this guard one can accidentally puts a UUID of a human-created or externally-managed Nautobot object in their YAML. the operator will overwrite it without any warnin I see .

return []nb.ConsolePortTemplate{}, resp, nil
}
return list.Results, resp, nil
list, resp, err := s.client.APIClient.DcimAPI.DcimConsolePortTemplatesList(ctx).Limit(10000).Depth(2).DeviceType([]string{deviceTypeID}).Execute()
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.

It's a hardcoded ceiling

}

type DeviceType struct {
ID string `yaml:"id"`
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.

if we ever Marshals it to JSON , the ID field would serialized as "ID" instead of "id" . I saw in cluster.go this pattern ID string json:"id" yaml:"id"

if list == nil || len(list.Results) == 0 {
return []nb.Manufacturer{}
}
if list.Results[0].Id == nil {
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.

In ListAll, if Results[0].Id == nil, the entire result set is discarded and an empty slice is returned. I m not sure if it is intentional . but let's say there are 10 items , it would check just 1st or the 0th position and would discard all . right ?

return nb.Location{}
}

return list.Results[0]
Copy link
Copy Markdown
Contributor

@nidzrai nidzrai May 6, 2026

Choose a reason for hiding this comment

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

so here if found in cache, no API call needed otherwise and it call API. bt where would it update cache ? how does it write ?

if id == "" {
return nil
}
return nb.PtrString(id)
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.

what if I put in valid format but belongs to another object. and since there is not owner check . I think it would overwrite .

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.

2 participants