Skip to content

Commit

Permalink
Merge pull request #1661 from flanksource/fix-context-topology
Browse files Browse the repository at this point in the history
chore: use new context for topology job
  • Loading branch information
moshloop authored Feb 7, 2024
2 parents 58ca774 + e4b7c53 commit ffbf795
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/jobs/topology/topology_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"reflect"
"sync"

canaryCtx "github.com/flanksource/canary-checker/api/context"
v1 "github.com/flanksource/canary-checker/api/v1"
"github.com/flanksource/canary-checker/pkg"
"github.com/flanksource/canary-checker/pkg/db"
Expand All @@ -20,7 +21,7 @@ var TopologyScheduler = cron.New()

var topologyJobs sync.Map

func newTopologyJob(ctx context.Context, topology pkg.Topology) {
func newTopologyJob(topology pkg.Topology) {
id := topology.ID.String()
v1, err := topology.ToV1()
if err != nil {
Expand All @@ -36,7 +37,7 @@ func newTopologyJob(ctx context.Context, topology pkg.Topology) {
}
j := &job.Job{
Name: "Topology",
Context: ctx.WithObject(v1.ObjectMeta).WithTopology(*v1),
Context: canaryCtx.DefaultContext.WithObject(v1.ObjectMeta).WithTopology(*v1),
Schedule: v1.Spec.Schedule,
Singleton: true,
JobHistory: true,
Expand Down Expand Up @@ -97,15 +98,15 @@ func SyncTopologyJob(ctx context.Context, t pkg.Topology) error {
}

if existingJob == nil {
newTopologyJob(ctx, t)
newTopologyJob(t)
return nil
}

existingTopology := existingJob.Context.Value("topology")
if existingTopology != nil && !reflect.DeepEqual(existingTopology.(v1.Topology).Spec, v1Topology.Spec) {
ctx.Debugf("Rescheduling %s topology with updated specs", t)
existingJob.Unschedule()
newTopologyJob(ctx, t)
newTopologyJob(t)
}
return nil
}
Expand Down

0 comments on commit ffbf795

Please sign in to comment.