Skip to content

Commit

Permalink
Merge pull request #1688 from flanksource/bdu
Browse files Browse the repository at this point in the history
chore: use ctx.RunTemplate
  • Loading branch information
yashmehrotra authored Feb 27, 2024
2 parents 7428c31 + aabd335 commit 4faa86d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions checks/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/flanksource/canary-checker/pkg"
"github.com/flanksource/canary-checker/pkg/utils"
cUtils "github.com/flanksource/commons/utils"
"github.com/flanksource/gomplate/v3"
"github.com/robfig/cron/v3"
)

Expand Down Expand Up @@ -70,7 +69,7 @@ func template(ctx *context.Context, template v1.Template) (string, error) {
tpl.Functions[k] = v
}

return gomplate.RunTemplate(ctx.Environment, tpl)
return ctx.RunTemplate(tpl, ctx.Environment)
}

// transform generates new checks from the transformation template of the parent check
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/fergusstrange/embedded-postgres v1.25.0
github.com/flanksource/artifacts v1.0.4
github.com/flanksource/commons v1.22.0
github.com/flanksource/duty v1.0.347
github.com/flanksource/duty v1.0.349
github.com/flanksource/gomplate/v3 v3.24.0
github.com/flanksource/is-healthy v0.0.0-20231003215854-76c51e3a3ff7
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 @@ -848,8 +848,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.0 h1:LI839ZOVJ6qrNuGKqb6Z4JyIxFHXGhfDxJbXUj5VimQ=
github.com/flanksource/commons v1.22.0/go.mod h1:GD5+yGvmYFPIW3WMNN+y1JkeDMJY74e05pQAsRbrvwY=
github.com/flanksource/duty v1.0.347 h1:tZayR1B3jnEcN6upyHoeY+ihHqYtXKXMRdlTX2pg7kc=
github.com/flanksource/duty v1.0.347/go.mod h1:nBvFOIoquZipqykL8EK0EkwEXNu/k7iC4KVxpikKUWI=
github.com/flanksource/duty v1.0.349 h1:uCDzvC61826uo95zJdnvPsLx3rMPVkWxlDRQCtVvSdU=
github.com/flanksource/duty v1.0.349/go.mod h1:nBvFOIoquZipqykL8EK0EkwEXNu/k7iC4KVxpikKUWI=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.0 h1:wwW6aIfy8EyOZqB3UjXqxVNEmBmb5WM97xTy9uzhHQQ=
github.com/flanksource/gomplate/v3 v3.24.0/go.mod h1:l6qN3L0Covtdrbei0nUSe4tqNlDcpTWsiHhRhHdVmCw=
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 @@ -50,7 +50,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.347 // indirect
github.com/flanksource/duty v1.0.349 // indirect
github.com/flanksource/is-healthy v0.0.0-20231003215854-76c51e3a3ff7 // indirect
github.com/flanksource/kommons v0.31.4 // indirect
github.com/flanksource/kubectl-neat v1.0.2 // 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 @@ -730,8 +730,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.0 h1:LI839ZOVJ6qrNuGKqb6Z4JyIxFHXGhfDxJbXUj5VimQ=
github.com/flanksource/commons v1.22.0/go.mod h1:GD5+yGvmYFPIW3WMNN+y1JkeDMJY74e05pQAsRbrvwY=
github.com/flanksource/duty v1.0.347 h1:tZayR1B3jnEcN6upyHoeY+ihHqYtXKXMRdlTX2pg7kc=
github.com/flanksource/duty v1.0.347/go.mod h1:nBvFOIoquZipqykL8EK0EkwEXNu/k7iC4KVxpikKUWI=
github.com/flanksource/duty v1.0.349 h1:uCDzvC61826uo95zJdnvPsLx3rMPVkWxlDRQCtVvSdU=
github.com/flanksource/duty v1.0.349/go.mod h1:nBvFOIoquZipqykL8EK0EkwEXNu/k7iC4KVxpikKUWI=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.0 h1:wwW6aIfy8EyOZqB3UjXqxVNEmBmb5WM97xTy9uzhHQQ=
github.com/flanksource/gomplate/v3 v3.24.0/go.mod h1:l6qN3L0Covtdrbei0nUSe4tqNlDcpTWsiHhRhHdVmCw=
Expand Down
7 changes: 3 additions & 4 deletions pkg/topology/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/flanksource/duty/query"

"github.com/flanksource/duty/types"
"github.com/flanksource/gomplate/v3"
"github.com/google/uuid"
jsontime "github.com/liamylian/jsontime/v2/v2"
"github.com/pkg/errors"
Expand Down Expand Up @@ -163,7 +162,7 @@ func lookupComponents(ctx *ComponentContext, component v1.ComponentSpec) (compon
comp.Lifecycle = component.Lifecycle
}
if comp.ExternalId == "" && component.Id != nil {
id, err := gomplate.RunTemplate(comp.GetAsEnvironment(), component.Id.Gomplate())
id, err := ctx.RunTemplate(component.Id.Gomplate(), comp.GetAsEnvironment())
if err != nil {
return nil, errors.Wrapf(err, "Failed to lookup id: %v", component.Id)
} else {
Expand Down Expand Up @@ -260,7 +259,7 @@ func lookupConfig(ctx *ComponentContext, property *v1.Property) (*types.Property

ctx.Tracef("%s property=%s => %s", ctx, property.Name, _config.String())

prop.Text, err = gomplate.RunTemplate(templateEnv, property.ConfigLookup.Display.Template.Gomplate())
prop.Text, err = ctx.RunTemplate(property.ConfigLookup.Display.Template.Gomplate(), templateEnv)
return prop, err
}

Expand Down Expand Up @@ -513,7 +512,7 @@ func (tj *TopologyJob) Run(job job.JobRuntime) error {
rootComponent.Summary = rootComponent.Components.Summarize()
}
if rootComponent.ID.String() == "" && ctx.Topology.Spec.Id != nil {
id, err := gomplate.RunTemplate(rootComponent.GetAsEnvironment(), ctx.Topology.Spec.Id.Gomplate())
id, err := ctx.RunTemplate(ctx.Topology.Spec.Id.Gomplate(), rootComponent.GetAsEnvironment())
if err != nil {
job.History.AddError(fmt.Sprintf("Failed to lookup id: %v", err))
} else {
Expand Down

0 comments on commit 4faa86d

Please sign in to comment.