Skip to content

Commit

Permalink
chore: use ctx.RunTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Feb 26, 2024
1 parent 5e23955 commit aabd335
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 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
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 aabd335

Please sign in to comment.