Skip to content

Commit bbaf1e2

Browse files
yashmehrotramoshloop
authored andcommitted
chore: inject component data in selectors
1 parent 1804f1f commit bbaf1e2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/topology/component_relationship.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ import (
88
"github.com/flanksource/duty/job"
99
"github.com/flanksource/duty/models"
1010
"github.com/flanksource/duty/query"
11+
"github.com/flanksource/duty/types"
1112
"github.com/google/uuid"
1213
"github.com/pkg/errors"
1314
"github.com/samber/lo"
1415
"gorm.io/gorm/clause"
1516
)
1617

18+
func injectComponentDataInSelectors(comp models.Component) types.ResourceSelectors {
19+
for i, rs := range comp.Selectors {
20+
if rs.Functions.ComponentConfigTraversal != nil {
21+
comp.Selectors[i].Functions.ComponentConfigTraversal.ComponentID = comp.ID.String()
22+
}
23+
}
24+
return comp.Selectors
25+
}
26+
1727
var ComponentRelationshipSync = &job.Job{
1828
Name: "ComponentRelationshipSync",
1929
Schedule: "@every 5m",
@@ -30,7 +40,8 @@ var ComponentRelationshipSync = &job.Job{
3040

3141
for _, component := range components {
3242
hash := component.Selectors.Hash()
33-
comps, err := query.FindComponents(ctx.Context, -1, component.Selectors...)
43+
selectors := injectComponentDataInSelectors(component)
44+
comps, err := query.FindComponents(ctx.Context, -1, selectors...)
3445
if err != nil {
3546
ctx.History.AddError(fmt.Sprintf("error getting components with selectors: %v. err: %v", component.Selectors, err))
3647
continue

0 commit comments

Comments
 (0)