@@ -7,45 +7,18 @@ import (
77 "path/filepath"
88 "strings"
99
10- "github.com/Masterminds/sprig/v3"
11- "github.com/osteele/liquid"
1210 console "github.com/pluralsh/console-client-go"
1311 "github.com/pluralsh/polly/containers"
12+ "github.com/pluralsh/polly/template"
1413 "github.com/samber/lo"
1514 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1615 "k8s.io/kubectl/pkg/cmd/util"
1716)
1817
1918var (
20- extensions = []string {".json" , ".yaml" , ".yml" , ".yaml.liquid" , ".yml.liquid" , ".json.liquid" }
21- liquidEngine = liquid .NewEngine ()
22- sprigFunctions = map [string ]string {
23- "toJson" : "to_json" ,
24- "fromJson" : "from_json" ,
25- "b64enc" : "b64enc" ,
26- "b64dec" : "b64dec" ,
27- "semverCompare" : "semver_compare" ,
28- "sha256sum" : "sha26sum" ,
29- "quote" : "quote" ,
30- "squote" : "squote" ,
31- "replace" : "replace" ,
32- "coalesce" : "coalesce" ,
33- }
19+ extensions = []string {".json" , ".yaml" , ".yml" , ".yaml.liquid" , ".yml.liquid" , ".json.liquid" }
3420)
3521
36- func init () {
37- fncs := sprig .TxtFuncMap ()
38- for key , name := range sprigFunctions {
39- liquidEngine .RegisterFilter (name , fncs [key ])
40- }
41- liquidEngine .RegisterFilter ("indent" , indent )
42- liquidEngine .RegisterFilter ("nindent" , nindent )
43- liquidEngine .RegisterFilter ("replace" , strings .ReplaceAll )
44-
45- liquidEngine .RegisterFilter ("default" , dfault )
46- liquidEngine .RegisterFilter ("ternary" , ternary )
47- }
48-
4922type raw struct {
5023 dir string
5124}
@@ -54,21 +27,13 @@ func NewRaw(dir string) *raw {
5427 return & raw {dir }
5528}
5629
57- func isTemplated (svc * console.GetServiceDeploymentForAgent_ServiceDeployment ) bool {
58- if svc .Templated != nil {
59- return * svc .Templated
60- }
61- // default true
62- return true
63- }
64-
6530func renderLiquid (input []byte , svc * console.GetServiceDeploymentForAgent_ServiceDeployment ) ([]byte , error ) {
6631 bindings := map [string ]interface {}{
6732 "configuration" : configMap (svc ),
6833 "cluster" : clusterConfiguration (svc .Cluster ),
6934 "contexts" : contexts (svc ),
7035 }
71- return liquidEngine . ParseAndRender (input , bindings )
36+ return template . RenderLiquid (input , bindings )
7237}
7338
7439func (r * raw ) Render (svc * console.GetServiceDeploymentForAgent_ServiceDeployment , utilFactory util.Factory ) ([]* unstructured.Unstructured , error ) {
@@ -132,24 +97,3 @@ func (r *raw) Render(svc *console.GetServiceDeploymentForAgent_ServiceDeployment
13297 res = newSet .List ()
13398 return res , nil
13499}
135-
136- func clusterConfiguration (cluster * console.GetServiceDeploymentForAgent_ServiceDeployment_Cluster ) map [string ]interface {} {
137- res := map [string ]interface {}{
138- "ID" : cluster .ID ,
139- "Self" : cluster .Self ,
140- "Handle" : cluster .Handle ,
141- "Name" : cluster .Name ,
142- "Version" : cluster .Version ,
143- "CurrentVersion" : cluster .CurrentVersion ,
144- "KasUrl" : cluster .KasURL ,
145- "Metadata" : cluster .Metadata ,
146- }
147-
148- for k , v := range res {
149- res [strings .ToLower (k )] = v
150- }
151- res ["kasUrl" ] = cluster .KasURL
152- res ["currentVersion" ] = cluster .CurrentVersion
153-
154- return res
155- }
0 commit comments