Skip to content

Commit

Permalink
support templated flag (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored Feb 16, 2024
1 parent 77780df commit f5fbeb1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/orcaman/concurrent-map/v2 v2.0.1
github.com/osteele/liquid v1.3.2
github.com/pkg/errors v0.9.1
github.com/pluralsh/console-client-go v0.0.92
github.com/pluralsh/console-client-go v0.0.95
github.com/pluralsh/controller-reconcile-helper v0.0.4
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
github.com/pluralsh/polly v0.1.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pluralsh/console-client-go v0.0.92 h1:PMSF05Zp5gLejeEWXbwe17CfXNLJ55dGlFPAAVucfCM=
github.com/pluralsh/console-client-go v0.0.92/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/console-client-go v0.0.95 h1:JxZ4FSGDo9Mxu1947i2ipCZquDQ+iWW6FGx3s4/onpA=
github.com/pluralsh/console-client-go v0.0.95/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw=
Expand Down
11 changes: 11 additions & 0 deletions pkg/manifests/template/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@ func NewRaw(dir string) *raw {
return &raw{dir}
}

func isTemplated(svc *console.GetServiceDeploymentForAgent_ServiceDeployment) bool {
if svc.Templated != nil {
return *svc.Templated
}
// default true
return true
}

func renderLiquid(input []byte, svc *console.GetServiceDeploymentForAgent_ServiceDeployment) ([]byte, error) {
if !isTemplated(svc) {
return input, nil
}
bindings := map[string]interface{}{
"configuration": configMap(svc),
"cluster": svc.Cluster,
Expand Down
11 changes: 10 additions & 1 deletion pkg/manifests/template/raw_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package template

import (
"github.com/samber/lo"

Check failure on line 4 in pkg/manifests/template/raw_test.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `goimports`-ed (goimports)
"path/filepath"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -10,14 +11,14 @@ import (

var _ = Describe("Raw template", func() {

dir := filepath.Join("..", "..", "..", "test", "raw")
svc := &console.GetServiceDeploymentForAgent_ServiceDeployment{
Namespace: "default",
Configuration: make([]*console.GetServiceDeploymentForAgent_ServiceDeployment_Configuration, 0),
}
Context("Render raw template", func() {
const name = "nginx"
It("should successfully render the raw template", func() {
dir := filepath.Join("..", "..", "..", "test", "raw")
svc.Configuration = []*console.GetServiceDeploymentForAgent_ServiceDeployment_Configuration{
{
Name: "name",
Expand All @@ -29,6 +30,14 @@ var _ = Describe("Raw template", func() {
Expect(len(resp)).To(Equal(1))
Expect(resp[0].GetName()).To(Equal(name))
})
It("should skip templating liquid", func() {
dir := filepath.Join("..", "..", "..", "test", "rawTemplated")
svc.Templated = lo.ToPtr(false)
resp, err := NewRaw(dir).Render(svc, utilFactory)
Expect(err).NotTo(HaveOccurred())
Expect(len(resp)).To(Equal(1))
Expect(resp[0].GetName()).To(Equal(name))
})

})
})
10 changes: 10 additions & 0 deletions test/rawTemplated/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

0 comments on commit f5fbeb1

Please sign in to comment.