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 97c133e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 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
10 changes: 5 additions & 5 deletions jobs/sync_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
eventQueueUpdateChannel = "event_queue_updates"
)

var SyncConfigChanges = job.Job{
var SyncConfigChanges = &job.Job{
Name: "SyncConfigChanges",
JobHistory: true,
Singleton: true,
Expand All @@ -43,7 +43,7 @@ var SyncConfigChanges = job.Job{
},
}

var SyncConfigAnalyses = job.Job{
var SyncConfigAnalyses = &job.Job{
Name: "SyncConfigAnalyses",
JobHistory: true,
Singleton: true,
Expand All @@ -59,7 +59,7 @@ var SyncConfigAnalyses = job.Job{
},
}

var ReconcileConfigScrapersAndItems = job.Job{
var ReconcileConfigScrapersAndItems = &job.Job{
Name: "ReconcileConfigScrapersAndItems",
JobHistory: true,
Singleton: true,
Expand Down Expand Up @@ -87,7 +87,7 @@ var ReconcileConfigScrapersAndItems = job.Job{
},
}

var PullUpstreamConfigScrapers = job.Job{
var PullUpstreamConfigScrapers = &job.Job{
Name: "PullUpstreamConfigScrapers",
JobHistory: true,
Singleton: true,
Expand All @@ -102,7 +102,7 @@ var PullUpstreamConfigScrapers = job.Job{
},
}

var UpstreamJobs = []job.Job{
var UpstreamJobs = []*job.Job{
SyncConfigChanges,
SyncConfigAnalyses,
PullUpstreamConfigScrapers,
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
3 changes: 2 additions & 1 deletion 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 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 97c133e

Please sign in to comment.