Skip to content

Commit

Permalink
fix: topology & canary controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe authored and moshloop committed May 1, 2024
1 parent 8bed8b9 commit 6b2f541
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/fergusstrange/embedded-postgres v1.25.0
github.com/flanksource/artifacts v1.0.4
github.com/flanksource/commons v1.22.1
github.com/flanksource/duty v1.0.433
github.com/flanksource/duty v1.0.435
github.com/flanksource/gomplate/v3 v3.24.7
github.com/flanksource/is-healthy v1.0.4
github.com/flanksource/kommons v0.31.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,8 @@ github.com/flanksource/artifacts v1.0.4 h1:KjQTwsvQ73uHqTK7o4Jwt/RW8fyxJOTJ6JLgz
github.com/flanksource/artifacts v1.0.4/go.mod h1:wkbdseaTkDo4Q6k6T86vXd4Uy47M6NPCmexgHvCTDl0=
github.com/flanksource/commons v1.22.1 h1:Ycg8r26bx537UTdAEFgngDW1r2j5bX6Lr3NGxLICpiw=
github.com/flanksource/commons v1.22.1/go.mod h1:GD5+yGvmYFPIW3WMNN+y1JkeDMJY74e05pQAsRbrvwY=
github.com/flanksource/duty v1.0.433 h1:Mhbt/yc3Cv8Af/YN697eMuDeWoZKZZ0QkuvNxzzMOTU=
github.com/flanksource/duty v1.0.433/go.mod h1:GNckeTl2cnxQepuHJAH0b8xEaLsAnx9kQZs+VIPDnXc=
github.com/flanksource/duty v1.0.435 h1:pUDj8wmWhcyLZtYiJmfEHh9V4lDwGXj+USz7Q3Bv0XE=
github.com/flanksource/duty v1.0.435/go.mod h1:GNckeTl2cnxQepuHJAH0b8xEaLsAnx9kQZs+VIPDnXc=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.7 h1:XVIwcOTIR9l95D+jaerHcqRFN2Mo6MNEMttxsEsZ9aY=
github.com/flanksource/gomplate/v3 v3.24.7/go.mod h1:7SJHGdFITvw3I8qf/ppF1BXbL2/ENyI5vpQkWt8MHtU=
Expand Down
2 changes: 1 addition & 1 deletion hack/generate-schemas/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/exaring/otelpgx v0.5.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/flanksource/duty v1.0.433 // indirect
github.com/flanksource/duty v1.0.435 // indirect
github.com/flanksource/is-healthy v1.0.4 // indirect
github.com/flanksource/kommons v0.31.4 // indirect
github.com/flanksource/kubectl-neat v1.0.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions hack/generate-schemas/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/flanksource/commons v1.22.1 h1:Ycg8r26bx537UTdAEFgngDW1r2j5bX6Lr3NGxLICpiw=
github.com/flanksource/commons v1.22.1/go.mod h1:GD5+yGvmYFPIW3WMNN+y1JkeDMJY74e05pQAsRbrvwY=
github.com/flanksource/duty v1.0.433 h1:Mhbt/yc3Cv8Af/YN697eMuDeWoZKZZ0QkuvNxzzMOTU=
github.com/flanksource/duty v1.0.433/go.mod h1:GNckeTl2cnxQepuHJAH0b8xEaLsAnx9kQZs+VIPDnXc=
github.com/flanksource/duty v1.0.435 h1:pUDj8wmWhcyLZtYiJmfEHh9V4lDwGXj+USz7Q3Bv0XE=
github.com/flanksource/duty v1.0.435/go.mod h1:GNckeTl2cnxQepuHJAH0b8xEaLsAnx9kQZs+VIPDnXc=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.7 h1:XVIwcOTIR9l95D+jaerHcqRFN2Mo6MNEMttxsEsZ9aY=
github.com/flanksource/gomplate/v3 v3.24.7/go.mod h1:7SJHGdFITvw3I8qf/ppF1BXbL2/ENyI5vpQkWt8MHtU=
Expand Down
10 changes: 9 additions & 1 deletion pkg/db/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,15 @@ func PersistCanaryModel(ctx context.Context, model pkg.Canary) (*pkg.Canary, err
db := ctx.DB()
err := db.Clauses(
clause.OnConflict{
Columns: []clause.Column{{Name: "agent_id"}, {Name: "name"}, {Name: "namespace"}, {Name: "source"}},
Columns: []clause.Column{{Name: "agent_id"}, {Name: "name"}, {Name: "namespace"}, {Name: "source"}},
TargetWhere: clause.Where{
Exprs: []clause.Expression{
clause.Or(
clause.Eq{Column: "deleted_at", Value: gorm.Expr("NULL")},
clause.Not(clause.Eq{Column: "agent_id", Value: uuid.Nil.String()}),
),
},
},
DoUpdates: clause.AssignmentColumns([]string{"labels", "spec"}),
},
clause.Returning{},
Expand Down
18 changes: 14 additions & 4 deletions pkg/db/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,20 @@ func PersistV1Topology(ctx context.Context, t *v1.Topology) (pkg.Topology, bool,
}

func PersistTopology(ctx context.Context, model *pkg.Topology) (bool, error) {
tx := ctx.DB().Table("topologies").Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "agent_id"}, {Name: "name"}, {Name: "namespace"}},
UpdateAll: true,
}).Create(model)
tx := ctx.DB().
Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "agent_id"}, {Name: "name"}, {Name: "namespace"}},
TargetWhere: clause.Where{
Exprs: []clause.Expression{
clause.Or(
clause.Eq{Column: "deleted_at", Value: gorm.Expr("NULL")},
clause.Not(clause.Eq{Column: "agent_id", Value: uuid.Nil.String()}),
),
},
},
DoUpdates: clause.AssignmentColumns([]string{"labels", "spec"}),
}).
Create(model)
if tx.Error != nil {
return false, tx.Error
}
Expand Down

0 comments on commit 6b2f541

Please sign in to comment.