Skip to content

Commit

Permalink
fix: duty changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Feb 5, 2024
1 parent dbd60f5 commit 74f4241
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ else
GOBIN=$(shell go env GOBIN)
endif

.PHONY: tidy
tidy:
go mod tidy
git add go.mod go.sum
cd hack/generate-schemas && go mod tidy && git add go.mod go.sum

docker:
docker build . -f build/Dockerfile -t ${IMG}

Expand Down
2 changes: 1 addition & 1 deletion api/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

type ScrapeContext interface {
duty.DBContext
context.Context
DutyContext() dutyCtx.Context

IsTrace() bool
Expand Down
13 changes: 4 additions & 9 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (
"github.com/flanksource/commons/utils"
v1 "github.com/flanksource/config-db/api/v1"
"github.com/flanksource/config-db/db/models"
"github.com/flanksource/duty"
"github.com/flanksource/duty/context"
dutyModels "github.com/flanksource/duty/models"
"github.com/flanksource/duty/query"
"github.com/flanksource/duty/types"
"github.com/google/uuid"
"github.com/lib/pq"
"github.com/ohler55/ojg/oj"
"github.com/patrickmn/go-cache"
"github.com/samber/lo"
"gorm.io/gorm/clause"
)

Expand Down Expand Up @@ -102,12 +101,12 @@ func UpdateConfigItem(ci *models.ConfigItem) error {
return nil
}

func FindConfigsByRelationshipSelector(ctx context.Context, selector v1.RelationshipSelector) ([]dutyModels.ConfigItem, error) {
func FindConfigIDsByRelationshipSelector(ctx context.Context, selector v1.RelationshipSelector) ([]uuid.UUID, error) {
if selector.IsEmpty() {
return nil, nil
}

return duty.FindConfigs(ctx, []types.ResourceSelector{selector.ToResourceSelector()}, duty.PickColumns("id"))
return query.FindConfigIDsByResourceSelector(ctx, selector.ToResourceSelector())
}

// FindConfigIDsByNamespaceNameClass returns the uuid of config items which matches the given type, name & namespace
Expand All @@ -117,12 +116,8 @@ func FindConfigIDsByNamespaceNameClass(ctx context.Context, namespace, name, con
Namespace: namespace,
FieldSelector: fmt.Sprintf("config_class=%s", configClass),
}
items, err := duty.FindConfigs(ctx, []types.ResourceSelector{rs}, duty.PickColumns("id"))
if err != nil {
return nil, err
}

return lo.Map(items, func(c dutyModels.ConfigItem, _ int) uuid.UUID { return c.ID }), nil
return query.FindConfigIDsByResourceSelector(ctx, rs)
}

// QueryConfigItems ...
Expand Down
6 changes: 3 additions & 3 deletions scrapers/processors/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ func getRelationshipsFromRelationshipConfigs(ctx context.Context, input v1.Scrap
}

for _, selector := range relationshipSelectors {
linkedConfigItems, err := db.FindConfigsByRelationshipSelector(ctx, selector)
linkedConfigIDs, err := db.FindConfigIDsByRelationshipSelector(ctx, selector)
if err != nil {
return nil, fmt.Errorf("failed to find config items by relationship selector: %w", err)
}

for _, itemToLink := range linkedConfigItems {
for _, id := range linkedConfigIDs {
rel := v1.RelationshipResult{
ConfigExternalID: v1.ExternalID{ExternalID: []string{input.ID}, ConfigType: input.Type},
RelatedConfigID: itemToLink.ID.String(),
RelatedConfigID: id.String(),
}

relationships = append(relationships, rel)
Expand Down
5 changes: 3 additions & 2 deletions scrapers/runscrapers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/flanksource/duty"
"github.com/flanksource/duty/context"
dutymodels "github.com/flanksource/duty/models"
"github.com/flanksource/duty/query"
"github.com/flanksource/duty/types"
"github.com/google/uuid"
. "github.com/onsi/ginkgo/v2"
Expand All @@ -41,7 +42,7 @@ var _ = Describe("Scrapers test", Ordered, func() {
})
})

Describe("Test kubernetes relationship", func() {
Describe("Test kubernetes relationship", Focus, func() {
var scrapeConfig v1.ScrapeConfig

It("should prepare scrape config", func() {
Expand Down Expand Up @@ -117,7 +118,7 @@ var _ = Describe("Scrapers test", Ordered, func() {
})

It("should correctly setup kubernetes relationship", func() {
duty.CleanCache()
query.FlushGettersCache()

scraperCtx := api.NewScrapeContext(gocontext.TODO(), gormDB, nil).WithScrapeConfig(&scrapeConfig)
_, err := RunScraper(scraperCtx)
Expand Down

0 comments on commit 74f4241

Please sign in to comment.