Skip to content

Commit

Permalink
add yaml tag to our structs definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
itamar-smirra-port committed Apr 25, 2024
1 parent 9135417 commit d98bc12
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 148 deletions.
34 changes: 21 additions & 13 deletions pkg/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,35 +244,43 @@ func (c *Controller) getObjectEntities(obj interface{}, selector port.Selector,
}

entities := make([]port.Entity, 0, len(mappings))
objectsToMap := make([]map[string]interface{}, 0)
editedObject, ok := structuredObj.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("error parsing object '%#v'", structuredObj)
}

if itemsToParse != "" {
editedObject, ok := structuredObj.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("error parsing object '%#v'", structuredObj)
}

items, parseItemsError := jq.ParseArray(itemsToParse, structuredObj)
if parseItemsError != nil {
return nil, parseItemsError
}

for _, item := range items {
editedObject["item"] = item
objectsToMap = append(objectsToMap, editedObject)
selectorResult, err := isPassSelector(editedObject, selector)

if err != nil {
return nil, err
}

if selectorResult {
currentEntities, err := mapEntities(editedObject, mappings)
if err != nil {
return nil, err
}

entities = append(entities, currentEntities...)
}
}
} else {
objectsToMap = append(objectsToMap, editedObject)
}

for _, objectToMap := range objectsToMap {
selectorResult, err := isPassSelector(objectToMap, selector)
selectorResult, err := isPassSelector(structuredObj, selector)

if err != nil {
return nil, err
}

if selectorResult {
currentEntities, err := mapEntities(objectToMap, mappings)
currentEntities, err := mapEntities(structuredObj, mappings)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit d98bc12

Please sign in to comment.