Skip to content

Commit

Permalink
Switch from text/template to the safer yamltemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
cheftako committed Jun 14, 2024
1 parent fc749b5 commit c5ecee1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions experiments/compositions/composition/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ require (
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand All @@ -62,6 +63,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions experiments/compositions/composition/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"bytes"
"context"
"fmt"
"text/template"
"time"

"github.com/go-logr/logr"
"github.com/google/safetext/yamltemplate"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -131,11 +131,11 @@ func NewJobFactory(ctx context.Context, logger logr.Logger, client client.Client
func (f *JobFactory) parseObjectTemplate(name string, objTemplate string) ([]byte, error) {
var manifests bytes.Buffer

tmpl, err := template.New(name).Parse(objTemplate)
tmpl, err := yamltemplate.New(name).Parse(objTemplate)
if err != nil {
return nil, err
}
// Execute template tmpl and write to a string
// Execute yamltemplate tmpl and write to a string
err = tmpl.Execute(&manifests, *f)
if err != nil {
return nil, err
Expand Down
14 changes: 7 additions & 7 deletions experiments/compositions/composition/proto/expander.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5ecee1

Please sign in to comment.