feat(nautobotOP): Use UUID for Nautobot Operator Sync#1994
feat(nautobotOP): Use UUID for Nautobot Operator Sync#1994abhimanyu003 wants to merge 2 commits intomainfrom
Conversation
| s.client.AddReport("UpdateLocation", "failed to check ownership", "id", id, "error", err.Error()) | ||
| return nil, err | ||
| } | ||
| if !owned { |
There was a problem hiding this comment.
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() |
| } | ||
|
|
||
| type DeviceType struct { | ||
| ID string `yaml:"id"` |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
what if I put in valid format but belongs to another object. and since there is not owner check . I think it would overwrite .
This PR focuses on Nautobot Operator Sync.
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