Skip to content

Commit

Permalink
Map only identifier and blueprint in get entities for delete stale en…
Browse files Browse the repository at this point in the history
…tities
  • Loading branch information
talsabagport committed Jun 6, 2023
1 parent ad3a14c commit ff402b4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/k8s/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (c *Controller) syncHandler(item EventItem) error {
}

func (c *Controller) objectHandler(obj interface{}, item EventItem) error {
portEntities, err := c.getObjectEntities(obj)
portEntities, err := c.getObjectEntities(obj, c.resource.Port.Entity.Mappings)
if err != nil {
utilruntime.HandleError(fmt.Errorf("error getting entities for object key '%s': %v", item.Key, err))
return nil
Expand All @@ -198,7 +198,7 @@ func (c *Controller) objectHandler(obj interface{}, item EventItem) error {
return nil
}

func (c *Controller) getObjectEntities(obj interface{}) ([]port.Entity, error) {
func (c *Controller) getObjectEntities(obj interface{}, mappings []port.EntityMapping) ([]port.Entity, error) {
unstructuredObj, ok := obj.(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("error casting to unstructured")
Expand All @@ -220,8 +220,8 @@ func (c *Controller) getObjectEntities(obj interface{}) ([]port.Entity, error) {
return nil, nil
}

entities := make([]port.Entity, 0, len(c.resource.Port.Entity.Mappings))
for _, entityMapping := range c.resource.Port.Entity.Mappings {
entities := make([]port.Entity, 0, len(mappings))
for _, entityMapping := range mappings {
var portEntity *port.Entity
portEntity, err = mapping.NewEntity(structuredObj, entityMapping)
if err != nil {
Expand Down Expand Up @@ -258,8 +258,15 @@ func (c *Controller) GetEntitiesSet() (map[string]interface{}, error) {
if err != nil {
return nil, fmt.Errorf("error listing K8s objects of resource '%s': %v", c.resource.Kind, err)
}
mappings := make([]port.EntityMapping, 0, len(c.resource.Port.Entity.Mappings))
for _, m := range c.resource.Port.Entity.Mappings {
mappings = append(mappings, port.EntityMapping{
Identifier: m.Identifier,
Blueprint: m.Blueprint,
})
}
for _, obj := range objects {
entities, err := c.getObjectEntities(obj)
entities, err := c.getObjectEntities(obj, mappings)
if err != nil {
return nil, fmt.Errorf("error getting entities of object: %v", err)
}
Expand Down

0 comments on commit ff402b4

Please sign in to comment.