Skip to content

Commit

Permalink
Merge pull request #1151 from flanksource/agent-id-in-select
Browse files Browse the repository at this point in the history
fix: ignore agent canaries and topologies for sync
  • Loading branch information
moshloop authored Jul 13, 2023
2 parents 0c79e5e + 14eae18 commit f127d5a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions pkg/db/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"gorm.io/gorm/clause"
)

func GetAllCanaries() ([]pkg.Canary, error) {
func GetAllCanariesForSync() ([]pkg.Canary, error) {
var _canaries []pkg.Canary
var rawCanaries interface{}
query := `
Expand All @@ -36,7 +36,11 @@ func GetAllCanaries() ([]pkg.Canary, error) {
) :: jsonb
)
) :: jsonb AS canaries
FROM canaries WHERE deleted_at IS NULL`
FROM canaries
WHERE
deleted_at IS NULL AND
agent_id = '00000000-0000-0000-0000-000000000000'
`

rows, err := Gorm.Raw(query).Rows()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/db/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func GetTopology(ctx context.Context, id string) (*v1.Topology, error) {
return &tv1, nil
}

func GetAllTopologies() ([]v1.Topology, error) {
func GetAllTopologiesForSync() ([]v1.Topology, error) {
var v1topologies []v1.Topology
var topologies []pkg.Topology
if err := Gorm.Table("topologies").Find(&topologies).Where("deleted_at is NULL").Error; err != nil {
if err := Gorm.Table("topologies").Find(&topologies).Where("deleted_at is NULL AND namespace != 'push'").Error; err != nil {
return nil, err
}
for _, t := range topologies {
Expand Down
2 changes: 1 addition & 1 deletion pkg/jobs/canary/canary_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func SyncCanaryJobs() {
_ = db.PersistJobHistory(jobHistory)
defer func() { _ = db.PersistJobHistory(jobHistory.End()) }()

canaries, err := db.GetAllCanaries()
canaries, err := db.GetAllCanariesForSync()
if err != nil {
logger.Errorf("Failed to get canaries: %v", err)
jobHistory.AddError(err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/jobs/canary/canary_jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var _ = ginkgo.Describe("Test Sync Canary Job", ginkgo.Ordered, func() {
err = db.Gorm.Create(canaryM).Error
Expect(err).To(BeNil())

response, err := db.GetAllCanaries()
response, err := db.GetAllCanariesForSync()
Expect(err).To(BeNil())
Expect(len(response)).To(Equal(1))
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/jobs/system/system_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func SyncTopologyJobs() {
}
}

topologies, err := db.GetAllTopologies()
topologies, err := db.GetAllTopologiesForSync()
if err != nil {
logger.Errorf("Failed to get topology: %v", err)
return
Expand Down

0 comments on commit f127d5a

Please sign in to comment.