feat(nautobotOP): Use UUID for Nautobot Operator Sync#1994
feat(nautobotOP): Use UUID for Nautobot Operator Sync#1994abhimanyu003 wants to merge 6 commits into
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 .
| } | ||
|
|
||
| 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"
There was a problem hiding this comment.
I didn't get what you are saying here ?
| 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 ?
There was a problem hiding this comment.
This is just a safe guard to prevent app from panic and check if we recieved the data.
| 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 ?
There was a problem hiding this comment.
Can update will auto happen next time when reconcile happens, there cache is ony for one time use.
Sure we can look into it more, but in future update
| 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 .
There was a problem hiding this comment.
Not sure, why we want to owner check here ?
This function is a helper function that will create pointer of string
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